from odoo import api, fields, models
|
|
|
|
|
|
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_print=fields.Html('html content print')
|
|
#donation_type=fields.Char('letter', compute='_compute_donation_type')
|
|
|
|
|
|
|
|
# #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
|
|
|
|
|
|
|
|
|
|
def get_portal_url(self):
|
|
return "my/taxreceipt/print?id="+str(self.id)
|
|
def action_print_rf(self):
|
|
self.ensure_one()
|
|
|
|
|
|
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
|
|
|
|
#affichage du RF depuis l'espace donateur
|
|
def update_print_pdf(self):
|
|
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('{{donor_id}}',self.partner_id.donor_id)
|
|
html_content_print=html_content_print.replace('{{adresse}}',self.update_adresse())
|
|
|
|
self.html_content_print=html_content_print
|
|
|
|
def update_adresse(self):
|
|
p=self.env['res.partner'].search([('id','=',int(self.partner_id))])
|
|
result=''
|
|
#prise en compte de l'adresse fiscale ou non
|
|
if p.tax_street and p.tax_zip and p.city:
|
|
title=p.title.name if p.title.name else ''
|
|
name=p.name if p.name else ''
|
|
firstname=p.firstname if p.firstname else ''
|
|
street=p.tax_street if p.tax_street else ''
|
|
street2='<br>'+p.tax_street2 if p.tax_street2 else ''
|
|
locality='<br>'+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='<p>'+title+' '+name+' '+firstname+'<br>'+street+street2+locality+'<br>'+zip+' '+city+'<br>'+country+'</p>'
|
|
else:
|
|
title=p.title.name if p.title.name else ''
|
|
name=p.name if p.name else ''
|
|
firstname=p.firstname if p.firstname else ''
|
|
street=p.street if p.street else ''
|
|
street2='<br>'+p.street2 if p.street2 else ''
|
|
locality='<br>'+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='<p>'+title+' '+name+' '+firstname+'<br>'+street+street2+locality+'<br>'+zip+' '+city+'<br>'+country+'</p>'
|
|
|
|
#result="<p>Monsieur Dupont Marcel<br>7 avenue de la Marne</p><p>75016 Paris</p>"
|
|
return result
|
|
|
|
class DonationTaxReceiptPrint(models.TransientModel):
|
|
_inherit = "donation.tax.receipt.print"
|
|
|
|
|
|
def print_receipts(self):
|
|
self.ensure_one()
|
|
if not self.receipt_ids:
|
|
raise UserError(_("There are no tax receipts to print."))
|
|
today = fields.Date.context_today(self)
|
|
#self.receipt_ids.write({"print_date": today})
|
|
|
|
#update htm to print in receipts
|
|
for receipt_id in self.receipt_ids:
|
|
|
|
receipt_id.update_print_pdf()
|
|
|
|
|
|
return self.env.ref("opendons.report_donation_tax_receipt").report_action(self.receipt_ids)
|