Minor fix

This commit is contained in:
oscar alvarez 2023-09-03 07:41:51 -05:00
parent 5ff530c982
commit a088ad46e9
1 changed files with 13 additions and 11 deletions

24
sale.py
View File

@ -6,13 +6,13 @@ from decimal import Decimal
from sql import Table from sql import Table
from sql.aggregate import Sum from sql.aggregate import Sum
from datetime import date, timedelta, datetime from datetime import date, timedelta, datetime
from time import sleep
from trytond.pool import Pool, PoolMeta from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction from trytond.transaction import Transaction
from trytond.model import fields from trytond.model import fields
from trytond.modules.dash.dash import DashAppBase from trytond.modules.dash.dash import DashAppBase
from .process_pay import get_pay, get_response_pay, process_response, get_dict_response_pay from .process_pay import (
get_pay, get_response_pay, process_response, get_dict_response_pay)
class Sale(metaclass=PoolMeta): class Sale(metaclass=PoolMeta):
@ -31,6 +31,7 @@ class Sale(metaclass=PoolMeta):
@classmethod @classmethod
def send_order(cls, args, ctx=None): def send_order(cls, args, ctx=None):
Product = Pool().get('product.product')
if args['id'] <= 0: if args['id'] <= 0:
res = cls.create_sale(args, ctx) res = cls.create_sale(args, ctx)
return res return res
@ -41,6 +42,8 @@ class Sale(metaclass=PoolMeta):
if ln[0] == 'create' and len(ln[1]) > 0: if ln[0] == 'create' and len(ln[1]) > 0:
for p in ln[1]: for p in ln[1]:
p['status_order'] = 'requested' p['status_order'] = 'requested'
product = Product(p['product'])
p['description'] = product.template.name
cls.write(records, args) cls.write(records, args)
res = { res = {
'record': {'id': args['id']}, 'record': {'id': args['id']},
@ -56,7 +59,6 @@ class Sale(metaclass=PoolMeta):
Party = Pool().get('party.party') Party = Pool().get('party.party')
User = Pool().get('res.user') User = Pool().get('res.user')
ctx = Transaction().context ctx = Transaction().context
print(args, 'ctx')
if ctx.get('shop'): if ctx.get('shop'):
shop = Shop(ctx['shop']) shop = Shop(ctx['shop'])
if args.get('shop'): if args.get('shop'):
@ -74,7 +76,6 @@ class Sale(metaclass=PoolMeta):
if nested_values: if nested_values:
lines = nested_values lines = nested_values
for v in lines: for v in lines:
print('Value line to create =====>', v)
if v.get('id'): if v.get('id'):
del v['id'] del v['id']
if v.get('amount'): if v.get('amount'):
@ -93,9 +94,10 @@ class Sale(metaclass=PoolMeta):
elif v.get('discount'): elif v.get('discount'):
del v['discount'] del v['discount']
v['unit'] = product.template.default_uom.id template = product.template
v['description'] = product.name v['unit'] = template.default_uom.id
taxes = list(product.account_category.customer_taxes_used) v['description'] = template.name
taxes = list(template.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)]
@ -105,17 +107,17 @@ class Sale(metaclass=PoolMeta):
price_list = args.get('price_list', None) price_list = args.get('price_list', None)
try: try:
# option kid # for kid
party, = Party.browse([args['party']['id']]) party, = Party.browse([args['party']['id']])
except Exception: except Exception:
# option fastkid # for fastkid
party, = Party.browse([args['party']]) party, = Party.browse([args['party']])
if args.get('shipment_address'): if args.get('shipment_address'):
try: try:
# option kid # for kid
shipment_address_id = args.get('shipment_address')['id'] shipment_address_id = args.get('shipment_address')['id']
except Exception: except Exception:
# option fastkid # for fastkid
shipment_address_id = args.get('shipment_address') shipment_address_id = args.get('shipment_address')
else: else:
shipment_address_id = party.addresses[0].id shipment_address_id = party.addresses[0].id