diff --git a/models/donation.py b/models/donation.py index 05247cf..04d087e 100644 --- a/models/donation.py +++ b/models/donation.py @@ -23,7 +23,7 @@ class DonationDonation(models.Model): string='Operation', track_visibility='onchange', ondelete='restrict', - required=True, + # required=True, domain=[('state', '=', 'exported')] ) @@ -33,7 +33,7 @@ class DonationDonation(models.Model): 'opendons.segment', string='Segment', track_visibility='onchange', - required=True, + # required=True, ondelete='restrict' ) @@ -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/models/duplicate.py b/models/duplicate.py index 1a9d0e2..813824b 100644 --- a/models/duplicate.py +++ b/models/duplicate.py @@ -21,8 +21,9 @@ class opendons_duplicate_partner(models.Model): index=True, readonly=True, track_visibility='onchange', - ondelete='restrict' + ondelete='cascade' ) + user_ids=fields.One2many(related='partner_id.user_ids') def find_duplicate_partner(self): self.env['opendons.duplicate_partner'].search([]).unlink() diff --git a/models/partner.py b/models/partner.py index 2fd9f0f..d53654f 100644 --- a/models/partner.py +++ b/models/partner.py @@ -108,7 +108,7 @@ class partner(models.Model): npai_count=fields.Integer(String="NPAI count", readonly=True) source=fields.Char(String="source") - donor_id=fields.Char('Donor id',compute="_compute_donor_id",store=True) + donor_id=fields.Char('Donor id',readonly=True) aggregate_id=fields.Many2one('opendons.aggregate.partner','partner_id') @@ -170,7 +170,7 @@ class partner(models.Model): # Change the values of a variable in this super function record['key'] = self._alpha(int(record.id)) - + record.donor_id=str(record.id)+record.key # Return the record so that the changes are applied and everything is stored. return record 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/duplicate.xml b/views/duplicate.xml index cf18260..961ba6e 100644 --- a/views/duplicate.xml +++ b/views/duplicate.xml @@ -20,6 +20,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 @@ />