Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] donation & donation_base: 6 improvements #124

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions donation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
"post_init_hook": "update_account_payment_mode",
"demo": ["demo/donation_demo.xml"],
"installable": True,
"application": True,
}
6 changes: 6 additions & 0 deletions donation/models/account_bank_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ def _prepare_donation_vals(self, stline, move_line, payment_mode):
"product_id": company.donation_credit_transfer_product_id.id,
"quantity": 1,
"unit_price": amount,
"analytic_account_id": move_line.analytic_account_id.id or False,
}
# https://github.com/ows-cloud/apps/tree/14.0/donation_analytic_description
if "donation_description" in self.env["account.analytic.account"]._fields:
line_vals["description"] = move_line.analytic_account_id.with_context(
lang=stline.partner_id.lang
).donation_description
partner = stline.partner_id
vals = {
"company_id": company.id,
Expand Down
17 changes: 17 additions & 0 deletions donation/models/donation.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ def _compute_country_id(self):
store=True,
index=True,
)
partner_address_ok = fields.Boolean(
related="partner_id.address_ok",
string="Donor address OK",
)
partner_email = fields.Char(
related="partner_id.email",
string="Donor email",
)
partner_lang = fields.Selection(
related="partner_id.lang",
string="Donor language",
)
partner_tag_ids = fields.Many2many(
string="Donor Tags",
related="partner_id.category_id",
help="Use tags on the donor to segment e.g. communication (email / snailmail)",
)
# country_id is here to have stats per country
# WARNING : I can't put a related field, because when someone
# writes on the country_id of a partner, it will trigger a write
Expand Down
6 changes: 6 additions & 0 deletions donation/models/donation_tax_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class DonationTaxReceipt(models.Model):
donation_ids = fields.One2many(
"donation.donation", "tax_receipt_id", string="Related Donations"
)
thanks_template_id = fields.Many2one(
"donation.thanks.template",
string="Thanks Template",
ondelete="restrict",
copy=False,
)

@api.model
def update_tax_receipt_annual_dict(
Expand Down
17 changes: 17 additions & 0 deletions donation/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,29 @@ def _compute_donation_count(self):
for partner in self:
partner.donation_count = mapped_data.get(partner.id, 0)

@api.depends("donation_ids.thanks_printed")
def _compute_donation_send_thanks(self):
for partner in self:
if partner.donation_ids.filtered(lambda d: not d.thanks_printed):
partner.donation_send_thanks = "yes"
else:
partner.donation_send_thanks = "no"

donation_ids = fields.One2many(
"donation.donation", "partner_id", string="Donations", readonly=True
)
donation_count = fields.Integer(
compute="_compute_donation_count", string="# of Donations", compute_sudo=True
)
# Stored selection to search on the <field>
donation_send_thanks = fields.Selection(
string="Send Donation Thanks",
selection=[("yes", "Yes"), ("no", "No")],
compute="_compute_donation_send_thanks",
store=True,
help="""Filter on donors who (don't) need a thanks.\n
Send it e.g. together with a newsletter.""",
)

def _prepare_donor_rank(self):
rank = super()._prepare_donor_rank()
Expand Down
20 changes: 15 additions & 5 deletions donation/views/donation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,17 @@
<group name="main">
<group name="manual">
<field name="partner_id" />
<field name="partner_address_ok" />
<field name="partner_email" />
<field name="partner_lang" />
<field name="partner_tag_ids" widget="many2many_tags" />
<field name="commercial_partner_id" invisible="1" />
<field name="payment_mode_id" widget="selection" />
<field
name="currency_id"
groups="base.group_multi_currency"
/>
<field name="company_currency_id" invisible="1" />
<field name="company_currency_id" invisible="1" />
<field
name="check_total"
groups="donation.group_donation_check_total"
Expand Down Expand Up @@ -149,14 +153,14 @@
<field name="arch" type="xml">
<tree>
<header>
<button
<button
name="%(donation_validate_action)d"
type="action"
string="Validate"
groups="donation.group_donation_user"
invisible="context.get('recurring_view')"
/>
<button
<button
name="thanks_printed_button"
type="object"
string="Mark as Thanks Printed"
Expand All @@ -166,9 +170,13 @@
/>
<!-- Unfortunately, confirm="" doesn't work for
buttons in tree view... at least not in v14 -->
</header>
</header>
<field name="number" invisible="context.get('recurring_view')" />
<field name="partner_id" invisible="context.get('partner_view')" />
<field name="partner_address_ok" optional="hide" />
<field name="partner_email" optional="hide" />
<field name="partner_lang" optional="hide" />
<field name="partner_tag_ids" widget="many2many_tags" optional="hide" />
<field name="donation_date" />
<field name="amount_total_company_currency" sum="1" />
<field name="amount_total" optional="hide" />
Expand Down Expand Up @@ -209,6 +217,8 @@
<search string="Search Donations">
<field name="number" />
<field name="partner_id" />
<field name="partner_lang" />
<field name="partner_tag_ids" widget="many2many_tags" />
<separator />
<filter
name="draft"
Expand All @@ -222,7 +232,7 @@
domain="[('state', '=', 'cancel')]"
/>
<separator />
<filter
<filter
name="thanks_to_print"
string="Thanks to Print"
domain="[('thanks_printed', '=', False)]"
Expand Down
25 changes: 24 additions & 1 deletion donation/views/donation_tax_receipt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,38 @@
-->
<odoo>
<record id="donation_tax_receipt_form" model="ir.ui.view">
<field name="name">donation.donation.tax.receipt.form</field>
<field name="name">donation.tax.receipt.form</field>
<field name="model">donation.tax.receipt</field>
<field name="inherit_id" ref="donation_base.donation_tax_receipt_form" />
<field name="arch" type="xml">
<group name="main" position="inside">
<field name="thanks_template_id" />
</group>
<group name="main" position="after">
<group name="donations" string="Related Donations">
<field name="donation_ids" nolabel="1" />
</group>
</group>
</field>
</record>
<record id="donation_tax_receipt_tree" model="ir.ui.view">
<field name="name">donation.tax.receipt.tree</field>
<field name="model">donation.tax.receipt</field>
<field name="inherit_id" ref="donation_base.donation_tax_receipt_tree" />
<field name="arch" type="xml">
<tree position="inside">
<field name="thanks_template_id" optional="hide" />
</tree>
</field>
</record>
<record id="donation_tax_receipt_search" model="ir.ui.view">
<field name="name">donation.tax.receipt.search</field>
<field name="model">donation.tax.receipt</field>
<field name="inherit_id" ref="donation_base.donation_tax_receipt_search" />
<field name="arch" type="xml">
<search position="inside">
<field name="thanks_template_id" />
</search>
</field>
</record>
</odoo>
21 changes: 21 additions & 0 deletions donation/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,25 @@
</xpath>
</field>
</record>
<record id="res_partner_view_form_donation_send_thanks" model="ir.ui.view">
<field name="name">res.partner.view.form.donation.send.thanks</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="donation_base.view_partner_property_form" />
<field name="groups_id" eval="[(4, ref('donation.group_donation_viewer'))]" />
<field name="arch" type="xml">
<field name="tax_receipt_send" position="after">
<field name="donation_send_thanks" />
</field>
</field>
</record>
<record id="res_partner_view_search" model="ir.ui.view">
<field name="name">res.partner.view.search.donation</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="donation_base.res_partner_view_search" />
<field name="arch" type="xml">
<search position="inside">
<field name="donation_send_thanks" />
</search>
</field>
</record>
</odoo>
5 changes: 4 additions & 1 deletion donation_base/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"author": "Barroux Abbey, Akretion, Odoo Community Association (OCA)",
"maintainers": ["alexis-via"],
"website": "https://github.com/OCA/donation",
"depends": ["account"],
"depends": [
"account",
"partner_address_ok", # https://github.com/OCA/partner-contact/pull/1694
],
"data": [
"security/ir.model.access.csv",
"security/tax_receipt_security.xml",
Expand Down
17 changes: 17 additions & 0 deletions donation_base/models/donation_tax_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ class DonationTaxReceipt(models.Model):
domain=[("parent_id", "=", False)],
index=True,
)
partner_address_ok = fields.Boolean(
related="partner_id.address_ok",
string="Donor address OK",
)
partner_email = fields.Char(
related="partner_id.email",
string="Donor email",
)
partner_lang = fields.Selection(
related="partner_id.lang",
string="Donor language",
)
partner_tag_ids = fields.Many2many(
related="partner_id.category_id",
string="Donor tags",
help="Use tags on the donor to segment e.g. communication (email / snailmail)",
)
company_id = fields.Many2one(
"res.company",
string="Company",
Expand Down
17 changes: 17 additions & 0 deletions donation_base/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ class ResPartner(models.Model):
tax_receipt_count = fields.Integer(
compute="_compute_tax_receipt_count", string="# of Tax Receipts", readonly=True
)
# Stored selection to search on the <field>
tax_receipt_send = fields.Selection(
string="Send Donation Tax Receipt",
selection=[("yes", "Yes"), ("no", "No")],
compute="_compute_tax_receipt_send",
store=True,
help="""Filter on donors who (don't) need a tax receipt.\n
Send it e.g. together with a newsletter.""",
)
donor_rank = fields.Integer(default=0)

# I don't want to sync tax_receipt_option between parent and child
Expand All @@ -36,6 +45,14 @@ def _compute_tax_receipt_count(self):
for partner in self:
partner.tax_receipt_count = len(partner.tax_receipt_ids.ids)

@api.depends("tax_receipt_ids.print_date")
def _compute_tax_receipt_send(self):
for partner in self:
if partner.tax_receipt_ids.filtered(lambda d: not d.print_date):
partner.tax_receipt_send = "yes"
else:
partner.tax_receipt_send = "no"

@api.model_create_multi
def create(self, vals_list):
search_partner_mode = self.env.context.get("res_partner_search_mode")
Expand Down
18 changes: 18 additions & 0 deletions donation_base/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@ To configure this module, you need to:

* create donation products
* set the *Tax Receipt Option* on partners

By default, there will be a tax receipt for each donation.
If you want "Annual Tax Receipts" for everyone, do this:

* Open a contact with no parent. Under Sale & Purchase, Fiscal Information,
set the Tax Receipt Option to Annual Tax Receipt and save.
* Activate the Developer mode (debug=1). In the developer tools menu (bug icon),
Set Defaults. Select "Tax Receipt Option = Annual Tax Receipt" for "All users"
and "Save default."
* Update all existing contacts.
* * In list view, select ALL contacts, click Action - Export.
* * Select "I want to update data (import-compatible export)".
* * Add the "Tax Receipt Option" to the list of fields to export.
* * Export, download, open the spreadsheet, set "Annual Tax Receipt" on all lines, save.
* * Odoo contact list - Favorites - Import records - Load file - Import.

An Annual Tax Receipt will be sent to the "commercial partner".
If a contact is not a company and has a "parent", the parent is the commercial partner.
10 changes: 10 additions & 0 deletions donation_base/views/donation_tax_receipt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
options="{'datepicker': {'warn_future': true}}"
/>
<field name="partner_id" />
<field name="partner_address_ok" />
<field name="partner_email" />
<field name="partner_lang" />
<field name="partner_tag_ids" widget="many2many_tags" />
<field name="type" widget="radio" />
<field
name="donation_date"
Expand All @@ -54,6 +58,10 @@
<tree>
<field name="number" />
<field name="partner_id" />
<field name="partner_address_ok" optional="hide" />
<field name="partner_email" optional="hide" />
<field name="partner_lang" optional="hide" />
<field name="partner_tag_ids" widget="many2many_tags" optional="hide" />
<field name="date" />
<field name="donation_date" optional="hide" />
<field
Expand Down Expand Up @@ -81,6 +89,8 @@
<search string="Search Donation Tax Receipts">
<field name="number" />
<field name="partner_id" />
<field name="partner_lang" />
<field name="partner_tag_ids" />
<filter
name="each"
string="One-Time Tax Receipts"
Expand Down
21 changes: 14 additions & 7 deletions donation_base/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
name="tax_receipt_option"
attrs="{'invisible': [('parent_id', '!=', False)]}"
/>
<field
name="tax_receipt_send"
attrs="{'invisible': [('parent_id', '!=', False)]}"
/>
<field name="donor_rank" invisible="1" />
</field>
<xpath expr="//div[@name='button_box']" position="inside">
Expand All @@ -44,19 +48,22 @@
</button>
</xpath>
</field>
</record>
</record>
<record id="res_partner_view_search" model="ir.ui.view">
<field name="name">donation.res.partner.search</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="account.res_partner_view_search" />
<field name="arch" type="xml">
<filter name="supplier" position="after">
<filter
string="Donors"
name="donor"
domain="[('donor_rank','>', 0)]"
/>
<filter name="supplier" position="after">
<filter
string="Donors"
name="donor"
domain="[('donor_rank','>', 0)]"
/>
</filter>
<search position="inside">
<field name="tax_receipt_send" />
</search>
</field>
</record>
<record id="res_partner_action_donor" model="ir.actions.act_window">
Expand Down
Loading