4 Commits
6.4 ... 7.0

4 changed files with 8 additions and 47 deletions

46
sale.py
View File

@@ -2,7 +2,6 @@ from trytond.pool import Pool, PoolMeta
from trytond.model import ModelView, fields from trytond.model import ModelView, fields
from trytond.transaction import Transaction from trytond.transaction import Transaction
from trytond.modules.currency.fields import Monetary from trytond.modules.currency.fields import Monetary
from trytond.pyson import Eval
from decimal import Decimal from decimal import Decimal
import requests import requests
@@ -19,12 +18,6 @@ class Sale(metaclass=PoolMeta):
"Total Discount", digits='currency', currency='currency'), "Total Discount", digits='currency', currency='currency'),
'get_amount') 'get_amount')
total_discount_cache = fields.Numeric("Total Discount cache", digits='currency') 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 @classmethod
def __setup__(cls): def __setup__(cls):
@@ -47,7 +40,6 @@ class Sale(metaclass=PoolMeta):
self.tax_amount = Decimal('0.0') self.tax_amount = Decimal('0.0')
self.total_amount = Decimal('0.0') self.total_amount = Decimal('0.0')
self.total_discount = Decimal('0.0') self.total_discount = Decimal('0.0')
self.total_tip = Decimal('0.0')
if self.lines: if self.lines:
for line in self.lines: for line in self.lines:
@@ -58,7 +50,6 @@ class Sale(metaclass=PoolMeta):
self.tax_amount = self.currency.round(self.tax_amount) self.tax_amount = self.currency.round(self.tax_amount)
self.total_amount = self.untaxed_amount + self.tax_amount self.total_amount = self.untaxed_amount + self.tax_amount
if self.currency: if self.currency:
self.total_tip = self.currency.round(self.total_tip)
self.total_discount = self.currency.round(self.total_discount) self.total_discount = self.currency.round(self.total_discount)
self.total_amount = self.currency.round(self.total_amount) self.total_amount = self.currency.round(self.total_amount)
@@ -69,7 +60,6 @@ class Sale(metaclass=PoolMeta):
sale.tax_amount_cache = sale.tax_amount sale.tax_amount_cache = sale.tax_amount
sale.total_amount_cache = sale.total_amount sale.total_amount_cache = sale.total_amount
sale.total_discount_cache = sale.total_discount sale.total_discount_cache = sale.total_discount
sale.total_tip_cache = sale.total_tip
cls.save(sales) cls.save(sales)
@classmethod @classmethod
@@ -78,7 +68,6 @@ class Sale(metaclass=PoolMeta):
tax_amount = {} tax_amount = {}
total_amount = {} total_amount = {}
total_discount = {} total_discount = {}
total_tip = {}
if {'tax_amount', 'total_amount'} & set(names): if {'tax_amount', 'total_amount'} & set(names):
compute_taxes = True compute_taxes = True
else: else:
@@ -91,10 +80,10 @@ class Sale(metaclass=PoolMeta):
if (sale.state in cls._states_cached if (sale.state in cls._states_cached
and sale.untaxed_amount_cache is not None and sale.untaxed_amount_cache is not None
and sale.tax_amount_cache is not None and sale.tax_amount_cache is not None
and sale.total_amount_cache is not None): and sale.total_amount_cache is not None
and sale.total_discount_cache is not None):
untaxed_amount[sale.id] = sale.untaxed_amount_cache untaxed_amount[sale.id] = sale.untaxed_amount_cache
total_discount[sale.id] = sale.total_discount_cache total_discount[sale.id] = sale.total_discount_cache
total_tip[sale.id] = sale.total_tip_cache
if compute_taxes: if compute_taxes:
tax_amount[sale.id] = sale.tax_amount_cache tax_amount[sale.id] = sale.tax_amount_cache
total_amount[sale.id] = sale.total_amount_cache total_amount[sale.id] = sale.total_amount_cache
@@ -103,11 +92,8 @@ class Sale(metaclass=PoolMeta):
(line.amount for line in sale.lines (line.amount for line in sale.lines
if line.type == 'line'), Decimal(0)),2) if line.type == 'line'), Decimal(0)),2)
total_discount[sale.id] = round(sum( total_discount[sale.id] = round(sum(
(line.discount_amount * Decimal(line.quantity) for line in sale.lines (line.discount_amount for line in sale.lines
if line.discount_amount and line.type == 'line'), Decimal(0)), 2) if 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: if compute_taxes:
tax_amount[sale.id] = sale.get_tax_amount() tax_amount[sale.id] = sale.get_tax_amount()
total_amount[sale.id] = ( total_amount[sale.id] = (
@@ -118,7 +104,6 @@ class Sale(metaclass=PoolMeta):
'tax_amount': tax_amount, 'tax_amount': tax_amount,
'total_amount': total_amount, 'total_amount': total_amount,
'total_discount': total_discount, 'total_discount': total_discount,
'total_tip' : total_tip
} }
for key in list(result.keys()): for key in list(result.keys()):
if key not in names: if key not in names:
@@ -183,11 +168,10 @@ class Sale(metaclass=PoolMeta):
"unit_price": str(line.amount_w_tax) if line.type != 'title' else None, "unit_price": str(line.amount_w_tax) if line.type != 'title' else None,
"taxes": str(round(line.taxes[0].rate * 100, 2))+'%' "taxes": str(round(line.taxes[0].rate * 100, 2))+'%'
if line.type != 'title' and line.taxes else None if line.type != 'title' and line.taxes else None
} for line in record.lines if line.type == 'line' and not line.product.tip] } for line in record.lines]
data["total_discount"] = str(round(record.total_discount,2)) data["total_discount"] = str(round(record.total_discount,2))
data["untaxed_amount"] = str(record.untaxed_amount) data["untaxed_amount"] = str(record.untaxed_amount)
data["total_tip"] = str(record.total_tip)
data["tax_amount"] = str(record.tax_amount) data["tax_amount"] = str(record.tax_amount)
data["total"] = str(record.total_amount) data["total"] = str(record.total_amount)
data["state"] = "SUBTOTAL" if record.state == "draft" else "CUENTA FINAL" data["state"] = "SUBTOTAL" if record.state == "draft" else "CUENTA FINAL"
@@ -347,17 +331,6 @@ class Line(metaclass=PoolMeta):
pizza = fields.Integer("Pizza") pizza = fields.Integer("Pizza")
impreso = fields.Boolean("Impreso") impreso = fields.Boolean("Impreso")
bought_pizza = fields.Boolean("Sold pizza") 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', @fields.depends('product', 'unit', 'sale',
'_parent_sale.party', '_parent_sale.invoice_party', '_parent_sale.party', '_parent_sale.invoice_party',
@@ -372,13 +345,8 @@ class Line(metaclass=PoolMeta):
else: else:
self.bought_pizza = False self.bought_pizza = False
def get_production(self): def get_production(self, product_quantities ):
"Return production for the sale line" "Return production for the sale line"
Production = super(Line, self).get_production() Production = super(Line, self).get_production(product_quantities)
return Production return Production
@fields.depends('discount_rate')
def on_change_discount_rate(self):
if self.discount_rate:
self.rate = self.discount_rate

View File

@@ -1,5 +1,5 @@
[tryton] [tryton]
version=6.4 version=7.0.0
depends: depends:
ir ir
res res

View File

@@ -15,8 +15,5 @@ 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"> <xpath expr="/form/notebook/page[@id='sale']/group[@id='amount']/field[@name='tax_amount']" position="after">
<label name="total_discount"/> <label name="total_discount"/>
<field name="total_discount"/> <field name="total_discount"/>
<label name="total_tip"/>
<field name="total_tip"/>
</xpath> </xpath>
</data> </data>

View File

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