Skip to content

Commit

Permalink
Donation new features: Certificate, Thanks Letter, Summary
Browse files Browse the repository at this point in the history
  • Loading branch information
brendaf committed Apr 19, 2024
1 parent 99b4186 commit 1c2ec72
Show file tree
Hide file tree
Showing 52 changed files with 2,017 additions and 0 deletions.
4 changes: 4 additions & 0 deletions donation_certificate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright <YEAR(S)> <AUTHOR(S)>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models
from . import wizard
27 changes: 27 additions & 0 deletions donation_certificate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright <YEAR(S)> <AUTHOR(S)>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Donation Certificate",
"summary": "Donation Certificate",
"version": "16.0.1.0.0",
"category": "Custom",
"website": "https://www.qubiq.es",
"author": "Brenda Fernández Alayo",
"license": "AGPL-3",
"application": True,
"installable": True,
"depends": ['report_py3o', 'donation', 'donation_base', 'mail'],
"data": [
"security/ir.model.access.csv",
"data/mail_template.xml",
"data/donation_sequence.xml",
'data/py3o_certificate_template.xml',
'views/donation_certificate_send_views.xml',
'views/tax_receipt_donation.xml',
'views/donation_send_cert_button.xml',
'views/py3o_certificate_report.xml',
'wizard/tax_receipt_annual_create_view.xml',
'wizard/tax_receipt_print_view.xml'
],
}
12 changes: 12 additions & 0 deletions donation_certificate/data/donation_sequence.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">

<record id="donation_seq" model="ir.sequence">
<field name="name">Donation</field>
<field name="code">donation.donation</field>
<field name="prefix">DON-%(range_year)s-</field>
<field name="padding">4</field>
<field name="use_date_range" eval="True" />
</record>

</odoo>
44 changes: 44 additions & 0 deletions donation_certificate/data/mail_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" ?>
<odoo>
<data noupdate="1">
<!-- Comments: Todavia no sé qué estructura debería tener, pero si hay algun sugerencia la añado -->
<record id="email_template_donation_certificate" model="mail.template">
<field name="name">Donation: Certificate</field>
<field name="model_id" ref="donation.model_donation_tax_receipt" />
<field name="auto_delete" eval="True"/>
<field name="email_from">{{ object.company_id.email }}</field>
<field name="email_to">{{ object.partner_id.email }}</field>
<field name="subject">Donation Certificate</field>
<field name="description">Donation Certificate</field>
<field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
<p style="margin: 0px; padding: 0px; font-size: 13px;">
Dear
<t t-out="object.partner_id.name or ''">Donor name</t>,
<br />
<br />
We want to express our sincere gratitude for your generous donation of
<span style="font-weight:bold;" t-out="format_amount(object.amount, object.currency_id) or ''">$ 143,750.00</span>
to our organization. This contribution is a testament to your commitment and trust in our work.
<br />
<br />
With this collaboration you help us move forward with our mission. We sincerely appreciate your support.
<br />
<br />
Cordially,
<br />
<br />
<t t-out="object.company_id.name or ''">
--
<br/>
Association name
</t>
</p>
</div>
</field>

<field name="lang">{{ object.partner_id.lang }}</field>
<field name="report_name">Donation Certificate</field>
</record>
</data>
</odoo>
28 changes: 28 additions & 0 deletions donation_certificate/data/py3o_certificate_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="py3o_template_certificate_ES" model="py3o.template">
<field name="name">Donation Certificate ES</field>
<field name="filetype">odt</field>
<field name="py3o_template_fallback">report/PDA34_Certificat_de_donacions_ES.odt</field>
</record>

<record id="py3o_template_certificate_CAT" model="py3o.template">
<field name="name">Donation Certificate CAT</field>
<field name="filetype">odt</field>
<field name="py3o_template_fallback">report/PDA34_Certificat_de_donacions_CAT.odt</field>
</record>

<record id="py3o_template_certificate_FR" model="py3o.template">
<field name="name">Donation Certificate FR</field>
<field name="filetype">odt</field>
<field name="py3o_template_fallback">report/PDA34_Certificat_de_donacions_FR.odt</field>
</record>

<record id="py3o_template_certificate_EN" model="py3o.template">
<field name="name">Donation Certificate EN</field>
<field name="filetype">odt</field>
<field name="py3o_template_fallback">report/PDA34_Certificat_de_donacions_EN.odt</field>
</record>

</odoo>
4 changes: 4 additions & 0 deletions donation_certificate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import py3o_report
from . import py3o_template
from . import donation
from . import donation_tax_receipt
70 changes: 70 additions & 0 deletions donation_certificate/models/donation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from odoo import _, fields, models
from odoo.exceptions import ValidationError
from odoo.tools import get_lang


class Donation(models.Model):
_inherit = "donation.donation"

is_certificate_send = fields.Boolean(
help="This field automatically becomes active when "
"the thanks letter has been send.",
)
attachment_ids = fields.One2many(
'ir.attachment',
'res_id',
domain=[('res_model', '=', 'donation.donation')],
string='Attachments'
)

def action_send_certificate(self):
self.ensure_one()
if not self.tax_receipt_id and self.tax_receipt_option == 'annual':
raise ValidationError(_("Annual receipt has not been generated yet."))
self.write({"is_certificate_send": True})
template = self.env.ref(self._get_mail_template(), raise_if_not_found=False)
lang = False
if template:
lang = template._render_lang(self.ids)[self.id]
if not lang:
lang = get_lang(self.env).code
compose_form = self.env.ref('donation_certificate.donation_certificate_send_wizard_form', raise_if_not_found=False)
ctx = dict(
default_model='donation.tax.receipt',
default_res_id=self.tax_receipt_id.id,
default_res_model='donation.tax.receipt',
default_use_template=bool(template),
default_template_id=template and template.id or False,
default_composition_mode='comment',
mark_invoice_as_sent=True,
default_email_layout_xmlid="mail.mail_notification_layout_with_responsible_signature",
force_email=True,
active_ids=self.tax_receipt_id.ids,
)
report_action = {
'name': _('Send Certificate'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'donation.certificate.send',
'views': [(compose_form.id, 'form')],
'view_id': compose_form.id,
'target': 'new',
'context': ctx,
}
return report_action

def action_print_tax_receipt(self):
""" Print the certificate and mark it as sent, so that we can see more
easily the next step of the workflow
"""
self.filtered(lambda r: not r.is_certificate_send).write({'is_certificate_send': True})
return self.env.ref('donation_certificate.donation_certificate_report_py3o').report_action(self)

def _get_mail_template(self):
"""
:return: the correct mail template based on the current move type
"""
return (
'donation_certificate.email_template_donation_certificate'
)
90 changes: 90 additions & 0 deletions donation_certificate/models/donation_tax_receipt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
from odoo import _, fields, models, api
from odoo.tools import get_lang


class DonationTaxReceipt(models.Model):
_inherit = "donation.tax.receipt"

is_certificate_send = fields.Boolean(
help="This field automatically becomes active when "
"the thanks letter has been send.",
)
attachment_ids = fields.One2many('ir.attachment', 'res_id', domain=[('res_model', '=', 'donation.tax.receipt')], string='Attachments')
amount_donation = fields.Monetary(tracking=True, compute="_compute_amounts")
amount_donation_in_kind_consu = fields.Monetary(tracking=True, compute="_compute_amounts")
amount_donation_in_kind_service = fields.Monetary(tracking=True, compute="_compute_amounts")

@api.depends('donation_ids')
def _compute_amounts(self):
for rec in self:
amount_donation = 0
amount_donation_in_kind_consu = 0
amount_donation_in_kind_service = 0
for donation in rec.donation_ids:
for line in donation.line_ids:
if line.product_id.detailed_type == 'donation':
amount_donation = amount_donation + line.amount
elif line.product_id.detailed_type == 'donation_in_kind_consu':
amount_donation_in_kind_consu = amount_donation_in_kind_consu + line.amount
else:
amount_donation_in_kind_service = amount_donation_in_kind_service + line.amount
rec.amount_donation = round(amount_donation, 2)
rec.amount_donation_in_kind_consu = round(amount_donation_in_kind_consu, 2)
rec.amount_donation_in_kind_service = round(amount_donation_in_kind_service, 2)

def action_send_tax_receipt(self):
self.write({"is_certificate_send": True})
template = self.env.ref(self._get_mail_template(), raise_if_not_found=False)
compose_form = self.env.ref('donation_certificate.donation_certificate_send_wizard_form', raise_if_not_found=False)
ctx = dict(
default_model='donation.tax.receipt',
default_res_model='donation.tax.receipt',
default_use_template=bool(template),
default_template_id=template and template.id or False,
default_composition_mode='comment',
mark_invoice_as_sent=True,
default_email_layout_xmlid="mail.mail_notification_layout_with_responsible_signature",
force_email=True,
active_ids=self.ids,
)
report_action = {
'name': _('Send Certificate'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'donation.certificate.send',
'views': [(compose_form.id, 'form')],
'view_id': compose_form.id,
'target': 'new',
'context': ctx,
}
return report_action

def get_ref_report_name(self, lang):
report_names = {
'es_ES': "donation_certificate.donation_certificate_report_py3o_ES",
'ca_ES': "donation_certificate.donation_certificate_report_py3o_CAT",
'fr_FR': "donation_certificate.donation_certificate_report_py3o_FR",
'en_GB': "donation_certificate.donation_certificate_report_py3o_EN"
}

return report_names.get(lang, "donation_certificate.donation_certificate_report_py3o_EN")

def action_print_tax_receipt(self):
""" Print the certificate and mark it as sent, so that we can see more
easily the next step of the workflow
"""
today = fields.Date.context_today(self)
self.write({"print_date": today})
self.filtered(lambda inv: not inv.is_certificate_send).write({'is_certificate_send': True})
lang = get_lang(self.env).code
report_action_py3o = self.get_ref_report_name(lang)
return self.env.ref(report_action_py3o).report_action(self)

def _get_mail_template(self):
"""
:return: the correct mail template based on the current move type
"""
return (
'donation_certificate.email_template_donation_certificate'
)
18 changes: 18 additions & 0 deletions donation_certificate/models/py3o_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2013 XCG Consulting (http://odoo.consulting)
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
from odoo import models


class Py3oReport(models.TransientModel):
_inherit = "py3o.report"

def _merge_results(self, reports_path):
self.ensure_one()
filetype = self.ir_actions_report_id.py3o_filetype
if not reports_path:
return False, False
if len(reports_path) == 1:
return reports_path[0], filetype
else:
return self._zip_results(reports_path), "zip"
34 changes: 34 additions & 0 deletions donation_certificate/models/py3o_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from odoo import fields, models, api
from base64 import b64encode
# import sys
import pkg_resources
# import os


class Py3oTemplate(models.Model):
_inherit = "py3o.template"

py3o_template_fallback = fields.Char(
"Fallback",
size=128,
help=(
"If the user does not provide a template this will be used "
"it should be a relative path to root of YOUR module "
"or an absolute path on your server."
),
)

@api.model_create_multi
def create(self, vals_list):
module = "donation_certificate"
vals = vals_list[0]
if vals['py3o_template_fallback']:
flbk_filename = pkg_resources.resource_filename(
"odoo.addons.%s" % module, vals['py3o_template_fallback']
)
with open(flbk_filename, "rb") as tmpl:
tmpl_data = b64encode(tmpl.read())
vals['py3o_template_data'] = tmpl_data
# if not rec.py3o_template_data:
# rec.py3o_template_data = False
return super().create([vals])
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions donation_certificate/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_donation_certificate_send,donation.certificate.send,donation_certificate.model_donation_certificate_send,base.group_user,1,1,1,1
access_donation_donation,donation.donation,donation.model_donation_donation,base.group_user,1,1,1,1
access_donation_tax_receipt,donation.tax.receipt,model_donation_tax_receipt,base.group_user,1,1,1,1
access_tax_receipt_annual_create,tax.receipt.annual.create,model_tax_receipt_annual_create,base.group_user,1,1,1,1
access_py3o_template,py3o.template,report_py3o.model_py3o_template,base.group_user,1,1,1,1
access_donation_tax_receipt_print,donation.tax.receipt.print,donation_base.model_donation_tax_receipt_print,base.group_user,1,1,1,1
Binary file added donation_certificate/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1c2ec72

Please sign in to comment.