add field allow discount

This commit is contained in:
wilson gomez 2021-06-19 10:01:49 -05:00
parent c4ddac4ef4
commit c4460f0a8f
2 changed files with 16 additions and 0 deletions

14
sale.py
View File

@ -43,6 +43,13 @@ class Sale(metaclass=PoolMeta):
del v['unit_price_w_tax']
v['type'] = 'line'
product = Product(v['product'])
if v.get('discount') and v['discount'] != '':
v['discount'] = Decimal(v['discount'])/100
unit_price = product.list_price - (product.list_price * Decimal(v['discount']))
v['unit_price'] = Decimal(unit_price).quantize(Decimal(str(10.0 ** -4)))
elif v.get('discount'):
del v['discount']
v['unit'] = product.template.default_uom.id
v['description'] = product.name
taxes = list(product.account_category.customer_taxes_used)
@ -87,6 +94,11 @@ class Sale(metaclass=PoolMeta):
'lines': [('create', args['lines'])],
}
sale, = cls.create([to_create])
for line in sale.lines:
if line.discount and line.discount > 0:
line.on_change_discount()
print(line.discount, line.unit_price, line.unit_price_w_tax, 'valores resultados')
cls.quote([sale])
record = args.copy()
record.update({
@ -288,7 +300,9 @@ class AppDelivery(ModelSQL, ModelView):
class AppSaleOrder(ModelSQL, ModelView):
'App Sale Order'
__name__ = 'dash.app.sale_order'
company = fields.Many2One('company.company', 'Company', required=True)
allow_discount = fields.Boolean('Allow Discount')
@classmethod
def __setup__(cls):

View File

@ -4,4 +4,6 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
<form>
<label name="company"/>
<field name="company" widget="selection"/>
<label name="allow_discount"/>
<field name="allow_discount" />
</form>