Skip to content

Commit

Permalink
Merge 4bda787 into 2716503
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Jun 18, 2018
2 parents 2716503 + 4bda787 commit 5187981
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
34 changes: 17 additions & 17 deletions account_product_fiscal_classification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ def create_fiscal_classification_from_product_template(cr, registry):
counter = 0
total = len(templates)
# Associate product template to Fiscal Classifications
for template in templates:
counter += 1
args = [
template.company_id and template.company_id.id or False,
sorted([x.id for x in template.taxes_id]),
sorted([x.id for x in template.supplier_taxes_id])]
if args not in classifications_keys.values():
_logger.info(
"""create new Fiscal Classification. Product templates"""
""" managed %s/%s""" % (counter, total))
classification_id = classification_obj.find_or_create(*args)
classifications_keys[classification_id] = args
# associate product template to the new Fiscal Classification
template.fiscal_classification_id = classification_id
res_list = templates.read(['company_id', 'taxes_id', 'supplier_taxes_id'])
for res in res_list:
key = str([
res['company_id'] and res['company_id'][0],
res['taxes_id'],
res['supplier_taxes_id']])
if key in classifications_keys.keys():
classifications_keys[key].append(res['id'])
else:
# associate product template to existing Fiscal Classification
template.fiscal_classification_id = classifications_keys.keys()[
classifications_keys.values().index(args)]
classifications_keys[key] = [res['id']]
for key, value in classifications_keys.iteritems():
counter += len(value)
_logger.info(
"create new Fiscal Classification for %d Product templates"
" %d / %d" % (len(value), counter, total))
classification_id = classification_obj.find_or_create(*eval(key))
sub_templates = templates.browse(value)
sub_templates.write({'fiscal_classification_id': classification_id})
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,16 @@ def fields_view_get(
return res

# Custom Section
@api.multi
def write_taxes_setting(self, vals):
"""If Fiscal Classification is defined, set the according taxes
to the product(s); Otherwise, find the correct Fiscal classification,
depending of the taxes, or create a new one, if no one are found."""
if not self:
return
if vals.get('fiscal_classification_id', False):
# update or replace 'taxes_id' and 'supplier_taxes_id'
classification = self.fiscal_classification_id
classification = self[0].fiscal_classification_id
tax_vals = {
'supplier_taxes_id': [[6, 0, [
x.id for x in classification.purchase_tax_ids]]],
Expand Down

0 comments on commit 5187981

Please sign in to comment.