|
|
@ -84,10 +84,45 @@ class DonationDonation(models.Model): |
|
|
|
string='Payment Batch', |
|
|
|
ondelete='set null' |
|
|
|
) |
|
|
|
accountingdeposit_id = fields.Many2one( |
|
|
|
'opendons.accountingdeposit', |
|
|
|
string='accounting deposit', |
|
|
|
ondelete='set null' |
|
|
|
) |
|
|
|
|
|
|
|
#bank_deposit_date=fields.Datetime(related='payment_batch_id.bank_deposit_date') |
|
|
|
payment_state=fields.Selection(related='payment_batch_id.state') |
|
|
|
payment_state=fields.Selection(string='payment state',selection=[ |
|
|
|
('draft', 'Draft'), |
|
|
|
('validated', 'Validated'), |
|
|
|
('deposited_in_bank', 'Deposited in bank'), |
|
|
|
('deposited_in_accounting', 'Deposited in accounting') |
|
|
|
], |
|
|
|
compute='_compute_payment_state', store=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 |
|
|
|
|
|
|
|
def generate_each_tax_receipt_batch(self): |
|
|
|
#on générère tous les dons avec taxreceipt_option= qui n'on pas de RF rattaché |
|
|
|
donations=self.env['donation.donation'].search([('tax_receipt_option','=','each'),('tax_receipt_id','=',False)]) |
|
|
|
|
|
|
|
for d in donations: |
|
|
|
if not d.company_currency_id.is_zero(d.tax_receipt_total): |
|
|
|
receipt_vals = d._prepare_each_tax_receipt() |
|
|
|
receipt = self.env["donation.tax.receipt"].create(receipt_vals) |
|
|
|
d.tax_receipt_id=receipt.id |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
def _compute_payment_state(self): |
|
|
|
for rec in self: |
|
|
|
rec.payment_state='draft' |
|
|
|
if rec.payment_batch_id: |
|
|
|
rec.payment_state=rec.payment_batch_id.state |
|
|
|
if rec.source_recurring_id: |
|
|
|
rec.payment_state='deposited_in_bank' |
|
|
|
#accounting_deposit_date=fields.Datetime(related='payment_batch_id.accounting_deposit_date') |
|
|
|
|
|
|
|
year_donation_date=fields.Integer('Year donation date',compute='_compute_year_donation_date',store=True) |
|
|
@ -98,7 +133,16 @@ class DonationDonation(models.Model): |
|
|
|
readonly=True |
|
|
|
) |
|
|
|
html_content_print=fields.Html('html content print') |
|
|
|
|
|
|
|
cancel_reason=fields.Selection(string='cancel reason',selection=[ |
|
|
|
('debit error','Debit error'), |
|
|
|
('donor error','Donor error'), |
|
|
|
('amount error','Amount error'), |
|
|
|
('invalid check','invalid check'), |
|
|
|
('affectation error','Affectation error'), |
|
|
|
('date error','Date error'), |
|
|
|
('other','Other'), |
|
|
|
]) |
|
|
|
|
|
|
|
def done2cancel(self): |
|
|
|
"""from Done state to Cancel state""" |
|
|
|
for donation in self: |
|
|
@ -112,12 +156,25 @@ class DonationDonation(models.Model): |
|
|
|
) |
|
|
|
% 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() |
|
|
|
|
|
|
|
|
|
|
|
view=self.env.ref('opendons.donation_cancel_view') |
|
|
|
|
|
|
|
wiz=self.env['opendons.donation_cancel.wizard'].create({'donation_id':self.id}) |
|
|
|
|
|
|
|
return { |
|
|
|
'name': _('Cancel donation'), |
|
|
|
'type': 'ir.actions.act_window', |
|
|
|
'view_type': 'form', |
|
|
|
'view_mode': 'form', |
|
|
|
'res_model': 'opendons.donation_cancel.wizard', |
|
|
|
'views': [(view.id, 'form')], |
|
|
|
'view_id': view.id, |
|
|
|
'target': 'new', |
|
|
|
'res_id': wiz.id, |
|
|
|
'context': self.env.context, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def reverse_accounting_entries(self): |
|
|
|
move=self.env['account.move'].search([('id','=',int(self.move_id))]) |
|
|
@ -174,12 +231,12 @@ class DonationDonation(models.Model): |
|
|
|
|
|
|
|
@api.model |
|
|
|
def create(self, vals): |
|
|
|
vals['tax_receipt_option']='annual' |
|
|
|
#vals['tax_receipt_option']='annual' |
|
|
|
|
|
|
|
res = super(DonationDonation, self).create(vals) |
|
|
|
|
|
|
|
#si don hors lot de paiement, création auto du lot de paiement |
|
|
|
if not res.payment_batch_id and res.state!='draft' : |
|
|
|
#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={} |
|
|
|
vals['payment_mode_id']=int(res.payment_mode_id) |
|
|
|
batch=self.env['opendons_payment_batch'].create(vals) |
|
|
@ -189,15 +246,15 @@ class DonationDonation(models.Model): |
|
|
|
return res |
|
|
|
|
|
|
|
|
|
|
|
def write(self, vals): |
|
|
|
|
|
|
|
res = super(DonationDonation, self).write(vals) |
|
|
|
#si don hors lot de paiement, création auto du lot de paiement |
|
|
|
if not self.payment_batch_id and self.state!='draft' : |
|
|
|
vals={} |
|
|
|
vals['payment_mode_id']=int(self.payment_mode_id) |
|
|
|
batch=self.env['opendons_payment_batch'].create(vals) |
|
|
|
batch.write({'donation_ids':[(4,int(self.id))]}) |
|
|
|
# def write(self, vals): |
|
|
|
|
|
|
|
# res = super(DonationDonation, self).write(vals) |
|
|
|
# #si don hors lot de paiement, création auto du lot de paiement |
|
|
|
# if not self.payment_batch_id and self.state!='draft' : |
|
|
|
# vals={} |
|
|
|
# vals['payment_mode_id']=int(self.payment_mode_id) |
|
|
|
# batch=self.env['opendons_payment_batch'].create(vals) |
|
|
|
# batch.write({'donation_ids':[(4,int(self.id))]}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -354,11 +411,13 @@ class DonationDonation(models.Model): |
|
|
|
} |
|
|
|
#creation du don à partir du template de don récurrent |
|
|
|
new_donation = donation.copy(default=default) |
|
|
|
new_donation.payment_state='deposited_in_bank' |
|
|
|
#ajout du don à la collection des dons générés pour affichage |
|
|
|
new_donation_ids.append(new_donation.id) |
|
|
|
#mise à jour de la date de dernière génération |
|
|
|
donation.lastexecution_date=date_generation |
|
|
|
|
|
|
|
|
|
|
|
payment_mode_id=donation.payment_mode_id.id |
|
|
|
if not new_donation_ids : raise Warning ("aucun don n'a été généré") |
|
|
|
|
|
|
@ -709,6 +768,13 @@ class DonationLine(models.Model): |
|
|
|
donation_date=fields.Date(related='donation_id.donation_date') |
|
|
|
partner_id=fields.Many2one(related='donation_id.partner_id') |
|
|
|
|
|
|
|
@api.model |
|
|
|
def create(self, values): |
|
|
|
|
|
|
|
res = super(DonationLine, self).create(values) |
|
|
|
res.analytic_account_id=res.product_id.analytic_account_id |
|
|
|
return res |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|