From 25ebabf46cb7681ceb069a8429e36f58ef78420a Mon Sep 17 00:00:00 2001 From: root Date: Fri, 17 Jun 2022 11:40:51 +0000 Subject: [PATCH] extourne suite annulation du don --- models/donation.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/models/donation.py b/models/donation.py index 292eae2..d5e6b7c 100644 --- a/models/donation.py +++ b/models/donation.py @@ -99,6 +99,48 @@ class DonationDonation(models.Model): ) html_content_print=fields.Html('html content print') + def done2cancel(self): + """from Done state to Cancel state""" + for donation in self: + if donation.tax_receipt_id: + raise UserError( + _( + "You cannot cancel this donation because " + "it is linked to the tax receipt %s. You should first " + "delete this tax receipt (but it may not be legally " + "allowed)." + ) + % donation.tax_receipt_id.number + ) + #if donation.move_id: + #donation.move_id.button_cancel() + #donation.move_id.unlink() + donation.write({"state": "cancel"}) + donation.partner_id._update_donor_rank() + donation.reverse_accounting_entries() + + def reverse_accounting_entries(self): + move=self.env['account.move'].search([('id','=',int(self.move_id))]) + #création de la pièce comptable d'extourne + vals={} + vals['ref']='Extourne de '+ move.name + vals['date']=datetime.now() + vals['journal_id']=int(move.journal_id) + vals['reversed_entry_id']=int(move.id) + move_r=self.env['account.move'].create(vals) + #création des écritures comptables d'extourne + for line in move.line_ids: + vals={} + vals['move_id']=int(move_r.id) + vals['partner_id']=int(line.partner_id) + vals['account_id']=int(line.account_id) + vals['debit']=line.credit + vals['credit']=line.debit + vals['quantity']=line.quantity + vals['date']=move_r.date + + line_r=self.env['account.move.line'].with_context(check_move_validity=False).create(vals) + move_r._post() def _compute_year_donation_date(self): for rec in self: