diff --git a/donation/README.rst b/donation/README.rst index d07d376ac..403e28372 100644 --- a/donation/README.rst +++ b/donation/README.rst @@ -1,14 +1,39 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 - ======== Donation ======== +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdonation-lightgray.png?logo=github + :target: https://github.com/OCA/donation/tree/12.0/donation + :alt: OCA/donation +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/donation-12-0/donation-12-0-donation + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/180/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + This module handles donations, including in-kind donations. When you validate a donation, it will create the corresponding accounting entries. + +**Table of contents** + +.. contents:: + :local: + Configuration ============= @@ -18,6 +43,7 @@ To configure this module, you need to: * activate the option *Donation Payment Method* on some bank/cash account journals * if you wish to have a control amount on the donation, add the users to the group *Check Total on supplier invoices* + Usage ===== @@ -29,19 +55,28 @@ To have some statistics about the donations, go to the menu Reporting > Donation :alt: Try me on Runbot :target: https://runbot.odoo-community.org/runbot/180/11.0 + Bug Tracker =========== -Bugs are tracked on `GitHub Issues -`_. In case of trouble, please -check there if your issue has already been reported. If you spotted it first, -help us smashing it by providing a detailed and welcomed feedback. +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= +Authors +~~~~~~~ + +* Barroux Abbey +* Akretion + Contributors ------------- +~~~~~~~~~~~~ * Brother Bernard * Brother Irénée (Barroux Abbey) @@ -49,17 +84,20 @@ Contributors * Serpent Consulting Services Pvt. Ltd. * Nikul Chaudhary -Maintainer ----------- + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit https://odoo-community.org. +This module is part of the `OCA/donation `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/donation/models/donation.py b/donation/models/donation.py index 69aa4e7aa..45674f6c4 100644 --- a/donation/models/donation.py +++ b/donation/models/donation.py @@ -20,7 +20,6 @@ class DonationDonation(models.Model): def _compute_total(self): for donation in self: total = tax_receipt_total = 0.0 - donation_currency = donation.currency_id for line in donation.line_ids: line_total = line.quantity * line.unit_price total += line_total @@ -31,10 +30,18 @@ def _compute_total(self): donation_currency =\ donation.currency_id.with_context(date=donation.donation_date) company_currency = donation.company_currency_id - total_company_currency = donation_currency.compute( - total, company_currency) - tax_receipt_total_cc = donation_currency.compute( - tax_receipt_total, company_currency) + total_company_currency = donation_currency._convert( + total, + company_currency, + donation.company_id, + donation.donation_date + ) + tax_receipt_total_cc = donation_currency._convert( + tax_receipt_total, + company_currency, + donation.company_id, + donation.donation_date + ) donation.amount_total_company_currency = total_company_currency donation.tax_receipt_total = tax_receipt_total_cc @@ -349,7 +356,7 @@ def validate(self): raise UserError(_( 'The date of the donation of %s should be today ' 'or in the past, not in the future!') - % donation.partner_id.name) + % donation.partner_id.name) if not donation.line_ids: raise UserError(_( "Cannot validate the donation of %s because it doesn't " @@ -521,8 +528,12 @@ def _compute_amount(self): line.amount = amount donation_currency = line.donation_id.currency_id.with_context( date=line.donation_id.donation_date) - amount_company_currency = donation_currency.compute( - amount, line.donation_id.company_id.currency_id) + amount_company_currency = donation_currency._convert( + amount, + line.donation_id.company_id.currency_id, + line.donation_id.company_id, + line.donation_id.donation_date + ) tax_receipt_amount_cc = 0.0 if line.product_id.tax_receipt_ok: tax_receipt_amount_cc = amount_company_currency @@ -544,7 +555,8 @@ def _compute_amount(self): 'res.currency', related='donation_id.company_id.currency_id', readonly=True, - compute_sudo=True + compute_sudo=True, + string="Company Currency" ) product_id = fields.Many2one( 'product.product', diff --git a/donation/models/donation_campaign.py b/donation/models/donation_campaign.py index 70a3638a4..3e6a1b8b8 100644 --- a/donation/models/donation_campaign.py +++ b/donation/models/donation_campaign.py @@ -29,4 +29,4 @@ def name_get(self): 'Start Date', default=fields.Date.context_today ) - note = fields.Text('Notes') + note = fields.Text('Notes', oldname='nota') diff --git a/donation/post_install.py b/donation/post_install.py index 77ee427dc..9a7c1b017 100644 --- a/donation/post_install.py +++ b/donation/post_install.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016 Akretion (Alexis de Lattre ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/donation/report/donation_report.py b/donation/report/donation_report.py index 089198c8b..8c25a4949 100644 --- a/donation/report/donation_report.py +++ b/donation/report/donation_report.py @@ -4,6 +4,7 @@ from odoo import tools from odoo import models, fields +from psycopg2 import sql class DonationReport(models.Model): @@ -66,7 +67,7 @@ class DonationReport(models.Model): ) def _select(self): - select = """ + return sql.SQL(""" SELECT min(l.id) AS id, d.donation_date AS donation_date, l.product_id AS product_id, @@ -80,26 +81,23 @@ def _select(self): d.company_currency_id AS company_currency_id, sum(l.amount_company_currency) AS amount_company_currency, sum(l.tax_receipt_amount) AS tax_receipt_amount - """ - return select + """) def _from(self): - from_sql = """ + return sql.SQL(""" donation_line l LEFT JOIN donation_donation d ON (d.id=l.donation_id) LEFT JOIN product_product pp ON (l.product_id=pp.id) LEFT JOIN product_template pt ON (pp.product_tmpl_id=pt.id) - """ - return from_sql + """) def _where(self): - where = """ + return sql.SQL(""" WHERE d.state='done' - """ - return where + """) def _group_by(self): - group_by = """ + return sql.SQL(""" GROUP BY l.product_id, l.in_kind, l.tax_receipt_ok, @@ -110,12 +108,17 @@ def _group_by(self): d.campaign_id, d.company_id, d.company_currency_id - """ - return group_by + """) def init(self): tools.drop_view_if_exists(self._cr, self._table) - sql = "CREATE OR REPLACE VIEW %s AS (%s FROM %s %s %s)" % ( - self._table, self._select(), self._from(), - self._where(), self._group_by()) - self._cr.execute(sql) + query = sql.SQL( + "CREATE OR REPLACE VIEW {0} AS ({1} FROM {2} {3} {4})" + ).format( + sql.Identifier(self._table), + self._select(), + self._from(), + self._where(), + self._group_by(), + ) # pylint: disable=sql-injection + self._cr.execute(query) diff --git a/donation/static/description/icon.png b/donation/static/description/icon.png index f443e075f..a9a295465 100644 Binary files a/donation/static/description/icon.png and b/donation/static/description/icon.png differ diff --git a/donation/static/description/icon.svg b/donation/static/description/icon.svg new file mode 100644 index 000000000..6b8d94559 --- /dev/null +++ b/donation/static/description/icon.svg @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/donation/tests/test_donation.py b/donation/tests/test_donation.py index a564baa94..203ac8063 100644 --- a/donation/tests/test_donation.py +++ b/donation/tests/test_donation.py @@ -3,7 +3,7 @@ import time from odoo.tests.common import TransactionCase -from odoo import tools +from odoo import fields, tools from odoo.modules.module import get_resource_path from odoo.exceptions import ValidationError @@ -101,7 +101,7 @@ def setUp(self): ], }) - def test_donation(self): + def test_donation_1(self): donations = [self.don1, self.don2, self.don3, self.don4, self.don5] for donation in donations: self.assertEquals(donation.state, 'draft') @@ -129,6 +129,31 @@ def test_donation(self): self.assertEquals( donation.tax_receipt_total, tax_receipt.amount) + def test_donation_2(self): + self.donation_id = self.ddo.create({ + 'check_total': 1000, + 'partner_id': self.donor1.id, + 'donation_date': time.strftime('%Y-%m-%d'), + 'journal_id': self.bank_journal.id, + 'tax_receipt_option': 'each', + 'line_ids': [(0, 0, { + 'product_id': self.inkind_product.id, + 'quantity': 1, + 'unit_price': 1000, + })], + }) + self.donation_id.name_get() + self.donation_id.save_default_values() + self.donation_id.partner_id_change() + self.donation_id.tax_receipt_option_change() + self.donation_id.validate() + self.donation_id.line_ids[0]._compute_amount() + self.donation_id.line_ids[0].product_id_change() + self.donation_id.tax_receipt_id = False + self.donation_id.done2cancel() + self.donation_id.cancel2draft() + self.donation_id.unlink() + def test_annual_tax_receipt(self): self.res_partner = self.env['res.partner'] @@ -167,8 +192,12 @@ def test_annual_tax_receipt(self): tax_receipt = tax_receipts[0] self.assertEquals(tax_receipt.amount, 200) self.assertTrue(tax_receipt.number) - self.assertEquals(tax_receipt.date, last_day_year) - self.assertEquals(tax_receipt.donation_date, last_day_year) + self.assertEquals( + tax_receipt.date, fields.Date.from_string(last_day_year) + ) + self.assertEquals( + tax_receipt.donation_date, fields.Date.from_string(last_day_year) + ) self.assertEquals( tax_receipt.currency_id, dons[0].company_id.currency_id) @@ -212,31 +241,6 @@ def test_donation_campaign(self): self.don8.tax_receipt_id = False wizard.switch() - def test_donation(self): - self.donation_id = self.ddo.create({ - 'check_total': 1000, - 'partner_id': self.donor1.id, - 'donation_date': time.strftime('%Y-%m-%d'), - 'journal_id': self.bank_journal.id, - 'tax_receipt_option': 'each', - 'line_ids': [(0, 0, { - 'product_id': self.inkind_product.id, - 'quantity': 1, - 'unit_price': 1000, - })], - }) - self.donation_id.name_get() - self.donation_id.save_default_values() - self.donation_id.partner_id_change() - self.donation_id.tax_receipt_option_change() - self.donation_id.validate() - self.donation_id.line_ids[0]._compute_amount() - self.donation_id.line_ids[0].product_id_change() - self.donation_id.tax_receipt_id = False - self.donation_id.done2cancel() - self.donation_id.cancel2draft() - self.donation_id.unlink() - def create_donation_annual_receipt( self, partner, amount_tax_receipt, amount_no_tax_receipt, payment_ref): diff --git a/donation/views/donation.xml b/donation/views/donation.xml index 6c87caf49..60caf7206 100644 --- a/donation/views/donation.xml +++ b/donation/views/donation.xml @@ -202,8 +202,9 @@ tree,form - +