diff --git a/addons/account/models/__init__.py b/addons/account/models/__init__.py index b6b023055b8..5f99c57e04d 100644 --- a/addons/account/models/__init__.py +++ b/addons/account/models/__init__.py @@ -19,3 +19,4 @@ from . import reconciliation_widget from . import account_incoterms from . import digest from . import account_invoice_import_wizard +from . import res_users diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 30b92b411c4..2974c2119c9 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -103,6 +103,11 @@ class AccountInvoice(models.Model): if invoice_type == 'out_invoice' and self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms'): return self.env.user.company_id.invoice_terms + def _get_aml_for_amount_residual(self): + """ Get the aml to consider to compute the amount residual of invoices """ + self.ensure_one() + return self.sudo().move_id.line_ids.filtered(lambda l: l.account_id == self.account_id) + @api.one @api.depends( 'state', 'currency_id', 'invoice_line_ids.price_subtotal', @@ -112,14 +117,13 @@ class AccountInvoice(models.Model): residual = 0.0 residual_company_signed = 0.0 sign = self.type in ['in_refund', 'out_refund'] and -1 or 1 - for line in self.sudo().move_id.line_ids: - if line.account_id == self.account_id: - residual_company_signed += line.amount_residual - if line.currency_id == self.currency_id: - residual += line.amount_residual_currency if line.currency_id else line.amount_residual - else: - from_currency = line.currency_id or line.company_id.currency_id - residual += from_currency._convert(line.amount_residual, self.currency_id, line.company_id, line.date or fields.Date.today()) + for line in self._get_aml_for_amount_residual(): + residual_company_signed += line.amount_residual + if line.currency_id == self.currency_id: + residual += line.amount_residual_currency if line.currency_id else line.amount_residual + else: + from_currency = line.currency_id or line.company_id.currency_id + residual += from_currency._convert(line.amount_residual, self.currency_id, line.company_id, line.date or fields.Date.today()) self.residual_company_signed = abs(residual_company_signed) * sign self.residual_signed = abs(residual) * sign self.residual = abs(residual) @@ -1068,12 +1072,18 @@ class AccountInvoice(models.Model): tax_grouped[key][field] += round_curr(val.get(field) or 0) return tax_grouped + @api.multi + def _get_aml_for_register_payment(self): + """ Get the aml to consider to reconcile in register payment """ + self.ensure_one() + return self.move_id.line_ids.filtered(lambda r: not r.reconciled and r.account_id.internal_type in ('payable', 'receivable')) + @api.multi def register_payment(self, payment_line, writeoff_acc_id=False, writeoff_journal_id=False): """ Reconcile payable/receivable lines from the invoice with payment_line """ line_to_reconcile = self.env['account.move.line'] for inv in self: - line_to_reconcile += inv.move_id.line_ids.filtered(lambda r: not r.reconciled and r.account_id.internal_type in ('payable', 'receivable')) + line_to_reconcile += inv._get_aml_for_register_payment() return (line_to_reconcile + payment_line).reconcile(writeoff_acc_id, writeoff_journal_id) @api.multi diff --git a/addons/account/models/res_users.py b/addons/account/models/res_users.py new file mode 100644 index 00000000000..3e6fd163482 --- /dev/null +++ b/addons/account/models/res_users.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models, _ +from odoo.exceptions import ValidationError + + +class Users(models.Model): + _inherit = "res.users" + + @api.multi + @api.constrains('groups_id') + def _check_one_user_type(self): + super(Users, self)._check_one_user_type() + for user in self: + if (user.user_has_groups('account.group_show_line_subtotals_tax_included') and + user.user_has_groups('account.group_show_line_subtotals_tax_excluded')): + raise ValidationError(_('A user cannot have both Tax B2B and Tax B2C')) diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml index c0abc40d236..234d1c4b53c 100644 --- a/addons/account/views/account_view.xml +++ b/addons/account/views/account_view.xml @@ -1263,6 +1263,7 @@ + @@ -1270,7 +1271,7 @@ - +