diff --git a/__manifest__.py b/__manifest__.py index ad9ad19..0cf2338 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -47,6 +47,7 @@ 'wizard/recurring_donation_wizard.xml', 'wizard/create_bank_deposit_wizard.xml', 'wizard/create_accounting_deposit_wizard.xml', + 'report/report_templates.xml', 'report/report_donationtax.xml', 'report/report_donation_recurring.xml', 'report/report.xml', diff --git a/models/donation_tax_receipt.py b/models/donation_tax_receipt.py index 8625c08..31d3249 100644 --- a/models/donation_tax_receipt.py +++ b/models/donation_tax_receipt.py @@ -1,12 +1,16 @@ from odoo import api, fields, models from datetime import datetime,timedelta,date - +import locale +import threading +from num2words import num2words +from contextlib import contextmanager class DonationTaxReceipt(models.Model): _inherit = "donation.tax.receipt" template_rf_id=fields.Many2one('opendons.template_rf', 'RF template') html_content_print=fields.Html('html content print') + css_print=fields.Text('css') pdf_file=fields.Binary("PDF") @@ -16,18 +20,26 @@ class DonationTaxReceipt(models.Model): res = super(DonationTaxReceipt, self).create(values) #generate the taxreceipt in HTMl format for PDF print template_rf=self.env['opendons.template_rf'].search([('type_rf','=','generic'),('active','=',True)],limit=1) - + res.css_print=template_rf.css 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('{{partner_id.name}}',str(res.partner_id.name)) + html_content_print=html_content_print.replace('{{partner_id.firstname}}',str(res.partner_id.firstname)) + html_content_print=html_content_print.replace('{{adresse}}',str(res.update_adresse())) + html_content_print=html_content_print.replace('{{number}}',str(res.number)) + locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') + today=datetime.today() + html_content_print=html_content_print.replace('{{date}}',today.strftime("%d %B %Y")) html_content_print=html_content_print.replace('{{donor_id}}',str(self.partner_id.donor_id)) + html_content_print=html_content_print.replace('{{fiscalyear}}',str(int(today.strftime("%Y"))-1)) + html_content_print=html_content_print.replace('{{amount}}',str(res.amount)) + html_content_print=html_content_print.replace('{{amountstr}}',num2words(float(res.amount),lang="fr",to="currency")) + 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) def action_print_rf(self): @@ -54,9 +66,9 @@ class DonationTaxReceipt(models.Model): locality='
'+p.tax_locality if p.tax_locality else '' zip=p.tax_zip if p.tax_zip else '' city=p.tax_city if p.tax_city else '' - country=p.tax_country_id.name if p.tax_country_id.name else '' + - result='

'+title+' '+name+' '+firstname+'
'+street+street2+locality+'
'+zip+' '+city+'
'+country+'

' + result='

'+title+' '+name+' '+firstname+'
'+street+street2+locality+'
'+zip+' '+city+'

' else: title=p.title.name if p.title.name else '' name=p.name if p.name else '' @@ -66,9 +78,9 @@ class DonationTaxReceipt(models.Model): locality='
'+p.locality if p.locality else '' zip=p.zip if p.zip else '' city=p.city if p.city else '' - country=p.country_id.name if p.country_id.name else '' + - result='

'+title+' '+name+' '+firstname+'
'+street+street2+locality+'
'+zip+' '+city+'
'+country+'

' + result='

'+title+' '+name+' '+firstname+'
'+street+street2+locality+'
'+zip+' '+city+'

' #result="

Monsieur Dupont Marcel
7 avenue de la Marne

75016 Paris

" return result diff --git a/models/template_rf.py b/models/template_rf.py index 4d6258e..3aea33a 100644 --- a/models/template_rf.py +++ b/models/template_rf.py @@ -17,6 +17,7 @@ class opendons_template_rf(models.Model): description=fields.Text('description') active=fields.Boolean('active') html_content=fields.Html('Html content') + css=fields.Text('css') 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.xml b/report/report.xml index 9bd107e..a41f53d 100644 --- a/report/report.xml +++ b/report/report.xml @@ -23,7 +23,7 @@ opendons.report_donationtaxreceipt 'Fiscal_receipt-'+(object.number or '').replace('/','')+'.pdf' + >'RF-'+(object.number or '').replace('/','') report diff --git a/report/report_donationtax.xml b/report/report_donationtax.xml index ece6da6..1c4f044 100644 --- a/report/report_donationtax.xml +++ b/report/report_donationtax.xml @@ -8,7 +8,8 @@ - +