Skip to content

Commit

Permalink
[FIX] make onchange raising if there are on taxes fields
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Dec 6, 2018
1 parent 6567948 commit 5e8d78c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions account_product_fiscal_classification/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from . import product_template
from . import product_product
from . import account_product_fiscal_classification_model
from . import account_product_fiscal_classification_template
from . import account_product_fiscal_classification
Expand Down
16 changes: 16 additions & 0 deletions account_product_fiscal_classification/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# coding: utf-8
# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import api, models


class ProductProduct(models.Model):
_inherit = 'product.product'

@api.onchange('fiscal_classification_id')
def onchange_fiscal_classification_id(self):
fc = self.fiscal_classification_id
self.supplier_taxes_id = [[6, 0, fc.purchase_tax_ids.ids]]
self.taxes_id = [[6, 0, fc.sale_tax_ids.ids]]
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ def fields_view_get(
res['arch'] = etree.tostring(doc)
return res

@api.onchange('fiscal_classification_id')
def onchange_fiscal_classification_id(self):
fc = self.fiscal_classification_id
self.supplier_taxes_id = [[6, 0, fc.purchase_tax_ids.ids]]
self.taxes_id = [[6, 0, fc.sale_tax_ids.ids]]

# Custom Section
def write_taxes_setting(self, vals):
"""If Fiscal Classification is defined, set the according taxes
Expand All @@ -91,7 +97,7 @@ def write_taxes_setting(self, vals):
x.id for x in fc.purchase_tax_ids]]],
'taxes_id': [[6, 0, [
x.id for x in fc.sale_tax_ids]]],
}
}
super(ProductTemplate, self.sudo()).write(tax_vals)
elif 'supplier_taxes_id' in vals.keys() or 'taxes_id' in vals.keys():
# product template Single update mode
Expand Down

0 comments on commit 5e8d78c

Please sign in to comment.