From ab06efa868bdea49ce9b07e10689974b37413661 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 21 Jun 2022 13:25:35 +0000 Subject: [PATCH] divers --- __manifest__.py | 2 + controllers/portal.py | 2 +- data/data.xml | 4 +- models/accounting_deposit.py | 4 +- models/bank_deposit.py | 4 +- models/donation.py | 106 ++++++++++++++++---- models/donation_tax_receipt.py | 57 ++++------- models/product.py | 11 ++ models/settings.py | 2 + models/template_rf.py | 18 ++-- report/report_bank_deposit.xml | 2 +- security/ir.model.access.csv | 6 +- views/accounting_deposit.xml | 24 ++--- views/bank_deposit.xml | 14 +++ views/donation.xml | 50 +++++++++ views/donation_tax_receipt.xml | 14 ++- views/payment_batch.xml | 3 +- views/recurring_donation.xml | 6 +- views/template_rf.xml | 6 +- wizard/__init__.py | 4 +- wizard/create_accounting_deposit_wizard.xml | 10 +- 21 files changed, 242 insertions(+), 107 deletions(-) diff --git a/__manifest__.py b/__manifest__.py index 069c326..3893064 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -32,6 +32,7 @@ 'views/email.xml', 'views/phone.xml', 'views/donation.xml', + 'views/product.xml', 'views/recurring_donation.xml', 'data/recurring_donation_configuration.xml', 'data/data.xml', @@ -59,6 +60,7 @@ 'report/report_bank_deposit.xml', 'views/donation_tax_receipt.xml', 'views/donation_thanks_template.xml', + 'wizard/donation_cancel_wizard.xml', 'views/laposte_ref.xml', 'views/partner_import.xml', 'views/portal.xml', diff --git a/controllers/portal.py b/controllers/portal.py index 20bbe45..03e590c 100644 --- a/controllers/portal.py +++ b/controllers/portal.py @@ -123,7 +123,7 @@ class PortalOpendons(CustomerPortal): if tr: #mise à jour du champ htl à imprimer - tr.update_print_pdf() + #tr.update_print_pdf() pdf = request.env.ref('opendons.report_donation_tax_receipt').sudo()._render_qweb_pdf([tr.id])[0] pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))] diff --git a/data/data.xml b/data/data.xml index c086e4d..b40c7a9 100644 --- a/data/data.xml +++ b/data/data.xml @@ -1,7 +1,7 @@ - + generic diff --git a/models/accounting_deposit.py b/models/accounting_deposit.py index ed32131..5ca1255 100644 --- a/models/accounting_deposit.py +++ b/models/accounting_deposit.py @@ -15,8 +15,8 @@ class opendons_accounting_deposit(models.Model): ondelete="cascade", default=lambda self: self.env.company, ) - payment_batch_ids = fields.One2many( - 'opendons_payment_batch', + donation_ids = fields.One2many( + 'donation.donation', 'accountingdeposit_id', string='Payment batchs', readonly=True diff --git a/models/bank_deposit.py b/models/bank_deposit.py index b8fd17d..c6b9275 100644 --- a/models/bank_deposit.py +++ b/models/bank_deposit.py @@ -42,6 +42,7 @@ class opendons_bank_deposit(models.Model): ondelete='restrict', default=_default_currency ) + printed=fields.Boolean('printed') donation_count=fields.Integer('donation count',compute='_compute_donation_count') total_amount=fields.Integer('total amount',compute='_compute_total_amount') # template_bankdeposit_id=fields.Many2one('opendons.template_bankdeposit', 'bank deposit template') @@ -71,8 +72,9 @@ class opendons_bank_deposit(models.Model): self.manual_mode_payment_id=m.id def action_print_bankdeposit(self): self.ensure_one() - + self.printed=True return self.env.ref("opendons.report_bankdeposits").report_action(self) + class opendons_bank_deposit_template(models.Model): _name = 'opendons.bankdeposit.template' diff --git a/models/donation.py b/models/donation.py index d5e6b7c..eb9b0b8 100644 --- a/models/donation.py +++ b/models/donation.py @@ -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 + \ No newline at end of file diff --git a/models/donation_tax_receipt.py b/models/donation_tax_receipt.py index 70833d4..05b4257 100644 --- a/models/donation_tax_receipt.py +++ b/models/donation_tax_receipt.py @@ -1,58 +1,41 @@ from odoo import api, fields, models - +from datetime import datetime,timedelta,date class DonationTaxReceipt(models.Model): _inherit = "donation.tax.receipt" template_rf_id=fields.Many2one('opendons.template_rf', 'RF template') - html_content=fields.Html('html content',compute='_html_content_rf') + #html_content=fields.Html('html content',) html_content_print=fields.Html('html content print') - #donation_type=fields.Char('letter', compute='_compute_donation_type') - + pdf_file=fields.Binary("PDF") - # #res = super(DonationTaxReceipt, self).create(vals) - # def _compute_donation_type(self): - - # if len(self.donation_ids)>1: - # #1 cas d'un RF à plusieurs dons - # simple=True - # i=1 - # for d in self.donation_ids: - # for l in d.donation_lines: - # if i==1: product_id=l.product_id - # else: - # if product_id!=l.product_id: - # simple=False - # break - # i=i+1 - # if simple==True : - # self.donation_type='simple' - # self.product_id=product_id - # if simple==False : - # self.donation_type='multiple' - # self.product_id=False + @api.model + def create(self, values): + + res = super(DonationTaxReceipt, self).create(values) + #génération du RF au format HTML pour impression pdf + template_rf=self.env['opendons.template_rf'].search([('type_rf','=','generic'),('active','=',True)],limit=1) + html_content_print=template_rf.html_content + html_content_print=html_content_print.replace('{{partner_id.name}}',str(self.partner_id.name)) + html_content_print=html_content_print.replace('{{partner_id.firstname}}',str(self.partner_id.firstname)) + html_content_print=html_content_print.replace('{{adresse}}',str(self.update_adresse())) + html_content_print=html_content_print.replace('{{donor_id}}',str(self.partner_id.donor_id)) + res.html_content_print=html_content_print + res.template_rf_id=template_rf.id + return res def get_portal_url(self): - return "my/taxreceipt/print?id="+str(self.id) + return "/my/taxreceipt/print?id="+str(self.id) def action_print_rf(self): self.ensure_one() + self.print_date=datetime.now() - - html_content_print=self.html_content - html_content_print=html_content_print.replace('{{partner_id.name}}',self.partner_id.name) - html_content_print=html_content_print.replace('{{partner_id.firstname}}',self.partner_id.firstname) - html_content_print=html_content_print.replace('{{adresse}}',self.update_adresse()) - html_content_print=html_content_print.replace('{{donor_id}}',self.partner_id.donor_id) - self.html_content_print=html_content_print - - #self.env['donation.tax_receipt'].write(vals) - #res=super(donation_tax_receipt, self).write(vals) return self.env.ref("opendons.report_donation_tax_receipt").report_action(self) - #return True + def _html_content_rf(self): self.html_content=self.template_rf_id.html_content diff --git a/models/product.py b/models/product.py index 3216e2b..3936ec8 100644 --- a/models/product.py +++ b/models/product.py @@ -5,6 +5,17 @@ from psycopg2 import sql, DatabaseError from werkzeug import utils +class KalachakraProductTemplate(models.Model): + _inherit = "product.template" + + analytic_account_id = fields.Many2one( + "account.analytic.account", + "Analytic Account", + ondelete="restrict", + + ) + + \ No newline at end of file diff --git a/models/settings.py b/models/settings.py index ef069e9..d7ce60d 100644 --- a/models/settings.py +++ b/models/settings.py @@ -7,7 +7,9 @@ class OpendonsSettings(models.TransientModel): generation_day=fields.Integer('Generation day in the month',config_parameter='opendons.generation_day') limit_days_before=fields.Integer('Limit days before generation day',config_parameter='opendons.limit_days_before') pa_debug_mode=fields.Boolean('Debug mode',config_parameter='opendons.pa_debug_mode') + #RF donation_big_amount=fields.Integer('Donation big amount threshold',config_parameter='opendons.donation_big_amount') + diff --git a/models/template_rf.py b/models/template_rf.py index 924b7ee..dcefce2 100644 --- a/models/template_rf.py +++ b/models/template_rf.py @@ -17,17 +17,13 @@ class opendons_template_rf(models.Model): description=fields.Text('description') active=fields.Boolean('active') html_content=fields.Html('Html content') - type_id=fields.Many2one('opendons.type_template_rf', required=True) + type_rf=fields.Selection(string='type',selection=[('generic','Generic'),('affectation','Affectation'),('high amount','High amount')]) - def action_update_receipts(self): + - rf=self.env['donation.tax.receipt'].search([('template_rf_id','=',int(self.id))]) - - for r in rf: - r.html_content=self.html_content - -class opendons_type_template_rf(models.Model): - _name = 'opendons.type_template_rf' - _description = 'manage type rf template' +# class opendons_type_template_rf(models.Model): +# _name = 'opendons.type_template_rf' +# _description = 'manage type rf template' - name=fields.Char('name') \ No newline at end of file +# name=fields.Char('name') +# type_rf=fields.Selection(string='type',selection=[('generic','Generic'),('affectation','Affectation'),('high amount','High amount')]) \ No newline at end of file diff --git a/report/report_bank_deposit.xml b/report/report_bank_deposit.xml index f8b1756..0a3e9e3 100644 --- a/report/report_bank_deposit.xml +++ b/report/report_bank_deposit.xml @@ -67,7 +67,7 @@ - + diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv index eb6a2e0..deb08fa 100644 --- a/security/ir.model.access.csv +++ b/security/ir.model.access.csv @@ -33,7 +33,7 @@ access_opendons_duplicate_partner,opendons_duplicate_partner,model_opendons_dupl access_opendons_template_rf,opendons_template_rf,model_opendons_template_rf,donation.group_donation_manager,1,1,1,1 -access_opendons_type_template_rf,opendons_type_template_rf,model_opendons_type_template_rf,donation.group_donation_manager,1,1,1,1 + access_opendons_donation_thanks_type_template,opendons_donation_thanks_type_template,model_opendons_type_donation_thanks_template,donation.group_donation_manager,1,1,1,1 @@ -42,8 +42,12 @@ access_opendons_laposte_ref,opendons_laposte_ref,model_opendons_laposte_ref,dona access_opendons_recurring_donation_wizard,opendons_recurring_donation_wizard,model_opendons_recurringdonation_wizard,donation.group_donation_manager,1,1,1,1 + access_opendons_recurring_donationprint_wizard,opendons_recurring_donationprint_wizard,model_opendons_recurringdonationprint_wizard,donation.group_donation_manager,1,1,1,1 access_opendons_recurring_donation,opendons_recurring_donation,model_opendons_recurring_donation,donation.group_donation_manager,1,1,1,1 + +access_opendons_donation_cancel_wizard,opendons_donation_cancel_wizard,model_opendons_donation_cancel_wizard,donation.group_donation_manager,1,1,1,1 + access_opendons_template_pa_letter,opendons_template_pa_letter,model_opendons_template_pa_letter,donation.group_donation_manager,1,1,1,1 access_opendons_print_donation_email_history,opendons_print_donation_email_history,model_opendons_donation_print_email_history,donation.group_donation_manager,1,1,1,1 diff --git a/views/accounting_deposit.xml b/views/accounting_deposit.xml index 5d0f473..dcf63a5 100644 --- a/views/accounting_deposit.xml +++ b/views/accounting_deposit.xml @@ -10,7 +10,7 @@ - + @@ -21,20 +21,13 @@ opendons.accountingdeposit -
- - - - - - - - - + + +
@@ -51,9 +44,14 @@
+ + Create an accounting deposit + opendons.createaccountingdeposit + form + + + -
\ No newline at end of file diff --git a/views/bank_deposit.xml b/views/bank_deposit.xml index d43ead2..a128e1e 100644 --- a/views/bank_deposit.xml +++ b/views/bank_deposit.xml @@ -29,6 +29,7 @@ + @@ -47,10 +48,23 @@ + + + opendons_bank_deposit.search + opendons.bankdeposit + + + + + + + + Bank deposits opendons.bankdeposit tree,form + {"search_default_not_printed":1} diff --git a/views/donation.xml b/views/donation.xml index 844af89..aebe90b 100644 --- a/views/donation.xml +++ b/views/donation.xml @@ -14,4 +14,54 @@ + + + opendons.donation.form + donation.donation + + + + + + + {'readonly':['|',('state','=','cancel'),('recurring_template','=','stopped')]} + + + {'readonly':[('state','=','cancel')]} + + + {'readonly':[('state','=','cancel')],'required': [('mandate_required', '=', True)], 'invisible': [('mandate_required', '=', False)]} + + + {'readonly':[('state','in',['done','cancel'])]} + + + {'readonly':[('state','in',['done','cancel'])]} + + + + + + this action is irreversible, do you confirm ? + + + + + + + + +{'form_no_edit':[('state','=','cancel')]} + + + + + + + + + \ No newline at end of file diff --git a/views/donation_tax_receipt.xml b/views/donation_tax_receipt.xml index eedaaaa..29ccf43 100644 --- a/views/donation_tax_receipt.xml +++ b/views/donation_tax_receipt.xml @@ -9,8 +9,9 @@ + - + @@ -22,4 +23,15 @@ + + opendons.donation.tax_receipt.tree + donation.tax.receipt + + + + + + + + \ No newline at end of file diff --git a/views/payment_batch.xml b/views/payment_batch.xml index 54a3a9d..447c382 100644 --- a/views/payment_batch.xml +++ b/views/payment_batch.xml @@ -128,8 +128,7 @@ parent="payment_batch_title_menu" sequence="10"/> - + diff --git a/views/recurring_donation.xml b/views/recurring_donation.xml index 3fc158d..7c8b7cf 100644 --- a/views/recurring_donation.xml +++ b/views/recurring_donation.xml @@ -8,15 +8,15 @@ - + - - + + diff --git a/views/template_rf.xml b/views/template_rf.xml index 469aa45..267a12b 100644 --- a/views/template_rf.xml +++ b/views/template_rf.xml @@ -13,8 +13,8 @@ - - + + @@ -33,7 +33,7 @@ - + diff --git a/wizard/__init__.py b/wizard/__init__.py index 328340f..01ab3cb 100644 --- a/wizard/__init__.py +++ b/wizard/__init__.py @@ -1,4 +1,6 @@ from . import operation_duplicate_wizard from . import recurring_donation_wizard from . import create_bank_deposit_wizard -from . import create_accounting_deposit_wizard \ No newline at end of file +from . import create_accounting_deposit_wizard +from . import donation_cancel_wizard +#from . import tax_receipt_annual_create \ No newline at end of file diff --git a/wizard/create_accounting_deposit_wizard.xml b/wizard/create_accounting_deposit_wizard.xml index 2c3a09c..dbf8e67 100644 --- a/wizard/create_accounting_deposit_wizard.xml +++ b/wizard/create_accounting_deposit_wizard.xml @@ -6,7 +6,7 @@

- Are you sure do you want to create a accounting deposit with selected payments ? + Are you sure do you want to create a accounting deposit for bank deposit or canceled payments ?