Skip to content
Snippets Groups Projects
Commit ec30c1b4 authored by Nicolas Martinelli's avatar Nicolas Martinelli Committed by Nicolas Martinelli
Browse files

[FIX] point_of_sale: modify tax

Prevent the modification of a tax which is used in an opened POS
session. This avoids inconsistency between the payment and the order
accounting entries.

opw-1859092
parent 06a80459
No related branches found
No related tags found
No related merge requests found
......@@ -1584,6 +1584,11 @@ msgstr ""
msgid "It acts as a default account for debit amount"
msgstr ""
#: code:addons/point_of_sale/models/account_tax.py:18
#, python-format
msgid "It is forbidden to modify a tax used in a POS order not posted. You must close the POS sessions before modifying the tax."
msgstr ""
#. module: point_of_sale
#: model:ir.model,name:point_of_sale.model_account_journal
#: model:ir.model.fields,field_description:point_of_sale.field_report_pos_order__journal_id
......
......@@ -3,6 +3,7 @@
from . import account_bank_statement
from . import account_journal
from . import account_tax
from . import barcode_rule
from . import pos_category
from . import pos_config
......
# -*- coding: utf-8 -*-
from odoo import _, api, models
from odoo.exceptions import UserError
class AccountTax(models.Model):
_inherit = 'account.tax'
@api.multi
def write(self, vals):
forbidden_fields = set([
'amount_type', 'amount', 'type_tax_use', 'tax_group_id', 'price_include',
'include_base_amount'
])
if forbidden_fields & set(vals.keys()):
tax_ids = self.env['pos.order.line'].sudo().search([
('order_id.session_id.state', '!=', 'closed')
]).read(['tax_ids'])
# Flatten the list of taxes, see https://stackoverflow.com/questions/952914
tax_ids = set([i for sl in [t['tax_ids'] for t in tax_ids] for i in sl])
if tax_ids & set(self.ids):
raise UserError(_(
'It is forbidden to modify a tax used in a POS order not posted. ' +
'You must close the POS sessions before modifying the tax.'
))
return super(AccountTax, self).write(vals)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment