From ea80936f1739ba66c02b94ef6161253ff7b73240 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 19 Aug 2022 13:59:46 +0000 Subject: [PATCH] correction PA --- models/donation.py | 63 ++++++++++++++++++++++++++++++++++-- views/donation.xml | 2 +- views/fls.xml | 4 +-- views/partner.xml | 2 +- views/recurring_donation.xml | 32 ++++++++++++++---- 5 files changed, 91 insertions(+), 12 deletions(-) diff --git a/models/donation.py b/models/donation.py index a885175..04d087e 100644 --- a/models/donation.py +++ b/models/donation.py @@ -99,6 +99,19 @@ class DonationDonation(models.Model): ], compute='_compute_payment_state', store=True) + @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" + + 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 create_mandate(self): + return True def generate_each_tax_receipt(self): #pas de création du RF à la validation du don, mais génération des RF ponctuels en mode batch return False @@ -204,7 +217,7 @@ class DonationDonation(models.Model): rec.year_donation_date=rec.donation_date.year def _default_payment_mode_id(self): - #raise Warning(self.recurring_template) + if self.recurring_template=='active': sepa_payment_method=self.env['account.payment.method'].search([('code','=','sepa_direct_debit')],limit=1) @@ -232,9 +245,21 @@ class DonationDonation(models.Model): @api.model def create(self, vals): #vals['tax_receipt_option']='annual' + if vals['tax_receipt_option']!='annual': raise Warning('The tax receipt option must be annual') + #si montant du PA=0 => message + total=0 + if not vals['line_ids']: + raise Warning('please add a donation line') + else: + for line_d in vals['line_ids']: + + total=total+float(line_d[2]['unit_price']) + if total==0:raise Warning('The total amount is null') res = super(DonationDonation, self).create(vals) + + #si don hors lot de paiement,ne provenant pas d'un PA : création auto du lot de paiement if not res.payment_batch_id and res.state!='draft' and res.source_recurring_id==False : vals={} @@ -633,6 +658,7 @@ class DonationDonation(models.Model): else: raise Warning('Please configure method sepa payment') + today=fields.Date.context_today(self) action = self.env.ref("opendons.donation_recurring_action").sudo().read([])[0] action.update( @@ -640,13 +666,46 @@ class DonationDonation(models.Model): "res_model": 'donation.donation', "view_mode": 'tree,form,pivot,graph', "context": {'default_recurring_template': 'active', 'recurring_view': True,'default_payment_mode_id':payment_mode_id, - 'default_tax_receipt_option':'annual'}, + 'default_tax_receipt_option':'annual', + 'default_donation_date':today}, "domain": [('recurring_template', '!=', False)] } ) return action + def recurring_donation_action_partner(self): + + partner_id = self._context.get('active_id') + + sepa_payment_method=self.env['account.payment.method'].search([('code','=','sepa_direct_debit')]) + if sepa_payment_method: + sepa_payment_mode=self.env['account.payment.mode'].search([('payment_method_id','=',int( sepa_payment_method))]) + if sepa_payment_mode: + payment_mode_id=sepa_payment_mode.id + else: + raise Warning('Please configure mode sepa payment') + + else: + raise Warning('Please configure method sepa payment') + + + action = self.env.ref("opendons.donation_recurring_action").sudo().read([])[0] + today=fields.Date.context_today(self) + action.update( + { + "res_model": 'donation.donation', + "view_mode": 'tree,form,pivot,graph', + "context": {'default_recurring_template': 'active', 'recurring_view': True, + 'default_payment_mode_id':payment_mode_id,'default_partner_id':partner_id, + 'default_tax_receipt_option':'annual', + 'default_donation_date':today}, + "domain": [('recurring_template', '!=', False),('partner_id','=',partner_id)] + } + ) + + return action + def payment_order_action(self): diff --git a/views/donation.xml b/views/donation.xml index acc13b6..03d309b 100644 --- a/views/donation.xml +++ b/views/donation.xml @@ -8,7 +8,7 @@ - + diff --git a/views/fls.xml b/views/fls.xml index d3c64fa..2882a7d 100644 --- a/views/fls.xml +++ b/views/fls.xml @@ -10,11 +10,11 @@ - + parent="fls_title_menu" sequence="1"/> --> \ No newline at end of file diff --git a/views/partner.xml b/views/partner.xml index b1b849f..6805a8e 100644 --- a/views/partner.xml +++ b/views/partner.xml @@ -209,7 +209,7 @@ />