From 0bc83265e1ab6a12f93c71e0cd1333e7b60d1f4d Mon Sep 17 00:00:00 2001 From: sinergia Date: Tue, 20 Feb 2024 02:17:05 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20Se=20a=C3=B1ade=20tip=20in=20totals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sale.py | 14 ++++++++++++-- view/sale_form.xml | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/sale.py b/sale.py index b5e48ab..8184e4b 100644 --- a/sale.py +++ b/sale.py @@ -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" diff --git a/view/sale_form.xml b/view/sale_form.xml index 4604357..4eb29e3 100644 --- a/view/sale_form.xml +++ b/view/sale_form.xml @@ -15,5 +15,8 @@ this repository contains the full copyright notices and license terms. -->