forked from Agofer/fix_views_14
Upload script for creating items in price lists
This commit is contained in:
commit
a5d608b6a3
127
create_ProductPricelistItem.py
Normal file
127
create_ProductPricelistItem.py
Normal file
@ -0,0 +1,127 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import odooly
|
||||
import re
|
||||
|
||||
|
||||
|
||||
|
||||
'''Cuando la Dirección de Ventas informa que el precio de un producto no se visualiza en la lista de precios,
|
||||
a pesar de estar actualizado en la hoja de cálculo 'Precios de Venta para Odoo',
|
||||
utilizo este script para actualizar los precios. Posteriormente,
|
||||
es necesario ejecutar la tarea programada (ir_cron) de actualización de precios.'''
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'''Agregamos los id's de las sucursales a las que no queremos actualizar el precio.
|
||||
Por lo general no hay una lista de precios para Buenaventura,
|
||||
por lo que se excluye de la actualización'''
|
||||
|
||||
|
||||
|
||||
branch_exceptions = [6]
|
||||
|
||||
'''Relacionamos el id del producto a actualizar.'''
|
||||
id_product = 1216
|
||||
|
||||
''' relacionamos el precio por kilo del producto para la lista Canal'''
|
||||
Price = 3950
|
||||
|
||||
'''Por tipo de lista ingresamos el margen para canal siempre es 0'''
|
||||
pricelist_types = {
|
||||
'channel': {'margin': 0.00, 'code': 'CN',},
|
||||
'commercial': {'margin': 0.05, 'code': 'CM',},
|
||||
'counter': {'margin': 0.1, 'code': 'MD',},
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def calc_price(margin, weight):
|
||||
price = Price
|
||||
result = price/(1-margin)
|
||||
return result*weight
|
||||
|
||||
def main(odoo):
|
||||
pp = odoo.env['product.pricelist']
|
||||
ppi = odoo.env['product.pricelist.item']
|
||||
hb = odoo.env['hr.branch']
|
||||
cop = odoo.env['res.currency'].get('base.COP')
|
||||
|
||||
patron = r"(.*?) - Lista"
|
||||
|
||||
product_id = odoo.env['product.product'].get(id_product)
|
||||
weight = product_id.weight
|
||||
cod_item = product_id.default_code
|
||||
|
||||
for pricelist_type in pricelist_types:
|
||||
|
||||
cod_pricelist=pricelist_types[pricelist_type]['code']
|
||||
pricelists_ids = pp.search([('pricelist_type','=',pricelist_type)])
|
||||
for pricelist in pricelists_ids:
|
||||
id = pricelist.id
|
||||
branchName = re.search(patron, pricelist.name)
|
||||
branch_id = hb.search([('name', '=', branchName.group(1))])
|
||||
|
||||
if not branch_id or branch_id.id[0] in branch_exceptions:
|
||||
continue
|
||||
else:
|
||||
cod_branch = branch_id.code[0].lower()
|
||||
|
||||
ppi_extid = (f'agofer_listaprecios_item.'
|
||||
f'{cod_branch}_{cod_pricelist}_{cod_item}')
|
||||
product_item_id = ppi.get(ppi_extid)
|
||||
price = calc_price(pricelist_types[pricelist_type]['margin'], weight)
|
||||
if product_item_id:
|
||||
values = {
|
||||
'applied_on': '0_product_variant',
|
||||
'base': 'list_price',
|
||||
'base_pricelist_id': False,
|
||||
'categ_id': False,
|
||||
'compute_price': 'fixed',
|
||||
'date_end': False,
|
||||
'date_start': False,
|
||||
'fixed_price': price,
|
||||
'min_quantity': 0.0,
|
||||
'percent_price': 0.0,
|
||||
'price_discount': 0.0,
|
||||
'price_max_margin': 0.0,
|
||||
'price_min_margin': 0.0,
|
||||
'price_round': 0.0,
|
||||
'price_surcharge': price,
|
||||
}
|
||||
product_item_id.write(values)
|
||||
else:
|
||||
values = {
|
||||
'product_id': product_id,
|
||||
'pricelist_id': id,
|
||||
'applied_on': '0_product_variant',
|
||||
'currency_id': cop.id,
|
||||
'compute_price': 'fixed',
|
||||
'min_quantity': 0.0,
|
||||
'percent_price': 0.0,
|
||||
'price_discount': 0.0,
|
||||
'price_max_margin': 0.0,
|
||||
'price_min_margin': 0.0,
|
||||
'price_round': 0.0,
|
||||
'fixed_price': price,
|
||||
'price_surcharge': price,
|
||||
'date_end': False,
|
||||
'date_start': False,
|
||||
'base_pricelist_id': False,
|
||||
'categ_id': False,
|
||||
}
|
||||
result = ppi.create(values)
|
||||
result._set_external_id(ppi_extid)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
odooly.Client._config_file = os.path.expanduser('odooly.ini')
|
||||
odoo = odooly.Client.from_config('erp_production')
|
||||
main(odoo)
|
||||
Loading…
Reference in New Issue
Block a user