From cd3f52ba1064000483f1a4cd781cf576767b4e01 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 27 May 2016 11:38:20 +0200 Subject: [PATCH] [FIX] account,*: preserve deactivated taxes By default, when reading a m2m field, entries that are deactivated in the destination table are not included. This behavior is desirable in some cases (e.g. for "tags" or "categories", but not for entries that significantly impact other field values in the parent record, such as taxes. The problem is rather obvious: when displaying a paid invoice that used taxes that are now deactivated, the taxes are hidden while they still affect the computed amount. And after cancelling + resetting to draft, the tax is not taken into account anymore, while still being linked. Forcing the field-level (python) domain to include both active and inactive entries solves the problem: - when reading, displaying and recomputing values, deactivated taxes will be included. - when trying to pick a tax, deactivated entries will still be ignored, as expected. This commit applies the technique to all m2m fields that refer to taxes. Fixes #12066 opw-677751 --- addons/account/account_invoice.py | 2 +- addons/mrp_repair/mrp_repair.py | 6 ++++-- addons/purchase/purchase.py | 2 +- addons/sale/sale.py | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 17ccfb3bd86..aefa91aa3da 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -1283,7 +1283,7 @@ class account_invoice_line(models.Model): default=0.0) invoice_line_tax_id = fields.Many2many('account.tax', 'account_invoice_line_tax', 'invoice_line_id', 'tax_id', - string='Taxes', domain=[('parent_id', '=', False)]) + string='Taxes', domain=[('parent_id', '=', False), '|', ('active', '=', False), ('active', '=', True)]) account_analytic_id = fields.Many2one('account.analytic.account', string='Analytic Account') company_id = fields.Many2one('res.company', string='Company', diff --git a/addons/mrp_repair/mrp_repair.py b/addons/mrp_repair/mrp_repair.py index d30abe291c1..3b1c71c7062 100644 --- a/addons/mrp_repair/mrp_repair.py +++ b/addons/mrp_repair/mrp_repair.py @@ -578,7 +578,8 @@ class mrp_repair_line(osv.osv, ProductChangeMixin): 'invoiced': fields.boolean('Invoiced', readonly=True, copy=False), 'price_unit': fields.float('Unit Price', required=True, digits_compute=dp.get_precision('Product Price')), 'price_subtotal': fields.function(_amount_line, string='Subtotal', digits_compute=dp.get_precision('Account')), - 'tax_id': fields.many2many('account.tax', 'repair_operation_line_tax', 'repair_operation_line_id', 'tax_id', 'Taxes'), + 'tax_id': fields.many2many('account.tax', 'repair_operation_line_tax', 'repair_operation_line_id', 'tax_id', 'Taxes', + domain=['|', ('active', '=', False), ('active', '=', True)]), 'product_uom_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), required=True), 'product_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True), 'invoice_line_id': fields.many2one('account.invoice.line', 'Invoice Line', readonly=True, copy=False), @@ -672,7 +673,8 @@ class mrp_repair_fee(osv.osv, ProductChangeMixin): 'price_unit': fields.float('Unit Price', required=True), 'product_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True), 'price_subtotal': fields.function(_amount_line, string='Subtotal', digits_compute=dp.get_precision('Account')), - 'tax_id': fields.many2many('account.tax', 'repair_fee_line_tax', 'repair_fee_line_id', 'tax_id', 'Taxes'), + 'tax_id': fields.many2many('account.tax', 'repair_fee_line_tax', 'repair_fee_line_id', 'tax_id', 'Taxes', + domain=['|', ('active', '=', False), ('active', '=', True)]), 'invoice_line_id': fields.many2one('account.invoice.line', 'Invoice Line', readonly=True, copy=False), 'to_invoice': fields.boolean('To Invoice'), 'invoiced': fields.boolean('Invoiced', readonly=True, copy=False), diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index d52c166a361..8e7aed998c8 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -1098,7 +1098,7 @@ class purchase_order_line(osv.osv): 'name': fields.text('Description', required=True), 'product_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), required=True), 'date_planned': fields.date('Scheduled Date', required=True, select=True), - 'taxes_id': fields.many2many('account.tax', 'purchase_order_taxe', 'ord_id', 'tax_id', 'Taxes'), + 'taxes_id': fields.many2many('account.tax', 'purchase_order_taxe', 'ord_id', 'tax_id', 'Taxes', domain=['|', ('active', '=', False), ('active', '=', True)]), 'product_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True), 'product_id': fields.many2one('product.product', 'Product', domain=[('purchase_ok','=',True)], change_default=True), 'move_ids': fields.one2many('stock.move', 'purchase_line_id', 'Reservation', readonly=True, ondelete='set null'), diff --git a/addons/sale/sale.py b/addons/sale/sale.py index a64ef85e68d..b4643fc6eb7 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -923,7 +923,7 @@ class sale_order_line(osv.osv): 'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price'), readonly=True, states={'draft': [('readonly', False)]}), 'price_subtotal': fields.function(_amount_line, string='Subtotal', digits_compute= dp.get_precision('Account')), 'price_reduce': fields.function(_get_price_reduce, type='float', string='Price Reduce', digits_compute=dp.get_precision('Product Price')), - 'tax_id': fields.many2many('account.tax', 'sale_order_tax', 'order_line_id', 'tax_id', 'Taxes', readonly=True, states={'draft': [('readonly', False)]}), + 'tax_id': fields.many2many('account.tax', 'sale_order_tax', 'order_line_id', 'tax_id', 'Taxes', readonly=True, states={'draft': [('readonly', False)]}, domain=['|', ('active', '=', False), ('active', '=', True)]), 'address_allotment_id': fields.many2one('res.partner', 'Allotment Partner',help="A partner to whom the particular product needs to be allotted."), 'product_uom_qty': fields.float('Quantity', digits_compute= dp.get_precision('Product UoS'), required=True, readonly=True, states={'draft': [('readonly', False)]}), 'product_uom': fields.many2one('product.uom', 'Unit of Measure ', required=True, readonly=True, states={'draft': [('readonly', False)]}),