minor fix

This commit is contained in:
wilson gomez 2021-12-03 15:47:39 -05:00
parent e2180d9956
commit 9335b463fc
2 changed files with 1 additions and 60 deletions

View File

@ -1315,7 +1315,7 @@ class PartyWithholdingStart(ModelView):
@classmethod
def selection_certificate_type(cls):
Tax = Pool().get('account.tax')
sel = Tax.clasification.selection
sel = Tax.classification.selection
return sel

View File

@ -10,65 +10,6 @@ from trytond.exceptions import UserError
class PriceList(metaclass=PoolMeta):
__name__ = 'product.price_list'
@classmethod
def import_data(cls, fields_names, data):
pool = Pool()
Prod_price_line = pool.get('product.price_list.line')
Product = pool.get('product.product')
Category = pool.get('product.category')
price_lists = cls.search([])
ls = {l.name: l for l in price_lists}
list_to_create = {}
for row in data:
list_name = row[fields_names.index('name')]
if list_name not in list_to_create.keys():
list_to_create[list_name] = {
'name': list_name,
'tax_included': row[fields_names.index('tax_included')] if row[fields_names.index('tax_included')] else None,
'lines': []
}
formula = row[fields_names.index('lines/formula')] if row[fields_names.index('lines/formula')] != '' else None
product = row[fields_names.index('lines/product')] if row[fields_names.index('lines/product')] != '' else None
category = row[fields_names.index('lines/category')] if row[fields_names.index('lines/product')] != '' else None
if product:
products = Product.search([('code', '=', product)])
if not products:
raise UserError(f'El producto no existe: {product}')
product = products[0].id
if category:
categories = Category.search([('code', 'in', product)])
if not categories:
raise UserError(f'La categoria no existe: {category}')
category = categories[0].id
values_line = {
'quantity': row[fields_names.index('lines/quantity')],
'formula': formula,
}
if category:
values_line.update({'category': category})
if product:
values_line.update({'product': product})
list_to_create[list_name]['lines'].append(values_line)
for list_price in list_to_create.values():
if list_price['name'] in ls.keys():
list_price_update = ls[list_price['name']]
Prod_price_line.delete(list_price_update.lines)
list_price['lines'] = [dict(item, **{'price_list': list_price_update.id}) for item in list_price['lines']]
Prod_price_line.create(list_price['lines'])
else:
list_price_create = cls.create([{
'name': list_price['name'],
'tax_included': list_price['tax_included'],
}])
list_price['lines'] = [dict(item, **{'price_list': list_price_create[0].id}) for item in list_price['lines']]
Prod_price_line.create(list_price['lines'])
return len(list_to_create.values())
class Product(metaclass=PoolMeta):
__name__ = 'product.product'