feat: Se añade tip in totals

This commit is contained in:
sinergia 2024-02-20 02:17:05 +00:00
parent 07390de74a
commit 0bc83265e1
2 changed files with 15 additions and 2 deletions

14
sale.py
View File

@ -18,6 +18,11 @@ class Sale(metaclass=PoolMeta):
"Total Discount", digits='currency', currency='currency'),
'get_amount')
total_discount_cache = fields.Numeric("Total Discount cache", digits='currency')
total_tip = fields.Function(
Monetary(
"Total Tip", digits='currency', currency='currency'),
'get_amount')
total_tip_cache = fields.Numeric("Total Tip cache", digits="currency")
@classmethod
def __setup__(cls):
@ -68,6 +73,7 @@ class Sale(metaclass=PoolMeta):
tax_amount = {}
total_amount = {}
total_discount = {}
total_tip = {}
if {'tax_amount', 'total_amount'} & set(names):
compute_taxes = True
else:
@ -83,6 +89,7 @@ class Sale(metaclass=PoolMeta):
and sale.total_amount_cache is not None):
untaxed_amount[sale.id] = sale.untaxed_amount_cache
total_discount[sale.id] = sale.total_discount_cache
total_tip[sale.id] = sale.total_tip_cache
if compute_taxes:
tax_amount[sale.id] = sale.tax_amount_cache
total_amount[sale.id] = sale.total_amount_cache
@ -92,7 +99,8 @@ class Sale(metaclass=PoolMeta):
if line.type == 'line'), Decimal(0)),2)
total_discount[sale.id] = round(sum(
(line.discount_amount for line in sale.lines
if line.type == 'line'), Decimal(0)), 2)
if line.discount_amount and line.type == 'line'), Decimal(0)), 2)
total_tip[sale.id] = round(sum((line.amount for line in sale.lines if line.product and line.product.tip and line.type == 'line'), Decimal(0)), 2)
if compute_taxes:
tax_amount[sale.id] = sale.get_tax_amount()
total_amount[sale.id] = (
@ -103,6 +111,7 @@ class Sale(metaclass=PoolMeta):
'tax_amount': tax_amount,
'total_amount': total_amount,
'total_discount': total_discount,
'total_tip' : total_tip
}
for key in list(result.keys()):
if key not in names:
@ -167,10 +176,11 @@ class Sale(metaclass=PoolMeta):
"unit_price": str(line.amount_w_tax) if line.type != 'title' else None,
"taxes": str(round(line.taxes[0].rate * 100, 2))+'%'
if line.type != 'title' and line.taxes else None
} for line in record.lines]
} for line in record.lines if not line.product.tip]
data["total_discount"] = str(round(record.total_discount,2))
data["untaxed_amount"] = str(record.untaxed_amount)
data["total_tip"] = str(record.total_tip)
data["tax_amount"] = str(record.tax_amount)
data["total"] = str(record.total_amount)
data["state"] = "SUBTOTAL" if record.state == "draft" else "CUENTA FINAL"

View File

@ -15,5 +15,8 @@ this repository contains the full copyright notices and license terms. -->
<xpath expr="/form/notebook/page[@id='sale']/group[@id='amount']/field[@name='tax_amount']" position="after">
<label name="total_discount"/>
<field name="total_discount"/>
<label name="total_tip"/>
<field name="total_tip"/>
</xpath>
</data>