Add get line

This commit is contained in:
oscar 2021-04-08 09:20:38 -05:00
parent a34ff9dbff
commit dd0bb097e3
1 changed files with 63 additions and 3 deletions

66
sale.py
View File

@ -1,6 +1,8 @@
# This file is part of purchase_discount module for Tryton. # This file is part of purchase_discount module for Tryton.
# The COPYRIGHT file at the top level of this repository contains # The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms. # the full copyright notices and license terms.
import math
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 from datetime import date
@ -23,6 +25,7 @@ class Sale(metaclass=PoolMeta):
Product = Pool().get('product.product') Product = Pool().get('product.product')
shop_id = ctx['shop'] shop_id = ctx['shop']
shop = Shop(shop_id) shop = Shop(shop_id)
today = date.today()
for v in args['lines']: for v in args['lines']:
del v['id'] del v['id']
del v['amount'] del v['amount']
@ -30,19 +33,23 @@ class Sale(metaclass=PoolMeta):
product = Product(v['product']) product = Product(v['product'])
v['unit'] = product.template.default_uom.id v['unit'] = product.template.default_uom.id
price_list = args.get('price_list', None)
if price_list:
price_list = price_list['id']
to_create = { to_create = {
'shop': shop_id, 'shop': shop_id,
'invoice_type': 'P', 'invoice_type': 'P',
'company': shop.company.id, 'company': shop.company.id,
'party': args['party']['id'], 'party': args['party']['id'],
'sale_date': args['sale_date'], 'sale_date': today,
'shipment_date': args['shipment_date'],
'shipment_address': args['shipment_address']['id'], 'shipment_address': args['shipment_address']['id'],
'invoice_address': args['shipment_address']['id'], 'invoice_address': args['shipment_address']['id'],
'agent': args['agent']['id'], 'agent': args['agent']['id'],
'price_list': args.get('price_list'), 'price_list': price_list,
'payment_term': shop.payment_term.id, 'payment_term': shop.payment_term.id,
'state': 'draft', 'state': 'draft',
'comment': args.get('comment', ''), 'description': args.get('comment', ''),
'lines': [('create', args['lines'])], 'lines': [('create', args['lines'])],
} }
sale, = cls.create([to_create]) sale, = cls.create([to_create])
@ -56,6 +63,59 @@ class Sale(metaclass=PoolMeta):
} }
return res return res
@classmethod
def dash_get_line(cls, args, ctx):
if not args.get('product'):
return {}
Product = Pool().get('product.product')
PriceListLine = Pool().get('product.price_list.line')
product_id = args['product']['id']
product = Product(product_id)
with Transaction().set_context(ctx):
unit_price = product.list_price
if args.get('quantity'):
quantity = int(args.get('quantity'))
else:
quantity = 1
if ctx.get('price_list'):
price_list_id = ctx.get('price_list')['id']
else:
price_list_id = None
percent_commission = 0
if price_list_id:
price_lines = PriceListLine.search([
('price_list', '=', price_list_id),
('product', '=', product_id),
])
if price_lines:
price_line = price_lines[0]
unit_price = float(unit_price)
unit_price = Decimal(eval(price_line.formula))
percent_commission = price_line.price_list.percent_commission
#ADD TAXES
taxes_ids = [t.id for t in product.customer_taxes_used]
# res = cls.get_price_with_tax([line], ['amount_w_tax', 'unit_price_w_tax'])
print('prueba.........')
res = {
# 'unit_price_w_tax': math.ceil(res['unit_price_w_tax'][None]),
# 'amount_w_tax': math.ceil(res['amount_w_tax'][None]),
# 'taxes': [[('add'), taxes_ids]],
'unit_price': math.ceil(unit_price),
'unit': product.template.default_uom.id,
'type': 'line',
}
if percent_commission:
res['commission_amount'] = round(
(unit_price * quantity * percent_commission), 0
)
return res
@classmethod @classmethod
def report_sales_day(cls, args, ctx): def report_sales_day(cls, args, ctx):
pass pass