minor fix
This commit is contained in:
parent
e32f88365a
commit
3150b5e2dd
42
sale.py
42
sale.py
|
@ -388,33 +388,33 @@ class Sale(metaclass=PoolMeta):
|
||||||
ctx = Transaction().context
|
ctx = Transaction().context
|
||||||
|
|
||||||
user = User(ctx.get('user'))
|
user = User(ctx.get('user'))
|
||||||
shop = Shop(args['shop']['id'])
|
shop = Shop(args['shop'])
|
||||||
attribs_del = ['id', 'amount', 'unit_price_w_tax', 'total_amount', 'discount']
|
attribs_del = ['id', 'amount', 'unit_price_w_tax', 'total_amount']
|
||||||
for v in args['lines']:
|
lines = args['lines']
|
||||||
|
nested_values = None
|
||||||
|
for line in lines:
|
||||||
|
if line and line[0] == 'create':
|
||||||
|
nested_values = line[1]
|
||||||
|
if nested_values:
|
||||||
|
lines = nested_values
|
||||||
|
for v in lines:
|
||||||
keys = v.keys()
|
keys = v.keys()
|
||||||
for k in attribs_del:
|
for k in attribs_del:
|
||||||
if k in keys:
|
if k in keys:
|
||||||
del v[k]
|
del v[k]
|
||||||
v['type'] = 'line'
|
v['type'] = 'line'
|
||||||
product = Product(v['product']['id'])
|
product = Product(v['product'])
|
||||||
|
v['unit_price'] = Decimal(str(v['unit_price']))
|
||||||
|
v['base_price'] = Decimal(str(v['base_price']))
|
||||||
|
if v.get('discount'):
|
||||||
|
v['discount'] = Decimal(str(v['discount']))
|
||||||
|
|
||||||
if v.get('unit_price'):
|
|
||||||
v['unit_price'] = Decimal(str(v['unit_price']))
|
|
||||||
# else:
|
|
||||||
# v['unit_price'] = product.list_price
|
|
||||||
if v.get('unit_price') == 0:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
v['base_price'] = product.list_price
|
|
||||||
v['unit'] = product.template.default_uom.id
|
|
||||||
v['description'] = product.name
|
|
||||||
v['product'] = v['product']['id']
|
|
||||||
taxes = list(product.account_category.customer_taxes_used)
|
taxes = list(product.account_category.customer_taxes_used)
|
||||||
taxes_ids = [t.id for t in taxes]
|
taxes_ids = [t.id for t in taxes]
|
||||||
v['taxes'] = [('add', taxes_ids)]
|
v['taxes'] = [('add', taxes_ids)]
|
||||||
|
|
||||||
price_list = args.get('price_list', None)
|
price_list = args.get('price_list', None)
|
||||||
party = Party(args['party']['id'])
|
party = Party(args['party'])
|
||||||
if args.get('shipment_address'):
|
if args.get('shipment_address'):
|
||||||
shipment_address_id = args.get('shipment_address')
|
shipment_address_id = args.get('shipment_address')
|
||||||
else:
|
else:
|
||||||
|
@ -445,8 +445,8 @@ class Sale(metaclass=PoolMeta):
|
||||||
date_ = datetime.now() - timedelta(hours=5)
|
date_ = datetime.now() - timedelta(hours=5)
|
||||||
today = date(date_.year, date_.month, date_.day)
|
today = date(date_.year, date_.month, date_.day)
|
||||||
to_create = {
|
to_create = {
|
||||||
'consumer': args['consumer']['id'],
|
'consumer': args['consumer'],
|
||||||
'source': args['source']['id'],
|
'source': args['source'],
|
||||||
'kind': args['kind'],
|
'kind': args['kind'],
|
||||||
'delivery_amount': delivery,
|
'delivery_amount': delivery,
|
||||||
'shop': shop.id,
|
'shop': shop.id,
|
||||||
|
@ -468,10 +468,10 @@ class Sale(metaclass=PoolMeta):
|
||||||
'order_status': 'requested',
|
'order_status': 'requested',
|
||||||
'description': description,
|
'description': description,
|
||||||
'comment': comment,
|
'comment': comment,
|
||||||
'lines': [('create', args['lines'])],
|
'lines': [('create', lines)],
|
||||||
}
|
}
|
||||||
if args.get('consumer'):
|
if args.get('consumer'):
|
||||||
to_create['consumer'] = args['consumer']['id']
|
to_create['consumer'] = args['consumer']
|
||||||
order_status_time = OrderStatusTime.create([{ 'requested': datetime.now()}])
|
order_status_time = OrderStatusTime.create([{ 'requested': datetime.now()}])
|
||||||
to_create['order_status_time'] = order_status_time[0].id
|
to_create['order_status_time'] = order_status_time[0].id
|
||||||
print(to_create, 'validate to create')
|
print(to_create, 'validate to create')
|
||||||
|
@ -487,7 +487,7 @@ class Sale(metaclass=PoolMeta):
|
||||||
})
|
})
|
||||||
res = {
|
res = {
|
||||||
'record': record,
|
'record': record,
|
||||||
'msg': 'successful_order',
|
'msg': f'Venta creada {sale.number}',
|
||||||
'type': 'success',
|
'type': 'success',
|
||||||
'status': 'ok',
|
'status': 'ok',
|
||||||
'open_modal': True,
|
'open_modal': True,
|
||||||
|
|
Loading…
Reference in New Issue