diff --git a/account_invoice_rounding_by_currency/README.rst b/account_invoice_rounding_by_currency/README.rst new file mode 100644 index 000000000000..e648c443be5d --- /dev/null +++ b/account_invoice_rounding_by_currency/README.rst @@ -0,0 +1,63 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Unit rounded invoice (Swedish rounding) by currency +======================================================= + +This module extende functionallity of module `Unit rounded invoice `_. + +Add a parameter to give a unit for rounding such as CHF 0.05 for Swiss +invoices + +In Settings -> Company -> Configurations you will find +Currencies Rounding Rules +Set currency rule for aech type of currency you need hadled. + +- `Swedish Round globally` + + To round your invoice total amount, this option will do the adjustment in + the most important tax line of your invoice. + +- `Swedish Round by adding an invoice line` + + To round your invoice total amount, this option create a invoice line without + taxes on it. This invoice line is tagged as `is_rounding` + + + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/95/8.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 +`here `_. + + +Credits +======= + +Contributors +------------ +Alessio Gerace + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://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 http://odoo-community.org. diff --git a/account_invoice_rounding_by_currency/__init__.py b/account_invoice_rounding_by_currency/__init__.py new file mode 100644 index 000000000000..06173e1fc189 --- /dev/null +++ b/account_invoice_rounding_by_currency/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 Agile Business Group sagl () +# Author: Alessio Gerace +# +# 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 company +from . import account +from . import tests diff --git a/account_invoice_rounding_by_currency/__openerp__.py b/account_invoice_rounding_by_currency/__openerp__.py new file mode 100644 index 000000000000..03dc2a6d5d06 --- /dev/null +++ b/account_invoice_rounding_by_currency/__openerp__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 Agile Business Group sagl () +# Author: Alessio Gerace +# +# 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': 'Unit rounded invoice by Currency', + 'version': '8.0.1.0.0', + 'category': 'Accounting', + 'author': "Agile Business Group,,Odoo Community Association (OCA)", + 'maintainer': 'Camptocamp', + 'website': 'http://www.agilebg.com/', + 'license': 'AGPL-3', + 'depends': ['account_invoice_rounding'], + 'data': [ + 'res_company.xml', + 'security/ir.model.access.csv', + ], + "demo": ['demo/data.xml'], + 'installable': True, + 'auto_install': False, + 'application': False +} diff --git a/account_invoice_rounding_by_currency/account.py b/account_invoice_rounding_by_currency/account.py new file mode 100644 index 000000000000..e8ba3542e08a --- /dev/null +++ b/account_invoice_rounding_by_currency/account.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 Agile Business Group sagl () +# Author: Alessio Gerace +# +# 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 + + +class AccountInvoice(models.Model): + _inherit = "account.invoice" + + def _compute_swedish_rounding(self, cr, uid, invoice, context=None): + """ + Depending on the method defined, we add an invoice line or adapt the + tax lines to have a rounded total amount on the invoice + :param invoice: invoice browse record + :return dict: updated values for _amount_all + """ + # avoid recusivity + + if 'swedish_write' in context: + return {} + rounding_rule_model = self.pool.get('company.rounding') + company = invoice.company_id + if invoice.currency_id.id != company.currency_id.id: + ret_ids = rounding_rule_model.search( + cr, uid, + [ + ('company_id', '=', company.id), + ('currency_id', '=', invoice.currency_id.id), + ], + context=context) + if ret_ids: + rule = rounding_rule_model.browse( + cr, uid, ret_ids[0], context=context) + company.tax_calculation_rounding_method = ( + rule.tax_calculation_rounding_method) + company.tax_calculation_rounding = ( + rule.tax_calculation_rounding) + company.tax_calculation_rounding_account_id = ( + rule.tax_calculation_rounding_account_id) + else: + return {} + + return super(AccountInvoice, self)._compute_swedish_rounding( + cr, uid, invoice, context=context) diff --git a/account_invoice_rounding_by_currency/company.py b/account_invoice_rounding_by_currency/company.py new file mode 100644 index 000000000000..8c423f3df23f --- /dev/null +++ b/account_invoice_rounding_by_currency/company.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 Agile Business Group sagl () +# Author: Alessio Gerace +# +# 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, fields + + +class RoundingByCurrency(models.Model): + _name = 'company.rounding' + + company_id = fields.Many2one('res.company', 'Company', required=True) + currency_id = fields.Many2one('res.currency', 'Currency', required=True) + tax_calculation_rounding = fields.Float('Tax Rounding unit') + tax_calculation_rounding_account_id = fields.Many2one( + 'account.account', + 'Tax Rounding Account', + domain=[('type', '<>', 'view')] + ) + tax_calculation_rounding_method = fields.Selection( + [ + ('swedish_round_globally', 'Swedish Round globally'), + ('swedish_add_invoice_line', 'Swedish Round by adding a line'), + ], + string='Tax Calculation Rounding Method', + help="If you select 'Round per line' : for each tax, the tax " + "amount will first be computed and rounded for each " + "PO/SO/invoice line and then these rounded amounts will be " + "summed, leading to the total amount for that tax. If you " + "select 'Round globally': for each tax, the tax amount will " + "be computed for each PO/SO/invoice line, then these amounts" + " will be summed and eventually this total tax amount will " + "be rounded. If you sell with tax included, you should " + "choose 'Round per line' because you certainly want the sum " + "of your tax-included line subtotals to be equal to the " + "total amount with taxes." + ) + + _sql_constraints = [ + ('currency_id_uniq_per+company', 'unique (currency_id, company_id)', + 'Currency must be unique per Company!'), + ] + + +class ResCompany(models.Model): + _inherit = 'res.company' + + currency_rounding_rules = fields.One2many( + 'company.rounding', 'company_id', + 'Rounding Rule' + ) diff --git a/account_invoice_rounding_by_currency/demo/data.xml b/account_invoice_rounding_by_currency/demo/data.xml new file mode 100644 index 000000000000..95d11525e4bb --- /dev/null +++ b/account_invoice_rounding_by_currency/demo/data.xml @@ -0,0 +1,114 @@ + + + + + + + + IVA a credito 10% + + + + IVA a credito 10% (imponibile) + + + + 10% test + 10 + 0.10 + + + + + + + + + + + + + + + + + + + + + + + + out_invoice + + + + + + + + + + + + + + [PCSC234] PC Assemble SC234-2 + + + + + + + + + + + out_invoice + + + + + + + + + + + + + + [PCSC234] PC Assemble SC234-2 + + + + + + + + + + out_invoice + + + + + + + + + + + + + + [PCSC234] PC Assemble SC234-2 + + + + diff --git a/account_invoice_rounding_by_currency/i18n/it.po b/account_invoice_rounding_by_currency/i18n/it.po new file mode 100644 index 000000000000..b380f454b09c --- /dev/null +++ b/account_invoice_rounding_by_currency/i18n/it.po @@ -0,0 +1,107 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_rounding_by_currency +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-10-12 16:28+0000\n" +"PO-Revision-Date: 2015-10-12 16:28+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_invoice_rounding_by_currency +#: model:ir.model,name:account_invoice_rounding_by_currency.model_res_company +msgid "Companies" +msgstr "Aziende" + +#. module: account_invoice_rounding_by_currency +#: field:company.rounding,company_id:0 +msgid "Company" +msgstr "Company" + +#. module: account_invoice_rounding_by_currency +#: field:company.rounding,create_uid:0 +msgid "Created by" +msgstr "Created by" + +#. module: account_invoice_rounding_by_currency +#: field:company.rounding,create_date:0 +msgid "Created on" +msgstr "Created on" + +#. module: account_invoice_rounding_by_currency +#: view:res.company:account_invoice_rounding_by_currency.view_res_company_currencies_settings +msgid "Currencies Rounding Rules" +msgstr "Regole di Arrotondamento per Valuta" + +#. module: account_invoice_rounding_by_currency +#: field:company.rounding,currency_id:0 +msgid "Currency" +msgstr "Valuta" + +#. module: account_invoice_rounding_by_currency +#: sql_constraint:company.rounding:0 +msgid "Currency must be unique per Company!" +msgstr "LA valuta deve essere univoca per azienda!" + +#. module: account_invoice_rounding_by_currency +#: field:company.rounding,id:0 +msgid "ID" +msgstr "ID" + +#. module: account_invoice_rounding_by_currency +#: help:company.rounding,tax_calculation_rounding_method:0 +msgid "If you select 'Round per line' : for each tax, the tax amount will first be computed and rounded for each PO/SO/invoice line and then these rounded amounts will be summed, leading to the total amount for that tax. If you select 'Round globally': for each tax, the tax amount will be computed for each PO/SO/invoice line, then these amounts will be summed and eventually this total tax amount will be rounded. If you sell with tax included, you should choose 'Round per line' because you certainly want the sum of your tax-included line subtotals to be equal to the total amount with taxes." +msgstr "Se si seleziona 'Arrotondamento per riga ' : per ciascuna imposta , l'importo dell'imposta viene calcolato e arrotondato per ogni riga di fattura e quindi tali importi arrotondati verranno riassunti , nella somma totale per tale imposta . Se si seleziona 'Arrotondamento a livello globale ' : per ciascuna imposta , l'importo dell'imposta sarà calcolato, quindi questi importi saranno sommati e alla fine l'importo totale dell'imposta sarà arrotondato . Se si vende con tasse incluse , si dovrebbe scegliere 'Arrotondamento per linea ' perché si vuole certamente la somma dei subtotali per riga fiscale incluso per essere pari all'importo totale con le tasse" + +#. module: account_invoice_rounding_by_currency +#: model:ir.model,name:account_invoice_rounding_by_currency.model_account_invoice +msgid "Invoice" +msgstr "Fattura" + +#. module: account_invoice_rounding_by_currency +#: field:company.rounding,write_uid:0 +msgid "Last Updated by" +msgstr "Last Updated by" + +#. module: account_invoice_rounding_by_currency +#: field:company.rounding,write_date:0 +msgid "Last Updated on" +msgstr "Last Updated on" + +#. module: account_invoice_rounding_by_currency +#: field:res.company,currency_rounding_rules:0 +msgid "Rounding Rule" +msgstr "Regola di Arrotondamento" + +#. module: account_invoice_rounding_by_currency +#: selection:company.rounding,tax_calculation_rounding_method:0 +msgid "Swedish Round by adding a line" +msgstr "Swedish Round , per riga" + +#. module: account_invoice_rounding_by_currency +#: selection:company.rounding,tax_calculation_rounding_method:0 +msgid "Swedish Round globally" +msgstr "Swedish Round Globale" + +#. module: account_invoice_rounding_by_currency +#: field:company.rounding,tax_calculation_rounding_method:0 +msgid "Tax Calculation Rounding Method" +msgstr "Metodo di arrotondamento calcolo Imposte" + +#. module: account_invoice_rounding_by_currency +#: field:company.rounding,tax_calculation_rounding_account_id:0 +msgid "Tax Rounding Account" +msgstr "Conto per arrotondamento imposte" + +#. module: account_invoice_rounding_by_currency +#: field:company.rounding,tax_calculation_rounding:0 +msgid "Tax Rounding unit" +msgstr "Percentuale di arrotondamento" + diff --git a/account_invoice_rounding_by_currency/res_company.xml b/account_invoice_rounding_by_currency/res_company.xml new file mode 100644 index 000000000000..7e370ba4e6be --- /dev/null +++ b/account_invoice_rounding_by_currency/res_company.xml @@ -0,0 +1,28 @@ + + + + + + res.company.add.rounding.correncies + res.company + 50 + + + + + + + + + + + + + + + + + + + diff --git a/account_invoice_rounding_by_currency/security/ir.model.access.csv b/account_invoice_rounding_by_currency/security/ir.model.access.csv new file mode 100644 index 000000000000..6d3848de0766 --- /dev/null +++ b/account_invoice_rounding_by_currency/security/ir.model.access.csv @@ -0,0 +1,2 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +"access_company_rounding","access_company_rounding","model_company_rounding","",1,0,0,0 diff --git a/account_invoice_rounding_by_currency/tests/__init__.py b/account_invoice_rounding_by_currency/tests/__init__.py new file mode 100644 index 000000000000..92f4c19d54af --- /dev/null +++ b/account_invoice_rounding_by_currency/tests/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 Agile Business Group sagl () +# Author: Alessio Gerace +# +# 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_rounding_by_currencies diff --git a/account_invoice_rounding_by_currency/tests/test_rounding_by_currencies.py b/account_invoice_rounding_by_currency/tests/test_rounding_by_currencies.py new file mode 100644 index 000000000000..332178e01516 --- /dev/null +++ b/account_invoice_rounding_by_currency/tests/test_rounding_by_currencies.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 Agile Business Group sagl () +# Author: Alessio Gerace +# +# 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 workflow +import openerp.tests.common as test_common + + +class TestRoundingByCurrencies(test_common.SingleTransactionCase): + + def setUp(self): + super(TestRoundingByCurrencies, self).setUp() + self.data_model = self.registry('ir.model.data') + self.invoice_model = self.registry('account.invoice') + self.context = {} + self.maxDiff = None + self.company = self.env.ref('base.main_company') + + def test_0_xml_export(self): + cr, uid = self.cr, self.uid + invoice_id = self.data_model.get_object_reference( + cr, uid, 'account_invoice_rounding_by_currency', + 'invtest_invoice_0' + ) + if invoice_id: + invoice_id = invoice_id and invoice_id[1] or False + invoice = self.invoice_model.browse(cr, uid, invoice_id) + self.assertEqual(invoice.state, 'draft') + workflow.trg_validate( + uid, 'account.invoice', invoice_id, 'invoice_open', cr + ) + self.assertEqual(invoice.state, 'open') + self.assertEqual(invoice.amount_total, 110.0) + + def test_1_xml_export(self): + cr, uid = self.cr, self.uid + invoice_id = self.data_model.get_object_reference( + cr, uid, 'account_invoice_rounding_by_currency', + 'invtest_invoice_1' + ) + if invoice_id: + invoice_id = invoice_id and invoice_id[1] or False + invoice = self.invoice_model.browse(cr, uid, invoice_id) + self.assertEqual(invoice.state, 'draft') + workflow.trg_validate( + uid, 'account.invoice', invoice_id, 'invoice_open', cr + ) + self.assertEqual(invoice.state, 'open') + self.assertEqual(invoice.amount_total, 110.45) + + def test_2_xml_export(self): + cr, uid = self.cr, self.uid + invoice_id = self.data_model.get_object_reference( + cr, uid, 'account_invoice_rounding_by_currency', + 'invtest_invoice_2' + ) + if invoice_id: + invoice_id = invoice_id and invoice_id[1] or False + invoice = self.invoice_model.browse(cr, uid, invoice_id) + self.assertEqual(invoice.state, 'draft') + workflow.trg_validate( + uid, 'account.invoice', invoice_id, 'invoice_open', cr + ) + self.assertEqual(invoice.state, 'open') + self.assertEqual(invoice.amount_total, 110.50)