diff --git a/purchase.py b/purchase.py index d31a88bf19..ee67031dfa 100644 --- a/purchase.py +++ b/purchase.py @@ -932,10 +932,26 @@ class PurchaseLine(ModelSQL, ModelView): res[line.id] = 2 return res + def _get_tax_rule_pattern(self, cursor, user, party, vals, context=None): + ''' + Get tax rule pattern + + :param cursor: the database cursor + :param user: the user id + :param party: the BrowseRecord of the party + :param vals: a dictionary with value from on_change + :param context: the context + :return: a dictionary to use as pattern for tax rule + ''' + res = {} + return res + def on_change_product(self, cursor, user, ids, vals, context=None): party_obj = self.pool.get('party.party') product_obj = self.pool.get('product.product') uom_obj = self.pool.get('product.uom') + tax_rule_obj = self.pool.get('account.tax.rule') + if context is None: context = {} if not vals.get('product'): @@ -966,12 +982,15 @@ class PurchaseLine(ModelSQL, ModelView): [product.id], vals.get('quantity', 0), context=ctx2)[product.id] res['taxes'] = [] for tax in product.supplier_taxes_used: - if party: - if 'supplier_' + tax.group.code in party_obj._columns \ - and party['supplier_' + tax.group.code]: - res['taxes'].append( - party['supplier_' + tax.group.code].id) - continue + if party and party.supplier_tax_rule: + pattern = self._get_tax_rule_pattern(cursor, user, party, + vals, context=context) + tax_id = tax_rule_obj.apply(cursor, user, + party.supplier_tax_rule, tax, pattern, + context=context) + if tax_id: + res['taxes'].append(tax_id) + continue res['taxes'].append(tax.id) if not vals.get('description'):