diff options
| author | Laurent Smet <las@openerp.com> | 2017-09-01 18:23:45 +0200 |
|---|---|---|
| committer | qdp-odoo <qdp@odoo.com> | 2017-09-01 18:23:45 +0200 |
| commit | aee43c0d145aa55ae87029ab1457fd8b74b97b94 (patch) | |
| tree | 981278b520519346916e1144089c4281675092bc /addons | |
| parent | c030213fa3b822b1ea373c77b552bfda716a3900 (diff) | |
[ADD] account: add cash rounding managment
In some countries, we need to be able to make appear on an invoice a rounding line, appearing there only because the smallest
coinage has been removed from the circulation.
For example, in Switerzland invoices have to be rounded to 0.05 CHF because coins of 0.01 CHF and 0.02 CHF aren't used anymore.
Was PR #15231
Was task 30904
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/account/__manifest__.py | 2 | ||||
| -rw-r--r-- | addons/account/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/account/models/account_cash_rounding.py | 47 | ||||
| -rw-r--r-- | addons/account/models/account_invoice.py | 75 | ||||
| -rw-r--r-- | addons/account/models/res_config_settings.py | 1 | ||||
| -rw-r--r-- | addons/account/security/account_security.xml | 5 | ||||
| -rw-r--r-- | addons/account/security/ir.model.access.csv | 1 | ||||
| -rw-r--r-- | addons/account/tests/__init__.py | 1 | ||||
| -rw-r--r-- | addons/account/tests/test_account_invoice_rounding.py | 107 | ||||
| -rw-r--r-- | addons/account/views/account_cash_rounding_view.xml | 64 | ||||
| -rw-r--r-- | addons/account/views/account_invoice_view.xml | 16 | ||||
| -rw-r--r-- | addons/account/views/res_config_settings_views.xml | 16 | ||||
| -rw-r--r-- | addons/l10n_ch/__init__.py | 23 | ||||
| -rw-r--r-- | addons/l10n_ch/__manifest__.py | 3 | ||||
| -rw-r--r-- | addons/l10n_ch/demo/account_cash_rounding.xml | 10 |
15 files changed, 356 insertions, 16 deletions
diff --git a/addons/account/__manifest__.py b/addons/account/__manifest__.py index 3d2228d3605..55fb0570c91 100644 --- a/addons/account/__manifest__.py +++ b/addons/account/__manifest__.py @@ -39,7 +39,7 @@ Core mechanisms for the accounting modules. To display the menuitems, install th 'views/report_invoice.xml', 'report/account_invoice_report_view.xml', 'views/report_overdue.xml', - 'views/report_overdue.xml', + 'views/account_cash_rounding_view.xml', 'wizard/account_report_common_view.xml', 'wizard/account_report_print_journal_view.xml', 'views/report_journal.xml', diff --git a/addons/account/models/__init__.py b/addons/account/models/__init__.py index 2e9cc211e15..399daaa3e8e 100644 --- a/addons/account/models/__init__.py +++ b/addons/account/models/__init__.py @@ -13,3 +13,4 @@ from . import product from . import company from . import res_config_settings from . import web_planner +from . import account_cash_rounding diff --git a/addons/account/models/account_cash_rounding.py b/addons/account/models/account_cash_rounding.py new file mode 100644 index 00000000000..4596315138f --- /dev/null +++ b/addons/account/models/account_cash_rounding.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- + +from odoo import models, fields, api, _ +from odoo.tools import float_round + + +class AccountCashRounding(models.Model): + """ + In some countries, we need to be able to make appear on an invoice a rounding line, appearing there only because the + smallest coinage has been removed from the circulation. For example, in Switerzland invoices have to be rounded to + 0.05 CHF because coins of 0.01 CHF and 0.02 CHF aren't used anymore. + see https://en.wikipedia.org/wiki/Cash_rounding for more details. + """ + _name = 'account.cash.rounding' + _description = 'Account Rounding' + + name = fields.Char(string='Name', translate=True, required=True) + rounding = fields.Float(string='Rounding Precision', required=True, + help='Represent the non-zero value smallest coinage (for example, 0.05).') + strategy = fields.Selection([('biggest_tax', 'Modify tax amount'), ('add_invoice_line', 'Add a rounding line')], + string='Rounding Strategy', default='add_invoice_line', required=True, + help='Specify which way will be used to round the invoice amount to the rounding precision') + account_id = fields.Many2one('account.account', string='Account') + rounding_method = fields.Selection(string='Rounding Method', required=True, + selection=[('UP', 'UP'), ('DOWN', 'DOWN'), ('HALF-UP', 'HALF-UP')], + default='HALF-UP', help='These values must correspond to the rounding_method of the float_round tools method.') + + @api.multi + def round(self, amount): + """Compute the rounding on the amount passed as parameter. + + :param amount: the amount to round + :return: the rounded amount depending the rounding value and the rounding method + """ + return float_round(amount, precision_rounding=self.rounding, rounding_method=self.rounding_method) + + @api.multi + def compute_difference(self, currency, amount): + """Compute the difference between the base_amount and the amount after rounding. + For example, base_amount=23.91, after rounding=24.00, the result will be 0.09. + + :param currency: The currency. + :param amount: The amount + :return: round(difference) + """ + difference = self.round(amount) - amount + return currency.round(difference) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index abe8329a049..77a0dc50c3a 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -5,7 +5,6 @@ import re import uuid from lxml import etree -from datetime import datetime from dateutil.relativedelta import relativedelta from werkzeug.urls import url_encode @@ -48,10 +47,11 @@ class AccountInvoice(models.Model): return str(uuid.uuid4()) @api.one - @api.depends('invoice_line_ids.price_subtotal', 'tax_line_ids.amount', 'currency_id', 'company_id', 'date_invoice', 'type') + @api.depends('invoice_line_ids.price_subtotal', 'tax_line_ids.amount', 'tax_line_ids.amount_rounding', + 'currency_id', 'company_id', 'date_invoice', 'type') def _compute_amount(self): self.amount_untaxed = sum(line.price_subtotal for line in self.invoice_line_ids) - self.amount_tax = sum(line.amount for line in self.tax_line_ids) + self.amount_tax = sum(line.amount_total for line in self.tax_line_ids) self.amount_total = self.amount_untaxed + self.amount_tax amount_total_company_signed = self.amount_total amount_untaxed_signed = self.amount_untaxed @@ -353,6 +353,9 @@ class AccountInvoice(models.Model): outstanding_credits_debits_widget = fields.Text(compute='_get_outstanding_info_JSON', groups="account.group_account_invoice") payments_widget = fields.Text(compute='_get_payment_info_JSON', groups="account.group_account_invoice") has_outstanding = fields.Boolean(compute='_get_outstanding_info_JSON', groups="account.group_account_invoice") + cash_rounding_id = fields.Many2one('account.cash.rounding', string='Cash Rounding Method', + readonly=True, states={'draft': [('readonly', False)]}, + help='Defines the smallest coinage of the currency that can be used to pay by cash.') #fields use to set the sequence, on the first invoice of the journal sequence_number_next = fields.Char(string='Next Number', compute="_get_sequence_number_next", inverse="_set_sequence_next") @@ -682,6 +685,48 @@ class AccountInvoice(models.Model): elif self.date_due and (date_invoice > self.date_due): self.date_due = date_invoice + @api.onchange('cash_rounding_id', 'invoice_line_ids', 'tax_line_ids') + def _onchange_cash_rounding(self): + # Drop previous cash rounding lines + lines_to_remove = self.invoice_line_ids.filtered(lambda l: l.is_rounding_line) + if lines_to_remove: + self.invoice_line_ids -= lines_to_remove + + # Clear previous rounded amounts + for tax_line in self.tax_line_ids: + if tax_line.amount_rounding != 0.0: + tax_line.amount_rounding = 0.0 + + if self.cash_rounding_id: + rounding_amount = self.cash_rounding_id.compute_difference(self.currency_id, self.amount_total) + if not self.currency_id.is_zero(rounding_amount): + if self.cash_rounding_id.strategy == 'biggest_tax': + # Search for the biggest tax line and add the rounding amount to it. + # If no tax found, an error will be raised by the _check_cash_rounding method. + if not self.tax_line_ids: + return + biggest_tax_line = None + for tax_line in self.tax_line_ids: + if not biggest_tax_line or tax_line.amount > biggest_tax_line.amount: + biggest_tax_line = tax_line + biggest_tax_line.amount_rounding += rounding_amount + elif self.cash_rounding_id.strategy == 'add_invoice_line': + # Create a new invoice line to perform the rounding + rounding_line = self.env['account.invoice.line'].new({ + 'name': self.cash_rounding_id.name, + 'invoice_id': self.id, + 'account_id': self.cash_rounding_id.account_id.id, + 'price_unit': rounding_amount, + 'quantity': 1, + 'is_rounding_line': True, + 'sequence': 9999 # always last line + }) + + # To be able to call this onchange manually from the tests, + # ensure the inverse field is updated on account.invoice. + if not rounding_line in self.invoice_line_ids: + self.invoice_line_ids += rounding_line + @api.multi def action_invoice_draft(self): if self.filtered(lambda inv: inv.state != 'cancel'): @@ -935,7 +980,7 @@ class AccountInvoice(models.Model): done_taxes = [] # loop the invoice.tax.line in reversal sequence for tax_line in sorted(self.tax_line_ids, key=lambda x: -x.sequence): - if tax_line.amount: + if tax_line.amount_total: tax = tax_line.tax_id if tax.amount_type == "group": for child_tax in tax.children_tax_ids: @@ -945,9 +990,9 @@ class AccountInvoice(models.Model): 'tax_line_id': tax_line.tax_id.id, 'type': 'tax', 'name': tax_line.name, - 'price_unit': tax_line.amount, + 'price_unit': tax_line.amount_total, 'quantity': 1, - 'price': tax_line.amount, + 'price': tax_line.amount_total, 'account_id': tax_line.account_id.id, 'account_analytic_id': tax_line.account_analytic_id.id, 'invoice_id': self.id, @@ -1089,6 +1134,16 @@ class AccountInvoice(models.Model): inv.with_context(ctx).write(vals) return True + @api.constrains('cash_rounding_id', 'tax_line_ids') + def _check_cash_rounding(self): + for inv in self: + if inv.cash_rounding_id: + rounding_amount = inv.cash_rounding_id.compute_difference(inv.currency_id, inv.amount_total) + if rounding_amount != 0.0: + raise UserError(_('The cash rounding cannot be computed because the difference must ' + 'be added on the biggest tax found and no tax are specified.\n' + 'Please set up a tax or change the cash rounding method.')) + @api.multi def _check_duplicate_supplier_reference(self): for invoice in self: @@ -1442,6 +1497,7 @@ class AccountInvoiceLine(models.Model): related='invoice_id.partner_id', store=True, readonly=True, related_sudo=False) currency_id = fields.Many2one('res.currency', related='invoice_id.currency_id', store=True, related_sudo=False) company_currency_id = fields.Many2one('res.currency', related='invoice_id.company_currency_id', readonly=True, related_sudo=False) + is_rounding_line = fields.Boolean(string='Rounding Line', help='Is a rounding line in case of cash rounding.') @api.model def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): @@ -1615,13 +1671,18 @@ class AccountInvoiceTax(models.Model): account_id = fields.Many2one('account.account', string='Tax Account', required=True, domain=[('deprecated', '=', False)]) account_analytic_id = fields.Many2one('account.analytic.account', string='Analytic account') amount = fields.Monetary() + amount_rounding = fields.Monetary() + amount_total = fields.Monetary(compute='_compute_amount_total') manual = fields.Boolean(default=True) sequence = fields.Integer(help="Gives the sequence order when displaying a list of invoice tax.") company_id = fields.Many2one('res.company', string='Company', related='account_id.company_id', store=True, readonly=True) currency_id = fields.Many2one('res.currency', related='invoice_id.currency_id', store=True, readonly=True) base = fields.Monetary(string='Base', compute='_compute_base_amount', store=True) - + @api.depends('amount', 'amount_rounding') + def _compute_amount_total(self): + for tax_line in self: + tax_line.amount_total = tax_line.amount + tax_line.amount_rounding class AccountPaymentTerm(models.Model): diff --git a/addons/account/models/res_config_settings.py b/addons/account/models/res_config_settings.py index b0b11f47d34..931ec193eeb 100644 --- a/addons/account/models/res_config_settings.py +++ b/addons/account/models/res_config_settings.py @@ -32,6 +32,7 @@ class ResConfigSettings(models.TransientModel): group_analytic_accounting = fields.Boolean(string='Analytic Accounting', implied_group='analytic.group_analytic_accounting') group_warning_account = fields.Boolean(string="Warnings", implied_group='account.group_warning_account') + group_cash_rounding = fields.Boolean(string="Cash Rounding", implied_group='account.group_cash_rounding') module_account_asset = fields.Boolean(string='Assets Management') module_account_deferred_revenue = fields.Boolean(string="Revenue Recognition") module_account_budget = fields.Boolean(string='Budget Management') diff --git a/addons/account/security/account_security.xml b/addons/account/security/account_security.xml index 6bb043e94fd..f073b831599 100644 --- a/addons/account/security/account_security.xml +++ b/addons/account/security/account_security.xml @@ -28,6 +28,11 @@ <field name="category_id" ref="base.module_category_hidden"/> </record> + <record id="group_cash_rounding" model="res.groups"> + <field name="name">Allow the cash rounding managment</field> + <field name="category_id" ref="base.module_category_hidden"/> + </record> + </data> <data noupdate="1"> diff --git a/addons/account/security/ir.model.access.csv b/addons/account/security/ir.model.access.csv index c1beed46daa..8a9aad92bd9 100644 --- a/addons/account/security/ir.model.access.csv +++ b/addons/account/security/ir.model.access.csv @@ -31,6 +31,7 @@ access_account_move_uinvoice,account.move,model_account_move,account.group_accou access_account_move_line_uinvoice,account.move.line invoice,model_account_move_line,account.group_account_invoice,1,1,1,1 access_account_payment_term_manager,account.payment.term,model_account_payment_term,account.group_account_manager,1,1,1,1 access_account_payment_term_line_manager,account.payment.term.line,model_account_payment_term_line,account.group_account_manager,1,1,1,1 +access_account_cash_rounding_uinvoice,account.cash.rounding,model_account_cash_rounding,account.group_account_invoice,1,1,1,1 access_account_tax_manager,account.tax,model_account_tax,account.group_account_manager,1,1,1,1 access_account_journal_manager,account.journal,model_account_journal,account.group_account_manager,1,1,1,1 access_account_journal_user,account.journal,model_account_journal,account.group_account_user,1,0,0,0 diff --git a/addons/account/tests/__init__.py b/addons/account/tests/__init__.py index 803e77e2355..8d6fb294413 100644 --- a/addons/account/tests/__init__.py +++ b/addons/account/tests/__init__.py @@ -5,6 +5,7 @@ from . import test_account_customer_invoice from . import test_account_move_closed_period from . import test_account_supplier_invoice from . import test_account_validate_account_move +from . import test_account_invoice_rounding from . import test_bank_statement_reconciliation #TODO re-enableand fix this test #from . import test_bank_stmt_reconciliation_widget_ui diff --git a/addons/account/tests/test_account_invoice_rounding.py b/addons/account/tests/test_account_invoice_rounding.py new file mode 100644 index 00000000000..9b0ef0fc9e8 --- /dev/null +++ b/addons/account/tests/test_account_invoice_rounding.py @@ -0,0 +1,107 @@ +# -*- coding: utf-8 -*- + +from odoo.addons.account.tests.account_test_classes import AccountingTestCase +from odoo.exceptions import ValidationError + +import time + + +class TestAccountInvoiceRounding(AccountingTestCase): + + def setUp(self): + super(TestAccountInvoiceRounding, self).setUp() + self.account_receivable = self.env['account.account'].search( + [('user_type_id', '=', self.env.ref('account.data_account_type_receivable').id)], limit=1) + self.account_revenue = self.env['account.account'].search( + [('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1) + self.fixed_tax = self.env['account.tax'].create({ + 'name': 'Test Tax', + 'amount': 0.0, + 'amount_type': 'fixed', + }) + + def create_cash_rounding(self, rounding, method, strategy): + return self.env['account.cash.rounding'].create({ + 'name': 'rounding ' + method, + 'rounding': rounding, + 'account_id': self.account_receivable.id, + 'strategy': strategy, + 'rounding_method': method, + }) + + def create_invoice(self, amount, cash_rounding_id, tax_amount=None): + """ Returns an open invoice """ + invoice_id = self.env['account.invoice'].create({ + 'partner_id': self.env.ref("base.res_partner_2").id, + 'reference_type': 'none', + 'currency_id': self.env.ref('base.USD').id, + 'name': 'invoice test rounding', + 'account_id': self.account_receivable.id, + 'type': 'out_invoice', + 'date_invoice': time.strftime('%Y') + '-06-26', + }) + if tax_amount: + self.fixed_tax.amount = tax_amount + self.env['account.invoice.line'].create({ + 'product_id': self.env.ref("product.product_product_4").id, + 'quantity': 1, + 'price_unit': amount, + 'invoice_id': invoice_id.id, + 'name': 'something', + 'account_id': self.account_revenue.id, + 'invoice_line_tax_ids': [(6, 0, [self.fixed_tax.id])] if tax_amount else None + }) + # Create the tax_line_ids + invoice_id._onchange_invoice_line_ids() + + # We need to set the cash_rounding_id after the _onchange_invoice_line_ids + # to avoid a ValidationError from _check_cash_rounding because the onchange + # are not well triggered in the tests. + try: + invoice_id.cash_rounding_id = cash_rounding_id + except ValidationError: + pass + + invoice_id._onchange_cash_rounding() + invoice_id.action_invoice_open() + return invoice_id + + def _check_invoice_rounding(self, inv, exp_lines_values, exp_tax_values=None): + inv_lines = inv.invoice_line_ids + self.assertEquals(len(inv_lines), len(exp_lines_values)) + for i in range(0, len(exp_lines_values)): + self.assertEquals(inv_lines[i].price_unit, exp_lines_values[i]) + + if exp_tax_values: + tax_lines = inv.tax_line_ids + self.assertEquals(len(tax_lines), len(exp_tax_values)) + for i in range(0, len(exp_tax_values)): + self.assertEquals(tax_lines[i].amount_total, exp_tax_values[i]) + + def test_rounding_add_invoice_line(self): + self._check_invoice_rounding( + self.create_invoice(100.2, self.create_cash_rounding(0.5, 'UP', 'add_invoice_line')), + [100.2, 0.3] + ) + self._check_invoice_rounding( + self.create_invoice(100.9, self.create_cash_rounding(1.0, 'DOWN', 'add_invoice_line')), + [100.9, -0.9] + ) + self._check_invoice_rounding( + self.create_invoice(100.5, self.create_cash_rounding(1.0, 'HALF-UP', 'add_invoice_line')), + [100.5, 0.5] + ) + + def test_rounding_biggest_tax(self): + self._check_invoice_rounding( + self.create_invoice(100.2, self.create_cash_rounding(0.5, 'UP', 'biggest_tax'), 1.0), + [100.2], [1.3] + ) + self._check_invoice_rounding( + self.create_invoice(100.9, self.create_cash_rounding(1.0, 'DOWN', 'biggest_tax'), 2.0), + [100.9], [1.1] + ) + self._check_invoice_rounding( + self.create_invoice(100.5, self.create_cash_rounding(1.0, 'HALF-UP', 'biggest_tax'), 1.0), + [100.5], [1.5] + ) diff --git a/addons/account/views/account_cash_rounding_view.xml b/addons/account/views/account_cash_rounding_view.xml new file mode 100644 index 00000000000..5edcc1bbd3f --- /dev/null +++ b/addons/account/views/account_cash_rounding_view.xml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <data> + <!-- Action --> + <record id="rounding_list_action" model="ir.actions.act_window"> + <field name="name">Cash Roundings</field> + <field name="res_model">account.cash.rounding</field> + <field name="view_type">form</field> + <field name="view_mode">tree,form</field> + <field name="help" type="html"> + <p class="oe_view_nocontent_create">Create the first cash rounding</p> + </field> + </record> + + <!-- Views --> + <record id="rounding_form_view" model="ir.ui.view"> + <field name="name">account.cash.rounding.form</field> + <field name="model">account.cash.rounding</field> + <field name="arch" type="xml"> + <form string="Rounding Form"> + <sheet> + <div class="oe_title"> + <label for="name" class="oe_edit_only"/> + <h1><field name="name" class="oe_inline"/></h1> + </div> + <group> + <field name="rounding"/> + <field name="strategy"/> + <field name="account_id" attrs="{'invisible': [('strategy', '!=', 'add_invoice_line')], 'required': [('strategy', '=', 'add_invoice_line')]}" + groups="account.group_account_user"/> + <field name="rounding_method"/> + </group> + </sheet> + </form> + </field> + </record> + + <record id="rounding_search_view" model="ir.ui.view"> + <field name="name">account.cash.rounding.search</field> + <field name="model">account.cash.rounding</field> + <field name="arch" type="xml"> + <search> + <field name="name"/> + </search> + </field> + </record> + + <record id="rounding_tree_view" model="ir.ui.view"> + <field name="name">account.cash.rounding.tree</field> + <field name="model">account.cash.rounding</field> + <field name="arch" type="xml"> + <tree string="Rounding Tree"> + <field name="name"/> + <field name="rounding"/> + <field name="rounding_method"/> + </tree> + </field> + </record> + + <!-- Menu --> + <menuitem id="menu_action_rounding_form_view" action="rounding_list_action" + groups="account.group_cash_rounding" parent="account_account_menu" sequence="4"/> + </data> +</odoo> diff --git a/addons/account/views/account_invoice_view.xml b/addons/account/views/account_invoice_view.xml index cfd46126895..09af679aae2 100644 --- a/addons/account/views/account_invoice_view.xml +++ b/addons/account/views/account_invoice_view.xml @@ -94,7 +94,7 @@ <field name="name"/> <field name="account_id" groups="account.group_account_user"/> <field name="base"/> - <field name="amount"/> + <field name="amount_total"/> <field name="currency_id" invisible="1"/> </tree> </field> @@ -111,7 +111,7 @@ <field name="account_id" groups="account.group_account_user"/> <field name="account_analytic_id" domain="[('company_id', '=', parent.company_id)]" groups="analytic.group_analytic_accounting"/> <field name="manual"/> - <field name="amount"/> + <field name="amount_total"/> <field name="base"/> <field name="currency_id" invisible="1"/> </group> @@ -296,7 +296,9 @@ <field name="manual" invisible="1"/> <field name="account_id" groups="account.group_account_user"/> <field name="account_analytic_id" domain="[('company_id', '=', parent.company_id)]" groups="analytic.group_analytic_accounting"/> - <field name="amount"/> + <field name="amount" invisible="1"/> + <field name="amount_rounding" invisible="1"/> + <field name="amount_total"/> <field name="currency_id" invisible="1"/> </tree> </field> @@ -390,6 +392,8 @@ context="{'search_default_customer':1, 'show_address': 1, 'default_company_type': 'company'}" options='{"always_reload": True, "no_quick_create": True}' domain="[('customer', '=', True)]"/> + <field name="payment_term_id"/> + <field name="cash_rounding_id" groups="account.group_cash_rounding"/> </group> <group> <field name="date_invoice"/> @@ -411,6 +415,7 @@ <field name="sequence" widget="handle"/> <field name="product_id" domain="[('sale_ok','=',True)]"/> <field name="origin" invisible="1"/> + <field name="is_rounding_line" invisible="1"/> <field name="name"/> <field name="company_id" invisible="1"/> <field name="account_id" groups="account.group_account_user" @@ -468,7 +473,6 @@ <page string="Other Info" name="other_info"> <group> <group> - <field name="payment_term_id"/> <field name="fiscal_position_id" options="{'no_create': True}" /> <field name="journal_id" groups="account.group_account_user" options="{'no_create': True}" attrs="{'readonly':[('move_name','!=',False)]}"/> @@ -492,7 +496,9 @@ <field name="sequence" invisible="1"/> <field name="manual" invisible="1"/> <field name="account_id" groups="account.group_account_user"/> - <field name="amount"/> + <field name="amount" invisible="1"/> + <field name="amount_rounding" invisible="1"/> + <field name="amount_total"/> <field name="currency_id" invisible="1"/> </tree> </field> diff --git a/addons/account/views/res_config_settings_views.xml b/addons/account/views/res_config_settings_views.xml index e3cff4bf7d5..aa59af53716 100644 --- a/addons/account/views/res_config_settings_views.xml +++ b/addons/account/views/res_config_settings_views.xml @@ -435,6 +435,22 @@ </div> </div> </div> + <div class="col-xs-12 col-md-6 o_setting_box"> + <div class="o_setting_left_pane"> + <field name="group_cash_rounding"/> + </div> + <div class="o_setting_right_pane"> + <label for="group_cash_rounding"/> + <div class="text-muted"> + Define the smallest coinage of the currency used to pay by cash. + </div> + <div> + <button name="%(account.rounding_list_action)d" icon="fa-arrow-right" + type="action" string="Cash Roundings" class="btn-link" + attrs="{'invisible': [('group_cash_rounding', '=', False)]}"/> + </div> + </div> + </div> </div> <h2 groups="account.group_account_user">Automated Entries</h2> <div class="row mt16 o_settings_container" id="recommended_apps" groups="account.group_account_user"> diff --git a/addons/l10n_ch/__init__.py b/addons/l10n_ch/__init__.py index 84e652daefd..bc5741375fc 100644 --- a/addons/l10n_ch/__init__.py +++ b/addons/l10n_ch/__init__.py @@ -5,6 +5,25 @@ from . import models from odoo import api, SUPERUSER_ID -def load_translations(cr, registry): - env = api.Environment(cr, SUPERUSER_ID, {}) + +def load_translations(env): env.ref('l10n_ch.l10nch_chart_template').process_coa_translations() + + +def init_settings(env): + '''If the company is localized in Switzerland, activate the cash rounding by default. + ''' + # The cash rounding is activated by default only if the company is localized in Switzerland. + for company in env['res.company'].search([('country_id', '=', env.ref('base.ch').id)]): + res_config_id = env['account.config.settings'].create({ + 'company_id': company.id, + 'group_cash_rounding': True + }) + # We need to call execute, otherwise the "implied_group" in fields are not processed. + res_config_id.execute() + + +def post_init(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + load_translations(env) + init_settings(env) diff --git a/addons/l10n_ch/__manifest__.py b/addons/l10n_ch/__manifest__.py index 1db941997b1..b9b586b5112 100644 --- a/addons/l10n_ch/__manifest__.py +++ b/addons/l10n_ch/__manifest__.py @@ -46,7 +46,8 @@ Here is how it works: 'demo': [ '../account/demo/account_bank_statement.yml', '../account/demo/account_invoice_demo.yml', + 'demo/account_cash_rounding.xml', ], - 'post_init_hook': 'load_translations', + 'post_init_hook': 'post_init', } diff --git a/addons/l10n_ch/demo/account_cash_rounding.xml b/addons/l10n_ch/demo/account_cash_rounding.xml new file mode 100644 index 00000000000..eff16e4e322 --- /dev/null +++ b/addons/l10n_ch/demo/account_cash_rounding.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <data> + <record id="cash_rounding_5_centime" model="account.cash.rounding"> + <field name="name">Coinage 0.05</field> + <field name="rounding">0.05</field> + <field name="strategy">add_invoice_line</field> + </record> + </data> +</odoo> |
