forked from OCA/donation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
donation_recurring: black, isort and other automatic reformatting
- Loading branch information
1 parent
2194545
commit 5bc5062
Showing
8 changed files
with
290 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- | ||
Copyright 2014-2021 Barroux Abbey (http://www.barroux.org) | ||
Copyright 2014-2021 Akretion France (http://www.akretion.com/) | ||
@author: Alexis de Lattre <[email protected]> | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
--> | ||
|
||
<odoo noupdate="1"> | ||
|
||
<record id="donor_rec1" model="res.partner"> | ||
<field name="name">Emilie Legrand</field> | ||
<field name="donor_rank" eval="1"/> | ||
<field name="donor_rank" eval="1" /> | ||
<field name="street">24 chemin des oliviers</field> | ||
<field name="zip">74210</field> | ||
<field name="city">Seythenex</field> | ||
<field name="country_id" ref="base.fr"/> | ||
<field name="country_id" ref="base.fr" /> | ||
<field name="email">[email protected]</field> | ||
<field name="tax_receipt_option">annual</field> | ||
</record> | ||
|
||
<record id="donor_rec2" model="res.partner"> | ||
<field name="name">Marie Durand</field> | ||
<field name="donor_rank" eval="1"/> | ||
<field name="donor_rank" eval="1" /> | ||
<field name="street">9 avenue du Général de Lattre</field> | ||
<field name="zip">75017</field> | ||
<field name="city">Paris</field> | ||
<field name="country_id" ref="base.fr"/> | ||
<field name="country_id" ref="base.fr" /> | ||
<field name="email">[email protected]</field> | ||
<field name="tax_receipt_option">annual</field> | ||
</record> | ||
|
||
<record id="donor_rec3" model="res.partner"> | ||
<field name="name">Olivier Dumesnil</field> | ||
<field name="donor_rank" eval="1"/> | ||
<field name="donor_rank" eval="1" /> | ||
<field name="street">9 avenue Foch</field> | ||
<field name="zip">92400</field> | ||
<field name="city">Courbevoie</field> | ||
<field name="country_id" ref="base.fr"/> | ||
<field name="country_id" ref="base.fr" /> | ||
<field name="email">[email protected]</field> | ||
<field name="tax_receipt_option">annual</field> | ||
</record> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,93 +3,96 @@ | |
# @author: Alexis de Lattre <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models, fields, api, _ | ||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class DonationDonation(models.Model): | ||
_inherit = 'donation.donation' | ||
_inherit = "donation.donation" | ||
|
||
recurring_template = fields.Selection([ | ||
('active', 'Active'), | ||
('suspended', 'Suspended')], | ||
string='Recurring Template', | ||
recurring_template = fields.Selection( | ||
[("active", "Active"), ("suspended", "Suspended")], | ||
string="Recurring Template", | ||
copy=False, | ||
index=True, | ||
tracking=True, | ||
) | ||
source_recurring_id = fields.Many2one( | ||
'donation.donation', | ||
string='Source Recurring Template', | ||
states={'done': [('readonly', True)]} | ||
"donation.donation", | ||
string="Source Recurring Template", | ||
states={"done": [("readonly", True)]}, | ||
) | ||
recurring_donation_ids = fields.One2many( | ||
'donation.donation', | ||
'source_recurring_id', | ||
string='Past Recurring Donations', | ||
"donation.donation", | ||
"source_recurring_id", | ||
string="Past Recurring Donations", | ||
readonly=True, | ||
copy=False | ||
copy=False, | ||
) | ||
|
||
@api.constrains( | ||
'recurring_template', 'source_recurring_id', 'state', | ||
'tax_receipt_option') | ||
"recurring_template", "source_recurring_id", "state", "tax_receipt_option" | ||
) | ||
def _check_recurring_donation(self): | ||
for donation in self: | ||
if donation.recurring_template and donation.state != 'draft': | ||
raise ValidationError(_( | ||
"The recurring donation template %s must stay in " | ||
"draft state.") % donation.number) | ||
if donation.recurring_template and donation.state != "draft": | ||
raise ValidationError( | ||
_("The recurring donation template %s must stay in " "draft state.") | ||
% donation.number | ||
) | ||
if donation.source_recurring_id and donation.recurring_template: | ||
raise ValidationError(_( | ||
"The recurring donation template %s cannot have " | ||
"a Source Recurring Template") | ||
% donation.number) | ||
if ( | ||
donation.recurring_template and | ||
donation.tax_receipt_option == 'each'): | ||
raise ValidationError(_( | ||
"The recurring donation %s cannot have a tax " | ||
"receipt option 'Each'.") | ||
% donation.number) | ||
raise ValidationError( | ||
_( | ||
"The recurring donation template %s cannot have " | ||
"a Source Recurring Template" | ||
) | ||
% donation.number | ||
) | ||
if donation.recurring_template and donation.tax_receipt_option == "each": | ||
raise ValidationError( | ||
_( | ||
"The recurring donation %s cannot have a tax " | ||
"receipt option 'Each'." | ||
) | ||
% donation.number | ||
) | ||
|
||
@api.depends('state', 'partner_id', 'move_id', 'recurring_template') | ||
@api.depends("state", "partner_id", "move_id", "recurring_template") | ||
def name_get(self): | ||
res = [] | ||
for donation in self: | ||
if donation.recurring_template == 'active': | ||
name = _('Recurring Donation %s') % ( | ||
donation.number) | ||
elif donation.recurring_template == 'suspended': | ||
name = _('Suspended Recurring Donation %s') % ( | ||
donation.number) | ||
if donation.recurring_template == "active": | ||
name = _("Recurring Donation %s") % (donation.number) | ||
elif donation.recurring_template == "suspended": | ||
name = _("Suspended Recurring Donation %s") % (donation.number) | ||
else: | ||
name = super(DonationDonation, donation).name_get()[0][1] | ||
res.append((donation.id, name)) | ||
return res | ||
|
||
@api.onchange('recurring_template') | ||
@api.onchange("recurring_template") | ||
def recurring_template_change(self): | ||
res = {'warning': {}} | ||
if self.recurring_template and self.tax_receipt_option == 'each': | ||
self.tax_receipt_option = 'annual' | ||
res['warning']['title'] = _('Update of Tax Receipt Option') | ||
res['warning']['message'] = _( | ||
res = {"warning": {}} | ||
if self.recurring_template and self.tax_receipt_option == "each": | ||
self.tax_receipt_option = "annual" | ||
res["warning"]["title"] = _("Update of Tax Receipt Option") | ||
res["warning"]["message"] = _( | ||
"As it is a recurring donation, " | ||
"the Tax Receipt Option has been changed from Each to " | ||
"Annual. You may want to change it also on the Donor " | ||
"form.") | ||
"form." | ||
) | ||
if not self.recurring_template and self.commercial_partner_id: | ||
if self.commercial_partner_id.tax_receipt_option != self.tax_receipt_option: | ||
self.tax_receipt_option = self.commercial_partner_id.tax_receipt_option | ||
return res | ||
|
||
def active2suspended(self): | ||
self.ensure_one() | ||
assert self.recurring_template == 'active' | ||
self.write({'recurring_template': 'suspended'}) | ||
assert self.recurring_template == "active" | ||
self.write({"recurring_template": "suspended"}) | ||
|
||
def suspended2active(self): | ||
self.ensure_one() | ||
assert self.recurring_template == 'suspended' | ||
self.write({'recurring_template': 'active'}) | ||
assert self.recurring_template == "suspended" | ||
self.write({"recurring_template": "active"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,3 @@ | |
* Alexis de Lattre <[email protected]> | ||
* Serpent Consulting Services Pvt. Ltd. <[email protected]> | ||
* Nikul Chaudhary <[email protected]> | ||
|
Oops, something went wrong.