From 759d88cce381793fb1397530d5dd1005bdfb449a Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Thu, 30 Oct 2014 12:40:35 +0100 Subject: [PATCH 01/10] [ADD] account_cash_discount_compute addons --- .travis.yml | 2 + account_cash_discount_compute/__init__.py | 31 ++++++ account_cash_discount_compute/__openerp__.py | 55 ++++++++++ .../models/__init__.py | 31 ++++++ .../models/account_invoice.py | 89 +++++++++++++++ .../reports/report_invoice.xml | 16 +++ .../tests/__init__.py | 36 ++++++ .../test_account_cash_discount_compute.py | 103 ++++++++++++++++++ .../views/account_invoice_view.xml | 33 ++++++ 9 files changed, 396 insertions(+) create mode 100644 account_cash_discount_compute/__init__.py create mode 100644 account_cash_discount_compute/__openerp__.py create mode 100644 account_cash_discount_compute/models/__init__.py create mode 100644 account_cash_discount_compute/models/account_invoice.py create mode 100644 account_cash_discount_compute/reports/report_invoice.xml create mode 100644 account_cash_discount_compute/tests/__init__.py create mode 100644 account_cash_discount_compute/tests/test_account_cash_discount_compute.py create mode 100644 account_cash_discount_compute/views/account_invoice_view.xml diff --git a/.travis.yml b/.travis.yml index 6bfb1bd2e..9ee53fc46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,8 @@ virtualenv: install: - git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools + - git clone https://github.com/OCA/account-financial-reporting ${HOME}/account-financial-reporting -b ${VERSION} + - git clone -b 8.0-add-account-cash-discount-base-ape https://github.com/acsone/banking.git ${HOME}/banking-cash-discount-base - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} - pip install xlrd pycoda unidecode - travis_install_nightly diff --git a/account_cash_discount_compute/__init__.py b/account_cash_discount_compute/__init__.py new file mode 100644 index 000000000..59b28fbb5 --- /dev/null +++ b/account_cash_discount_compute/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# +############################################################################## +# +# Authors: Adrien Peiffer +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import models diff --git a/account_cash_discount_compute/__openerp__.py b/account_cash_discount_compute/__openerp__.py new file mode 100644 index 000000000..aa41712df --- /dev/null +++ b/account_cash_discount_compute/__openerp__.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# +############################################################################## +# +# Authors: Adrien Peiffer +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + "name": "Account Cash Discount Compute", + "version": "1.0", + "author": "ACSONE SA/NV", + "maintainer": "ACSONE SA/NV", + "website": "http://www.acsone.eu", + "images": [], + "category": "Accounting", + "depends": [ + "account_cash_discount_base", + ], + "description": """ + Account Cash Discount Compute +""", + "data": [ + 'views/account_invoice_view.xml', + 'reports/report_invoice.xml', + ], + "demo": [], + "test": [], + "licence": "AGPL-3", + "installable": True, + "auto_install": False, + "application": True, +} diff --git a/account_cash_discount_compute/models/__init__.py b/account_cash_discount_compute/models/__init__.py new file mode 100644 index 000000000..afc1f694f --- /dev/null +++ b/account_cash_discount_compute/models/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# +############################################################################## +# +# Authors: Adrien Peiffer +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import account_invoice diff --git a/account_cash_discount_compute/models/account_invoice.py b/account_cash_discount_compute/models/account_invoice.py new file mode 100644 index 000000000..fa3038984 --- /dev/null +++ b/account_cash_discount_compute/models/account_invoice.py @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- +# +############################################################################## +# +# Authors: Adrien Peiffer +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp import api, models, fields +from datetime import datetime, timedelta +from openerp.tools import DEFAULT_SERVER_DATE_FORMAT + +BelgiumBaseTaxCodesIn = ['81', '82', '83', '84', '85', '86', '87', '88'] +BelgiumBaseTaxCodesOut = ['00', '01', '02', '03', '44', '45', '46', '46L', + '46T', '47', '48', '48s44', '48s46L', '48s46T', '49'] +BelgiumBaseTaxCodes = BelgiumBaseTaxCodesIn + BelgiumBaseTaxCodesOut + + +class account_invoice(models.Model): + _inherit = 'account.invoice' + + discount_percent = fields.Float(string='Discount Percent') + discount_delay = fields.Integer(string='Discount Delay (days)') + + @api.one + @api.onchange('discount_percent') + def discount_percent_change(self): + discount = self.amount_untaxed * (0.0 + self.discount_percent/100) + self.discount_amount = discount + return + + @api.one + @api.onchange('discount_delay', 'date_invoice') + def discount_delay_change(self): + if self.date_invoice: + date_invoice = self.date_invoice + date_invoice = datetime.strptime(date_invoice, + DEFAULT_SERVER_DATE_FORMAT) + else: + date_invoice = datetime.now() + due_date = date_invoice + timedelta(days=self.discount_delay) + self.discount_due_date = due_date.date() + + +class account_invoice_tax(models.Model): + _inherit = 'account.invoice.tax' + + def compute(self, invoice): + tax_grouped = super(account_invoice_tax, self).compute(invoice) + currency = invoice.currency_id\ + .with_context(date=invoice.date_invoice or + fields.Date.context_today(invoice)) + pct = invoice.discount_percent + if pct: + multiplier = 1-pct/100 + atc_obj = self.env['account.tax.code'] + belgium_btc = atc_obj.search([('code', 'in', + BelgiumBaseTaxCodes)]) + for t in tax_grouped.values(): + if t['base_code_id'] in belgium_btc.ids: + t['base'] = currency.round(t['base'] * multiplier) + t['amount'] = currency.round(t['amount'] * multiplier) + t['base_amount'] = currency.round(t['base_amount'] * + multiplier) + t['tax_amount'] = currency.round(t['tax_amount'] * + multiplier) + return tax_grouped diff --git a/account_cash_discount_compute/reports/report_invoice.xml b/account_cash_discount_compute/reports/report_invoice.xml new file mode 100644 index 000000000..7391a230f --- /dev/null +++ b/account_cash_discount_compute/reports/report_invoice.xml @@ -0,0 +1,16 @@ + + + + + + diff --git a/account_cash_discount_compute/tests/__init__.py b/account_cash_discount_compute/tests/__init__.py new file mode 100644 index 000000000..419c305e7 --- /dev/null +++ b/account_cash_discount_compute/tests/__init__.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# +############################################################################## +# +# Authors: Adrien Peiffer +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +# + +from . import test_account_cash_discount_compute + +checks = [ + test_account_cash_discount_compute, +] diff --git a/account_cash_discount_compute/tests/test_account_cash_discount_compute.py b/account_cash_discount_compute/tests/test_account_cash_discount_compute.py new file mode 100644 index 000000000..51bba8fe5 --- /dev/null +++ b/account_cash_discount_compute/tests/test_account_cash_discount_compute.py @@ -0,0 +1,103 @@ +# -*- coding: utf-8 -*- +# +############################################################################## +# +# Authors: Adrien Peiffer +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import openerp.tests.common as common +from datetime import datetime +from openerp.tools import DEFAULT_SERVER_DATE_FORMAT +import logging +_logger = logging.getLogger(__name__) + + +DB = common.DB +ADMIN_USER_ID = common.ADMIN_USER_ID + + +def create_simple_invoice(self, date, tax_id): + journal_id = self.ref('account.sales_journal') + partner_id = self.ref('base.res_partner_2') + product_id = self.ref('product.product_product_4') + return self.env['account.invoice']\ + .create({'partner_id': partner_id, + 'account_id': + self.ref('account.a_recv'), + 'journal_id': + journal_id, + 'discount_due_date': date, + 'discount_percent': 10.0, + 'date_invoice': date, + 'invoice_line': [(0, 0, {'name': 'test', + 'account_id': + self.ref('account.a_sale'), + 'price_unit': 2000.00, + 'quantity': 1, + 'product_id': product_id, + 'invoice_line_tax_id': [(4, tax_id)], + } + ) + ], + }) + + +def create_belgium_tax_code(self, code): + return self.env['account.tax.code'].create({'name': 'Belgium Tax Code', + 'code': code + }) + + +def create_tax(self, name, type_tax_use, compute_type, amount, base_code_id, + tax_code_id): + return self.env['account.tax'].create({'name': name, + 'type_tax_use': type_tax_use, + 'type': compute_type, + 'amount': amount, + 'base_code_id': base_code_id, + 'tax_code_id': tax_code_id, + }) + + +class TestAccountCashDiscountCompute(common.TransactionCase): + + def setUp(self): + super(TestAccountCashDiscountCompute, self).setUp() + self.context = self.registry("res.users").context_get(self.cr, + self.uid) + + def test_invoice_tax_discount(self): + tax_code = create_belgium_tax_code(self, '48') + tax = create_tax(self, 'Tax Test 21%', 'sale', 'percent', '0.21', + tax_code.id, tax_code.id) + today = datetime.now() + date = today.strftime(DEFAULT_SERVER_DATE_FORMAT) + invoice = create_simple_invoice(self, date, tax.id) + invoice.button_reset_taxes() + tax_line = invoice.tax_line + self.assertEqual(len(tax_line), 1, "Number of tax line isn't correct") + self.assertAlmostEqual(tax_line.base_amount, 1800, 2, + "Tax Base Amoount isn't correct") diff --git a/account_cash_discount_compute/views/account_invoice_view.xml b/account_cash_discount_compute/views/account_invoice_view.xml new file mode 100644 index 000000000..4e1399d7f --- /dev/null +++ b/account_cash_discount_compute/views/account_invoice_view.xml @@ -0,0 +1,33 @@ + + + + + account.invoice.supplier.form (account_cash_discount_compute) + account.invoice + + + + + + + + 0 + + + + + account.invoice.form (account_cash_discount_compute) + account.invoice + + + + + + + + 0 + + + + + \ No newline at end of file From 171b25435eb3fc6a3c4a1bd6413a8f528dd9eefc Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Tue, 2 Dec 2014 15:03:25 +0100 Subject: [PATCH 02/10] [IMP] Improve header --- account_cash_discount_compute/__init__.py | 8 -------- account_cash_discount_compute/__openerp__.py | 8 -------- account_cash_discount_compute/models/__init__.py | 8 -------- account_cash_discount_compute/models/account_invoice.py | 8 -------- account_cash_discount_compute/tests/__init__.py | 8 -------- .../tests/test_account_cash_discount_compute.py | 8 -------- 6 files changed, 48 deletions(-) diff --git a/account_cash_discount_compute/__init__.py b/account_cash_discount_compute/__init__.py index 59b28fbb5..7faae0bb7 100644 --- a/account_cash_discount_compute/__init__.py +++ b/account_cash_discount_compute/__init__.py @@ -4,14 +4,6 @@ # # Authors: Adrien Peiffer # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) -# All Rights Reserved -# -# WARNING: This program as such is intended to be used by professional -# programmers who take the whole responsibility of assessing all potential -# consequences resulting from its eventual inadequacies and bugs. -# End users who are looking for a ready-to-use solution with commercial -# guarantees and support are strongly advised to contact a Free Software -# Service Company. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as diff --git a/account_cash_discount_compute/__openerp__.py b/account_cash_discount_compute/__openerp__.py index aa41712df..79cb26981 100644 --- a/account_cash_discount_compute/__openerp__.py +++ b/account_cash_discount_compute/__openerp__.py @@ -4,14 +4,6 @@ # # Authors: Adrien Peiffer # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) -# All Rights Reserved -# -# WARNING: This program as such is intended to be used by professional -# programmers who take the whole responsibility of assessing all potential -# consequences resulting from its eventual inadequacies and bugs. -# End users who are looking for a ready-to-use solution with commercial -# guarantees and support are strongly advised to contact a Free Software -# Service Company. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as diff --git a/account_cash_discount_compute/models/__init__.py b/account_cash_discount_compute/models/__init__.py index afc1f694f..5ed28829d 100644 --- a/account_cash_discount_compute/models/__init__.py +++ b/account_cash_discount_compute/models/__init__.py @@ -4,14 +4,6 @@ # # Authors: Adrien Peiffer # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) -# All Rights Reserved -# -# WARNING: This program as such is intended to be used by professional -# programmers who take the whole responsibility of assessing all potential -# consequences resulting from its eventual inadequacies and bugs. -# End users who are looking for a ready-to-use solution with commercial -# guarantees and support are strongly advised to contact a Free Software -# Service Company. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as diff --git a/account_cash_discount_compute/models/account_invoice.py b/account_cash_discount_compute/models/account_invoice.py index fa3038984..c3745057f 100644 --- a/account_cash_discount_compute/models/account_invoice.py +++ b/account_cash_discount_compute/models/account_invoice.py @@ -4,14 +4,6 @@ # # Authors: Adrien Peiffer # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) -# All Rights Reserved -# -# WARNING: This program as such is intended to be used by professional -# programmers who take the whole responsibility of assessing all potential -# consequences resulting from its eventual inadequacies and bugs. -# End users who are looking for a ready-to-use solution with commercial -# guarantees and support are strongly advised to contact a Free Software -# Service Company. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as diff --git a/account_cash_discount_compute/tests/__init__.py b/account_cash_discount_compute/tests/__init__.py index 419c305e7..12dd7185a 100644 --- a/account_cash_discount_compute/tests/__init__.py +++ b/account_cash_discount_compute/tests/__init__.py @@ -4,14 +4,6 @@ # # Authors: Adrien Peiffer # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) -# All Rights Reserved -# -# WARNING: This program as such is intended to be used by professional -# programmers who take the whole responsibility of assessing all potential -# consequences resulting from its eventual inadequacies and bugs. -# End users who are looking for a ready-to-use solution with commercial -# guarantees and support are strongly advised to contact a Free Software -# Service Company. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as diff --git a/account_cash_discount_compute/tests/test_account_cash_discount_compute.py b/account_cash_discount_compute/tests/test_account_cash_discount_compute.py index 51bba8fe5..87f6f13c7 100644 --- a/account_cash_discount_compute/tests/test_account_cash_discount_compute.py +++ b/account_cash_discount_compute/tests/test_account_cash_discount_compute.py @@ -4,14 +4,6 @@ # # Authors: Adrien Peiffer # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) -# All Rights Reserved -# -# WARNING: This program as such is intended to be used by professional -# programmers who take the whole responsibility of assessing all potential -# consequences resulting from its eventual inadequacies and bugs. -# End users who are looking for a ready-to-use solution with commercial -# guarantees and support are strongly advised to contact a Free Software -# Service Company. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as From debc977c97324a42d153693158e39ed170000d74 Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Tue, 2 Dec 2014 15:07:56 +0100 Subject: [PATCH 03/10] [IMP] Rename account_cash_discount_compute to l10n_be_cash_discount --- .../__init__.py | 0 .../__openerp__.py | 2 +- .../models/__init__.py | 0 .../models/account_invoice.py | 0 .../reports/report_invoice.xml | 0 .../tests/__init__.py | 0 .../tests/test_account_cash_discount_compute.py | 0 .../views/account_invoice_view.xml | 0 8 files changed, 1 insertion(+), 1 deletion(-) rename {account_cash_discount_compute => l10n_be_cash_discount}/__init__.py (100%) rename {account_cash_discount_compute => l10n_be_cash_discount}/__openerp__.py (96%) rename {account_cash_discount_compute => l10n_be_cash_discount}/models/__init__.py (100%) rename {account_cash_discount_compute => l10n_be_cash_discount}/models/account_invoice.py (100%) rename {account_cash_discount_compute => l10n_be_cash_discount}/reports/report_invoice.xml (100%) rename {account_cash_discount_compute => l10n_be_cash_discount}/tests/__init__.py (100%) rename {account_cash_discount_compute => l10n_be_cash_discount}/tests/test_account_cash_discount_compute.py (100%) rename {account_cash_discount_compute => l10n_be_cash_discount}/views/account_invoice_view.xml (100%) diff --git a/account_cash_discount_compute/__init__.py b/l10n_be_cash_discount/__init__.py similarity index 100% rename from account_cash_discount_compute/__init__.py rename to l10n_be_cash_discount/__init__.py diff --git a/account_cash_discount_compute/__openerp__.py b/l10n_be_cash_discount/__openerp__.py similarity index 96% rename from account_cash_discount_compute/__openerp__.py rename to l10n_be_cash_discount/__openerp__.py index 79cb26981..f65c85104 100644 --- a/account_cash_discount_compute/__openerp__.py +++ b/l10n_be_cash_discount/__openerp__.py @@ -21,7 +21,7 @@ ############################################################################## { - "name": "Account Cash Discount Compute", + "name": "Belgium cash discount computation", "version": "1.0", "author": "ACSONE SA/NV", "maintainer": "ACSONE SA/NV", diff --git a/account_cash_discount_compute/models/__init__.py b/l10n_be_cash_discount/models/__init__.py similarity index 100% rename from account_cash_discount_compute/models/__init__.py rename to l10n_be_cash_discount/models/__init__.py diff --git a/account_cash_discount_compute/models/account_invoice.py b/l10n_be_cash_discount/models/account_invoice.py similarity index 100% rename from account_cash_discount_compute/models/account_invoice.py rename to l10n_be_cash_discount/models/account_invoice.py diff --git a/account_cash_discount_compute/reports/report_invoice.xml b/l10n_be_cash_discount/reports/report_invoice.xml similarity index 100% rename from account_cash_discount_compute/reports/report_invoice.xml rename to l10n_be_cash_discount/reports/report_invoice.xml diff --git a/account_cash_discount_compute/tests/__init__.py b/l10n_be_cash_discount/tests/__init__.py similarity index 100% rename from account_cash_discount_compute/tests/__init__.py rename to l10n_be_cash_discount/tests/__init__.py diff --git a/account_cash_discount_compute/tests/test_account_cash_discount_compute.py b/l10n_be_cash_discount/tests/test_account_cash_discount_compute.py similarity index 100% rename from account_cash_discount_compute/tests/test_account_cash_discount_compute.py rename to l10n_be_cash_discount/tests/test_account_cash_discount_compute.py diff --git a/account_cash_discount_compute/views/account_invoice_view.xml b/l10n_be_cash_discount/views/account_invoice_view.xml similarity index 100% rename from account_cash_discount_compute/views/account_invoice_view.xml rename to l10n_be_cash_discount/views/account_invoice_view.xml From a5492377b2f2eba73f4406afa5129204d82150ce Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Tue, 2 Dec 2014 15:08:34 +0100 Subject: [PATCH 04/10] [IMP] Replace description in __openerp__ file with README.rst --- l10n_be_cash_discount/README.rst | 12 ++++++++++++ l10n_be_cash_discount/__openerp__.py | 3 --- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 l10n_be_cash_discount/README.rst diff --git a/l10n_be_cash_discount/README.rst b/l10n_be_cash_discount/README.rst new file mode 100644 index 000000000..7e946f078 --- /dev/null +++ b/l10n_be_cash_discount/README.rst @@ -0,0 +1,12 @@ +Belgium cash discount computation +=== + +The module implements the Belgian method of applying taxes in presence of cash discount. + +The cash discount percentage is applied is applied on the amount without tax, and the VAT is computed on the discounted amount. + +Credits +--- + +* the computation algorithm has been designed by Luc De Meyer (Noviat) +* ACSONE implemented the current module structure and integrated with OCA/bank-payment diff --git a/l10n_be_cash_discount/__openerp__.py b/l10n_be_cash_discount/__openerp__.py index f65c85104..157a8ac7b 100644 --- a/l10n_be_cash_discount/__openerp__.py +++ b/l10n_be_cash_discount/__openerp__.py @@ -31,9 +31,6 @@ "depends": [ "account_cash_discount_base", ], - "description": """ - Account Cash Discount Compute -""", "data": [ 'views/account_invoice_view.xml', 'reports/report_invoice.xml', From 2639fb059a9d90bd9dcfa0555d1a45787f8cdfd1 Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Tue, 2 Dec 2014 15:11:00 +0100 Subject: [PATCH 05/10] [IMP] Not necessary to use checks list on 8.0 --- l10n_be_cash_discount/tests/__init__.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/l10n_be_cash_discount/tests/__init__.py b/l10n_be_cash_discount/tests/__init__.py index 12dd7185a..9254abb80 100644 --- a/l10n_be_cash_discount/tests/__init__.py +++ b/l10n_be_cash_discount/tests/__init__.py @@ -22,7 +22,3 @@ # from . import test_account_cash_discount_compute - -checks = [ - test_account_cash_discount_compute, -] From 9a53557dbdd9ec167ce5f209614d079885aacf55 Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Thu, 4 Dec 2014 14:03:04 +0100 Subject: [PATCH 06/10] [IMP] addons separation of functionality --- l10n_be_cash_discount/__openerp__.py | 1 - l10n_be_cash_discount/models/__init__.py | 2 +- ...ount_invoice.py => account_invoice_tax.py} | 29 +------------------ .../reports/report_invoice.xml | 16 ---------- .../views/account_invoice_view.xml | 8 ----- 5 files changed, 2 insertions(+), 54 deletions(-) rename l10n_be_cash_discount/models/{account_invoice.py => account_invoice_tax.py} (70%) delete mode 100644 l10n_be_cash_discount/reports/report_invoice.xml diff --git a/l10n_be_cash_discount/__openerp__.py b/l10n_be_cash_discount/__openerp__.py index 157a8ac7b..82259b11a 100644 --- a/l10n_be_cash_discount/__openerp__.py +++ b/l10n_be_cash_discount/__openerp__.py @@ -33,7 +33,6 @@ ], "data": [ 'views/account_invoice_view.xml', - 'reports/report_invoice.xml', ], "demo": [], "test": [], diff --git a/l10n_be_cash_discount/models/__init__.py b/l10n_be_cash_discount/models/__init__.py index 5ed28829d..97cb4fdd6 100644 --- a/l10n_be_cash_discount/models/__init__.py +++ b/l10n_be_cash_discount/models/__init__.py @@ -20,4 +20,4 @@ # ############################################################################## -from . import account_invoice +from . import account_invoice_tax diff --git a/l10n_be_cash_discount/models/account_invoice.py b/l10n_be_cash_discount/models/account_invoice_tax.py similarity index 70% rename from l10n_be_cash_discount/models/account_invoice.py rename to l10n_be_cash_discount/models/account_invoice_tax.py index c3745057f..8b0837cf0 100644 --- a/l10n_be_cash_discount/models/account_invoice.py +++ b/l10n_be_cash_discount/models/account_invoice_tax.py @@ -21,8 +21,6 @@ ############################################################################## from openerp import api, models, fields -from datetime import datetime, timedelta -from openerp.tools import DEFAULT_SERVER_DATE_FORMAT BelgiumBaseTaxCodesIn = ['81', '82', '83', '84', '85', '86', '87', '88'] BelgiumBaseTaxCodesOut = ['00', '01', '02', '03', '44', '45', '46', '46L', @@ -30,35 +28,10 @@ BelgiumBaseTaxCodes = BelgiumBaseTaxCodesIn + BelgiumBaseTaxCodesOut -class account_invoice(models.Model): - _inherit = 'account.invoice' - - discount_percent = fields.Float(string='Discount Percent') - discount_delay = fields.Integer(string='Discount Delay (days)') - - @api.one - @api.onchange('discount_percent') - def discount_percent_change(self): - discount = self.amount_untaxed * (0.0 + self.discount_percent/100) - self.discount_amount = discount - return - - @api.one - @api.onchange('discount_delay', 'date_invoice') - def discount_delay_change(self): - if self.date_invoice: - date_invoice = self.date_invoice - date_invoice = datetime.strptime(date_invoice, - DEFAULT_SERVER_DATE_FORMAT) - else: - date_invoice = datetime.now() - due_date = date_invoice + timedelta(days=self.discount_delay) - self.discount_due_date = due_date.date() - - class account_invoice_tax(models.Model): _inherit = 'account.invoice.tax' + @api.v8 def compute(self, invoice): tax_grouped = super(account_invoice_tax, self).compute(invoice) currency = invoice.currency_id\ diff --git a/l10n_be_cash_discount/reports/report_invoice.xml b/l10n_be_cash_discount/reports/report_invoice.xml deleted file mode 100644 index 7391a230f..000000000 --- a/l10n_be_cash_discount/reports/report_invoice.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - diff --git a/l10n_be_cash_discount/views/account_invoice_view.xml b/l10n_be_cash_discount/views/account_invoice_view.xml index 4e1399d7f..1592c29d8 100644 --- a/l10n_be_cash_discount/views/account_invoice_view.xml +++ b/l10n_be_cash_discount/views/account_invoice_view.xml @@ -6,10 +6,6 @@ account.invoice - - - - 0 @@ -20,10 +16,6 @@ account.invoice - - - - 0 From 8f9cce3ff72379886c99ae86cf60953782259b2d Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Mon, 29 Dec 2014 11:24:45 +0100 Subject: [PATCH 07/10] [IMP] Improve possibility of inheritance --- l10n_be_cash_discount/models/account_invoice_tax.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/l10n_be_cash_discount/models/account_invoice_tax.py b/l10n_be_cash_discount/models/account_invoice_tax.py index 8b0837cf0..340d70e10 100644 --- a/l10n_be_cash_discount/models/account_invoice_tax.py +++ b/l10n_be_cash_discount/models/account_invoice_tax.py @@ -31,9 +31,10 @@ class account_invoice_tax(models.Model): _inherit = 'account.invoice.tax' - @api.v8 - def compute(self, invoice): - tax_grouped = super(account_invoice_tax, self).compute(invoice) + def _compute_discount_tax_value(self, invoice, tax_grouped): + """ This method compute taxes values consider discount percent. + This method is designed to be inherited""" + currency = invoice.currency_id\ .with_context(date=invoice.date_invoice or fields.Date.context_today(invoice)) @@ -52,3 +53,9 @@ def compute(self, invoice): t['tax_amount'] = currency.round(t['tax_amount'] * multiplier) return tax_grouped + + @api.v8 + def compute(self, invoice): + tax_grouped = super(account_invoice_tax, self).compute(invoice) + tax_grouped = self._compute_discount_tax_value(invoice, tax_grouped) + return tax_grouped From 49d6307d8ca9374476690b60b17d40b3a4334a75 Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Thu, 15 Jan 2015 09:00:04 +0100 Subject: [PATCH 08/10] [IMP] Refactoring --- l10n_be_cash_discount/__openerp__.py | 4 +-- .../models/account_invoice_tax.py | 2 ++ l10n_be_cash_discount/tests/__init__.py | 2 +- ...mpute.py => test_l10n_be_cash_discount.py} | 0 .../views/account_invoice_view.xml | 25 ------------------- 5 files changed, 4 insertions(+), 29 deletions(-) rename l10n_be_cash_discount/tests/{test_account_cash_discount_compute.py => test_l10n_be_cash_discount.py} (100%) delete mode 100644 l10n_be_cash_discount/views/account_invoice_view.xml diff --git a/l10n_be_cash_discount/__openerp__.py b/l10n_be_cash_discount/__openerp__.py index 82259b11a..67c998936 100644 --- a/l10n_be_cash_discount/__openerp__.py +++ b/l10n_be_cash_discount/__openerp__.py @@ -31,9 +31,7 @@ "depends": [ "account_cash_discount_base", ], - "data": [ - 'views/account_invoice_view.xml', - ], + "data": [], "demo": [], "test": [], "licence": "AGPL-3", diff --git a/l10n_be_cash_discount/models/account_invoice_tax.py b/l10n_be_cash_discount/models/account_invoice_tax.py index 340d70e10..7229490ae 100644 --- a/l10n_be_cash_discount/models/account_invoice_tax.py +++ b/l10n_be_cash_discount/models/account_invoice_tax.py @@ -39,6 +39,8 @@ def _compute_discount_tax_value(self, invoice, tax_grouped): .with_context(date=invoice.date_invoice or fields.Date.context_today(invoice)) pct = invoice.discount_percent + if not pct and invoice.discount_amount: + pct = (1 - (invoice.discount_amount / invoice.amount_total)) * 100 if pct: multiplier = 1-pct/100 atc_obj = self.env['account.tax.code'] diff --git a/l10n_be_cash_discount/tests/__init__.py b/l10n_be_cash_discount/tests/__init__.py index 9254abb80..227aa3300 100644 --- a/l10n_be_cash_discount/tests/__init__.py +++ b/l10n_be_cash_discount/tests/__init__.py @@ -21,4 +21,4 @@ ############################################################################## # -from . import test_account_cash_discount_compute +from . import test_l10n_be_cash_discount diff --git a/l10n_be_cash_discount/tests/test_account_cash_discount_compute.py b/l10n_be_cash_discount/tests/test_l10n_be_cash_discount.py similarity index 100% rename from l10n_be_cash_discount/tests/test_account_cash_discount_compute.py rename to l10n_be_cash_discount/tests/test_l10n_be_cash_discount.py diff --git a/l10n_be_cash_discount/views/account_invoice_view.xml b/l10n_be_cash_discount/views/account_invoice_view.xml deleted file mode 100644 index 1592c29d8..000000000 --- a/l10n_be_cash_discount/views/account_invoice_view.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - account.invoice.supplier.form (account_cash_discount_compute) - account.invoice - - - - 0 - - - - - account.invoice.form (account_cash_discount_compute) - account.invoice - - - - 0 - - - - - \ No newline at end of file From 10573481d4a7c7911a9971e13ebb6e336c0af285 Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Tue, 21 Apr 2015 14:21:29 +0200 Subject: [PATCH 09/10] [FIX] Consider cash discount on tax amount --- l10n_be_cash_discount/models/__init__.py | 1 + .../models/account_invoice_line.py | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 l10n_be_cash_discount/models/account_invoice_line.py diff --git a/l10n_be_cash_discount/models/__init__.py b/l10n_be_cash_discount/models/__init__.py index 97cb4fdd6..38c495943 100644 --- a/l10n_be_cash_discount/models/__init__.py +++ b/l10n_be_cash_discount/models/__init__.py @@ -21,3 +21,4 @@ ############################################################################## from . import account_invoice_tax +from . import account_invoice_line diff --git a/l10n_be_cash_discount/models/account_invoice_line.py b/l10n_be_cash_discount/models/account_invoice_line.py new file mode 100644 index 000000000..a1ac1296d --- /dev/null +++ b/l10n_be_cash_discount/models/account_invoice_line.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# +############################################################################## +# +# Authors: Adrien Peiffer +# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp import models, api, fields +from openerp.addons.l10n_be_cash_discount.models.account_invoice_tax \ + import BelgiumBaseTaxCodes + + +class account_invoice_line(models.Model): + _inherit = 'account.invoice.line' + + @api.model + def _move_line_get_discount(self, invoice_id, aml): + invoice = self.env['account.invoice'].browse(invoice_id) + pct = invoice.discount_percent + if not pct and invoice.discount_amount: + pct = (1 - (invoice.discount_amount / invoice.amount_total)) * 100 + if pct: + currency = invoice.currency_id\ + .with_context(date=invoice.date_invoice or + fields.Date.context_today(invoice)) + multiplier = 1-pct/100 + atc_obj = self.env['account.tax.code'] + belgium_btc = atc_obj.search([('code', 'in', BelgiumBaseTaxCodes)]) + for tax in aml: + if tax['tax_code_id'] in belgium_btc.ids: + tax['tax_amount'] = \ + currency.round(tax['tax_amount'] * multiplier) + + @api.model + def move_line_get(self, invoice_id): + aml = super(account_invoice_line, self).move_line_get(invoice_id) + self._move_line_get_discount(invoice_id, aml) + return aml From cff26b487d9d46ab70215e4eaa45bbc467e7b484 Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Wed, 22 Nov 2017 18:18:27 +0100 Subject: [PATCH 10/10] [CHG] Version number and setup file. --- l10n_be_cash_discount/__openerp__.py | 2 +- setup/l10n_be_cash_discount/odoo_addons/__init__.py | 1 + .../l10n_be_cash_discount/odoo_addons/l10n_be_cash_discount | 1 + setup/l10n_be_cash_discount/setup.py | 6 ++++++ 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 setup/l10n_be_cash_discount/odoo_addons/__init__.py create mode 120000 setup/l10n_be_cash_discount/odoo_addons/l10n_be_cash_discount create mode 100644 setup/l10n_be_cash_discount/setup.py diff --git a/l10n_be_cash_discount/__openerp__.py b/l10n_be_cash_discount/__openerp__.py index 67c998936..834ef6e07 100644 --- a/l10n_be_cash_discount/__openerp__.py +++ b/l10n_be_cash_discount/__openerp__.py @@ -22,7 +22,7 @@ { "name": "Belgium cash discount computation", - "version": "1.0", + "version": "8.0.1.0.0", "author": "ACSONE SA/NV", "maintainer": "ACSONE SA/NV", "website": "http://www.acsone.eu", diff --git a/setup/l10n_be_cash_discount/odoo_addons/__init__.py b/setup/l10n_be_cash_discount/odoo_addons/__init__.py new file mode 100644 index 000000000..de40ea7ca --- /dev/null +++ b/setup/l10n_be_cash_discount/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/l10n_be_cash_discount/odoo_addons/l10n_be_cash_discount b/setup/l10n_be_cash_discount/odoo_addons/l10n_be_cash_discount new file mode 120000 index 000000000..6dfae9bba --- /dev/null +++ b/setup/l10n_be_cash_discount/odoo_addons/l10n_be_cash_discount @@ -0,0 +1 @@ +../../../l10n_be_cash_discount \ No newline at end of file diff --git a/setup/l10n_be_cash_discount/setup.py b/setup/l10n_be_cash_discount/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/l10n_be_cash_discount/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)