6 Commits
7.6 ... 6.4

Author SHA1 Message Date
4738104006 fix: Se añade total_tip 2024-03-05 14:42:20 -05:00
1ad532c033 fix: UPDATE on_change_lines 2024-03-04 13:17:35 -05:00
57f95f0b7d fix: Se elimina producto Tip de Bill report 2024-03-03 10:18:38 -05:00
cd199fbaa0 Fix: UPDATE Total descuento 2024-03-03 10:03:00 -05:00
c2b590b052 feat: Se añade campo rate in SaleLine 2024-02-25 14:05:35 -05:00
0bc83265e1 feat: Se añade tip in totals 2024-02-20 02:17:05 +00:00
3 changed files with 43 additions and 3 deletions

39
sale.py
View File

@@ -2,6 +2,7 @@ from trytond.pool import Pool, PoolMeta
from trytond.model import ModelView, fields
from trytond.transaction import Transaction
from trytond.modules.currency.fields import Monetary
from trytond.pyson import Eval
from decimal import Decimal
import requests
@@ -18,6 +19,12 @@ 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):
@@ -40,6 +47,7 @@ class Sale(metaclass=PoolMeta):
self.tax_amount = Decimal('0.0')
self.total_amount = Decimal('0.0')
self.total_discount = Decimal('0.0')
self.total_tip = Decimal('0.0')
if self.lines:
for line in self.lines:
@@ -50,6 +58,7 @@ class Sale(metaclass=PoolMeta):
self.tax_amount = self.currency.round(self.tax_amount)
self.total_amount = self.untaxed_amount + self.tax_amount
if self.currency:
self.total_tip = self.currency.round(self.total_tip)
self.total_discount = self.currency.round(self.total_discount)
self.total_amount = self.currency.round(self.total_amount)
@@ -60,6 +69,7 @@ class Sale(metaclass=PoolMeta):
sale.tax_amount_cache = sale.tax_amount
sale.total_amount_cache = sale.total_amount
sale.total_discount_cache = sale.total_discount
sale.total_tip_cache = sale.total_tip
cls.save(sales)
@classmethod
@@ -68,6 +78,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 +94,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
@@ -91,8 +103,11 @@ class Sale(metaclass=PoolMeta):
(line.amount for line in sale.lines
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)
(line.discount_amount * Decimal(line.quantity) for line in sale.lines
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 +118,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 +183,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 line.type == 'line' and 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"
@@ -330,6 +347,17 @@ class Line(metaclass=PoolMeta):
pizza = fields.Integer("Pizza")
impreso = fields.Boolean("Impreso")
bought_pizza = fields.Boolean("Sold pizza")
rate = fields.Numeric(
"Rate", digits=(16, 4),
states={
'invisible': Eval('type') != 'line',
'readonly': Eval('sale_state') != 'draft',
},
depends=['type', 'sale_state'])
@classmethod
def default_rate(cls):
return 0
@fields.depends('product', 'unit', 'sale',
'_parent_sale.party', '_parent_sale.invoice_party',
@@ -349,3 +377,8 @@ class Line(metaclass=PoolMeta):
Production = super(Line, self).get_production()
return Production
@fields.depends('discount_rate')
def on_change_discount_rate(self):
if self.discount_rate:
self.rate = self.discount_rate

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>

View File

@@ -10,4 +10,8 @@
<label name="bought_pizza"/>
<field name="bought_pizza"/>
</xpath>
<xpath expr="//field[@name='discount_rate']" position="after">
<label name="discount_rate"/>
<field name="discount_rate" factor="100"/>
</xpath>
</data>