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
25 changed files with 210 additions and 805 deletions

View File

@@ -1,6 +1,5 @@
from trytond.pool import Pool
from . import (
product, sale, production, invoice, user, report_close_statement, report)
from . import product, sale, production, invoice, user, report_close_statement
__all__ = ['register']
@@ -11,14 +10,9 @@ def register():
invoice.InvoiceLine,
sale.Sale,
sale.Line,
sale.SaleLineDeletedLog,
user.User,
production.Production,
report_close_statement.ReportCloseStatementStart,
report.ReportSaleProduct,
report.ReportSaleByUser,
report.ReportSaleByZone,
report.ReportSaleContext,
module='sale_fast_food', type_='model')
Pool.register(
report_close_statement.PrintReportCloseStatement,

View File

@@ -1,5 +1,7 @@
from trytond.pool import PoolMeta
from trytond.pyson import Eval
from trytond.pool import Pool, PoolMeta
from trytond.model import ModelView, fields
from trytond.exceptions import UserError
from trytond.pyson import Eval
class InvoiceLine(metaclass=PoolMeta):
@@ -11,3 +13,4 @@ class InvoiceLine(metaclass=PoolMeta):
cls.product.states['required'] = (Eval('type') == 'line')
cls.unit_price.domain = []

View File

@@ -58,98 +58,6 @@ msgctxt "field:sale.print_cash_register.start,shop:"
msgid "Shop"
msgstr "Tienda"
msgctxt "field:sale_fast_food.report.context,from_date:"
msgid "From Date"
msgstr "Desde la Fecha"
msgctxt "field:sale_fast_food.report.context,to_date:"
msgid "To Date"
msgstr "Hasta la Fecha"
msgctxt "model:ir.action,name:act_report_sale_fast_food_product_pizza"
msgid "Pizzas Sold by Product"
msgstr "Pizzas Vendidas Por Producto"
msgctxt "model:ir.ui.menu,name:menu_sale_fast_food_pizza"
msgid "Pizzas Sold by Product"
msgstr "Pizzas Vendidas Por Producto"
msgctxt "model:ir.action,name:act_report_sale_fast_food_by_user"
msgid "Sales by User"
msgstr "Ventas Por Usuario"
msgctxt "model:ir.ui.menu,name:menu_sale_fast_food_by_user"
msgid "Sales by User"
msgstr "Ventas Por Usuario"
msgctxt "model:ir.action,name:act_report_sale_fast_food_zone"
msgid "Sales by Zone"
msgstr "Ventas Por Zona"
msgctxt "model:ir.ui.menu,name:menu_sale_fast_food_zone"
msgid "Sales by Zone"
msgstr "Ventas Por Zona"
msgctxt "field:sale_fast_food.reporting.product,product_pizza:"
msgid "Product"
msgstr "Pizza"
msgctxt "field:sale_fast_food.reporting.product,quantity:"
msgid "Quantity"
msgstr "Cantidad"
msgctxt "field:sale_fast_food.reporting.by_user,user:"
msgid "User"
msgstr "Usuario"
msgctxt "field:sale_fast_food.reporting.by_user,completed_sales:"
msgid "Completed Sales"
msgstr "# Ventas"
msgctxt "field:sale_fast_food.reporting.by_user,untaxed_amount:"
msgid "Untaxed Amount"
msgstr "Base Imponible"
msgctxt "field:sale_fast_food.reporting.by_user,tax_amount:"
msgid "Tax Amount"
msgstr "Impuestos"
msgctxt "field:sale_fast_food.reporting.by_user,total_amount:"
msgid "Total Amount"
msgstr "Total"
msgctxt "field:sale_fast_food.reporting.by_user,total_tip_amount:"
msgid "Total Tip Amount"
msgstr "Propinas"
msgctxt "field:sale_fast_food.reporting.zone,zone:"
msgid "Zone"
msgstr "Zona"
msgctxt "field:sale_fast_food.reporting.zone,table:"
msgid "Table"
msgstr "Mesa"
msgctxt "field:sale_fast_food.reporting.zone,completed_sales:"
msgid "Completed Sales"
msgstr "# Ventas"
msgctxt "field:sale_fast_food.reporting.zone,untaxed_amount:"
msgid "Untaxed Amount"
msgstr "Base Imponible"
msgctxt "field:sale_fast_food.reporting.zone,tax_amount:"
msgid "Tax Amount"
msgstr "Impuestos"
msgctxt "field:sale_fast_food.reporting.zone,total_amount:"
msgid "Total Amount"
msgstr "Total"
msgctxt "field:sale_fast_food.reporting.zone,total_tip_amount:"
msgid "Total Tip Amount"
msgstr "Propinas"
msgctxt "wizard_button:sale.print_cash_register,start,end:"
msgid "Cancel"
msgstr "Cancelar"
@@ -160,4 +68,4 @@ msgstr "Imprimir"
msgctxt "model:ir.action,name:wizard_print_cash_register"
msgid "Print cash register"
msgstr "Imprimir arqueo de caja"
msgstr "Imprimir arqueo de caja"

View File

@@ -1,6 +1,6 @@
from trytond.pool import PoolMeta
from trytond.pool import Pool, PoolMeta
from trytond.model import fields
from trytond.pyson import Eval
from trytond.pyson import Eval, Bool
class Product(metaclass=PoolMeta):

View File

@@ -4,14 +4,14 @@
<tryton>
<data>
<record model="ir.ui.view" id="product_view_tree">
<field name="model">product.template</field>
<field name="inherit" ref="product.template_view_tree"/>
<field name="name">product_tree</field>
<field name="model">product.template</field>
<field name="inherit" ref="product.template_view_tree"/>
<field name="name">product_tree</field>
</record>
<record model="ir.ui.view" id="product_view_form">
<field name="model">product.template</field>
<field name="inherit" ref="product.template_view_form"/>
<field name="name">product_form</field>
<field name="model">product.template</field>
<field name="inherit" ref="product.template_view_form"/>
<field name="name">product_form</field>
</record>
</data>
</tryton>

View File

@@ -1,22 +1,23 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
# from decimal import Decimal
from trytond.pool import PoolMeta
# from trytond.model import fields
from decimal import Decimal
from trytond.pool import Pool, PoolMeta
from trytond.model import fields
from trytond.modules.product import price_digits, round_price
from trytond.exceptions import UserError
BOM_CHANGES = ['bom', 'product', 'quantity', 'uom', 'warehouse', 'location',
'company', 'inputs', 'outputs']
class Production(metaclass=PoolMeta):
"Production"
__name__ = 'production'
"""
@fields.depends(
'bom', 'product', 'uom', 'quantity', 'company', 'inputs', 'outputs',
methods=['_explode_move_values'])
@fields.depends(*BOM_CHANGES)
def explode_bom(self):
pool = Pool()
Uom = pool.get('product.uom')
@@ -24,36 +25,38 @@ class Production(metaclass=PoolMeta):
return
factor = self.bom.compute_factor(self.product, self.quantity or 0,
self.uom)
self.uom)
inputs = []
for input_ in self.bom.inputs:
# if input_.product.producible:
# for input_ in input_.product.template.boms.inputs:
quantity = input_.compute_quantity(factor)
move = self._explode_move_values('input', input_, quantity)
if move:
inputs.append(move)
quantity = Uom.compute_qty(
input_.uom, quantity,
input_.product.default_uom, round=False)
# else:
# quantity = input_.compute_quantity(factor)
# move = self._explode_move_values('output', input_, quantity)
# if move:
# inputs.append(move)
# quantity = Uom.compute_qty(
# input_.uom, quantity,
# input_.product.default_uom, round=False)
if input_.product.producible:
for input_ in input_.product.template.boms.inputs:
quantity = input_.compute_quantity(factor)
move = self._explode_move_values(
self.picking_location, self.location, self.company,
input_, quantity)
if move:
inputs.append(move)
quantity = Uom.compute_qty(input_.uom, quantity,
input_.product.default_uom, round=False)
else:
quantity = input_.compute_quantity(factor)
move = self._explode_move_values(
self.picking_location, self.location, self.company,
input_, quantity)
if move:
inputs.append(move)
quantity = Uom.compute_qty(input_.uom, quantity,
input_.product.default_uom, round=False)
self.inputs = inputs
outputs = []
for output in self.bom.outputs:
quantity = output.compute_quantity(factor)
move = self._explode_move_values('output', output,
quantity)
move = self._explode_move_values(
self.location, self.output_location, self.company, output,
quantity)
if move:
move.unit_price = Decimal(0)
outputs.append(move)
self.outputs = outputs
"""

280
report.py
View File

@@ -1,280 +0,0 @@
from trytond.model import ModelSQL, ModelView, fields
from trytond.pool import Pool
from trytond.pyson import If, Eval
from sql import Literal, Null
from sql.aggregate import Min, Sum, Count
from sql.functions import CurrentTimestamp
from trytond.transaction import Transaction
import datetime
class ReportSaleContext(ModelView):
"""Contexto de reportes de miembros de familia"""
__name__ = 'sale_fast_food.report.context'
from_date = fields.Date(
"From Date",
domain=[
If(Eval('to_date') & Eval('from_date'),
('from_date', '<=', Eval('to_date')),
()),
If(Eval('from_date'),
('from_date', '<=', datetime.date.today()))
])
to_date = fields.Date(
"To Date",
domain=[
If(Eval('from_date') & Eval('to_date'),
('to_date', '>=', Eval('from_date')),
()),
If(Eval('to_date'),
('to_date', '<=', datetime.date.today()))
])
class ReportSaleAbstract(ModelSQL):
@classmethod
def table_query(cls):
from_item, tables = cls._joins()
final_query = from_item.select(
*cls._columns(tables),
where=cls._where(tables),
group_by=cls._group_by(tables)
)
return final_query
@classmethod
def _joins(cls):
pool = Pool()
tables = {}
Sale = pool.get('sale.sale')
tables['sale.sale'] = sale = Sale.__table__()
SaleLine = pool.get('sale.line')
tables['sale.line'] = sale_line = SaleLine.__table__()
ProductTemplate = pool.get('product.template')
tables[
'product.template'
] = product_template = ProductTemplate.__table__()
ProductProduct = pool.get('product.product')
tables['product.product'] = product = ProductProduct.__table__()
from_item = sale_line.left_join(
product,
condition=product.id == sale_line.product
).left_join(
product_template,
condition=product.template == product_template.id
).left_join(
sale,
condition=sale.id == sale_line.sale
)
return from_item, tables
@classmethod
def _columns(cls, tables):
columns = [
cls._column_id(tables).as_('id'),
Literal(0).as_('create_uid'),
CurrentTimestamp().as_('create_date'),
cls.write_uid.sql_cast(Literal(Null)).as_('write_uid'),
cls.write_date.sql_cast(Literal(Null)).as_('write_date'),
]
return columns
@classmethod
def _where(cls, tables):
context = Transaction().context
where = Literal(True)
from_date = context.get('from_date')
to_date = context.get('to_date')
sale = tables['sale.sale']
if from_date:
where &= sale.sale_date >= from_date
if to_date:
where &= sale.sale_date <= to_date
return where
@classmethod
def _group_by(cls, tables):
raise NotImplementedError()
@classmethod
def _column_id(cls, tables):
sale_line = tables['sale.line']
return Min(sale_line.id)
class ReportSaleProduct(ReportSaleAbstract, ModelView):
"""Report Sale Group by Product"""
__name__ = 'sale_fast_food.reporting.product'
product_pizza = fields.Many2One('product.product', "Product")
quantity = fields.Float("Quantity")
@classmethod
def _columns(cls, tables):
sale_line = tables['sale.line']
return super(ReportSaleProduct, cls)._columns(tables) + [
sale_line.product.as_('product_pizza'),
Sum(sale_line.quantity).as_('quantity')
]
@classmethod
def _group_by(cls, tables):
sale_line = tables['sale.line']
return [
sale_line.product
]
@classmethod
def _where(cls, tables):
where = super(ReportSaleProduct, cls)._where(tables)
product_template = tables['product.template']
where &= product_template.pizza == Literal(True)
return where
class ReportSaleByUser(ReportSaleAbstract, ModelView):
"""Report Sale Group by User"""
__name__ = 'sale_fast_food.reporting.by_user'
user = fields.Many2One('res.user', "User")
completed_sales = fields.Integer("Completed Sales")
untaxed_amount = fields.Numeric(
"Untaxed Amount", digits='currency', readonly=True)
tax_amount = fields.Numeric(
"Tax Amount", digits='currency', readonly=True)
total_amount = fields.Numeric(
"Total Amount", digits='currency', readonly=True)
total_tip_amount = fields.Numeric(
"Total Tip Amount", digits='currency', readonly=True)
currency = fields.Many2One(
'currency.currency', 'Currency', required=True)
@classmethod
def _joins(cls):
pool = Pool()
tables = {}
Sale = pool.get('sale.sale')
tables['sale.sale'] = sale = Sale.__table__()
from_item = sale
return from_item, tables
@classmethod
def _columns(cls, tables):
sale = tables['sale.sale']
return super(ReportSaleByUser, cls)._columns(tables) + [
sale.create_uid.as_('user'),
Count(Literal(1)).as_('completed_sales'),
Sum(sale.untaxed_amount_cache).as_('untaxed_amount'),
Sum(sale.tax_amount_cache).as_('tax_amount'),
Sum(sale.total_amount_cache).as_('total_amount'),
Sum(sale.total_tip_cache).as_('total_tip_amount'),
sale.currency.as_('currency'),
]
@classmethod
def _group_by(cls, tables):
sale = tables['sale.sale']
return [
sale.create_uid,
sale.currency
]
@classmethod
def _column_id(cls, tables):
sale = tables['sale.sale']
return Min(sale.id)
class ReportSaleByZone(ReportSaleAbstract, ModelView):
"""Report Sale Group by Zone"""
__name__ = 'sale_fast_food.reporting.zone'
zone = fields.Many2One('sale.zone', "Zone")
table = fields.Many2One('sale.table', "Table")
completed_sales = fields.Integer("Completed Sales")
untaxed_amount = fields.Numeric(
"Untaxed Amount", digits='currency', readonly=True)
tax_amount = fields.Numeric(
"Tax Amount", digits='currency', readonly=True)
total_amount = fields.Numeric(
"Total Amount", digits='currency', readonly=True)
total_tip_amount = fields.Numeric(
"Total Tip Amount", digits='currency', readonly=True)
currency = fields.Many2One(
'currency.currency', 'Currency', required=True)
@classmethod
def _joins(cls):
pool = Pool()
tables = {}
Sale = pool.get('sale.sale')
tables['sale.sale'] = sale = Sale.__table__()
Table = pool.get('sale.table')
tables['sale.table'] = table = Table.__table__()
Zone = pool.get('sale.zone')
tables['sale.table'] = zone = Zone.__table__()
from_item = sale.left_join(
table,
condition=table.id == sale.table
).left_join(
zone,
condition=zone.id == table.zone
)
return from_item, tables
@classmethod
def _columns(cls, tables):
sale = tables['sale.sale']
return super(ReportSaleByZone, cls)._columns(tables) + [
sale.zone.as_('zone'),
sale.table.as_('table'),
Count(Literal(1)).as_('completed_sales'),
Sum(sale.untaxed_amount_cache).as_('untaxed_amount'),
Sum(sale.tax_amount_cache).as_('tax_amount'),
Sum(sale.total_amount_cache).as_('total_amount'),
Sum(sale.total_tip_cache).as_('total_tip_amount'),
sale.currency.as_('currency'),
]
@classmethod
def _group_by(cls, tables):
sale = tables['sale.sale']
return [
sale.zone,
sale.table,
sale.currency
]
@classmethod
def _column_id(cls, tables):
sale = tables['sale.sale']
return Min(sale.id)

View File

@@ -1,103 +0,0 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="sale_fast_food_report_view_form">
<field name="model">sale_fast_food.report.context</field>
<field name="type">form</field>
<field name="name">sale_fast_food_report_context_form</field>
</record>
<!-- Report by Product-->
<record model="ir.ui.view" id="report_sale_fast_food_product_pizza_view_list">
<field name="model">sale_fast_food.reporting.product</field>
<field name="type">tree</field>
<field name="name">pizzas_sold_by_product_list</field>
</record>
<record model="ir.action.act_window" id="act_report_sale_fast_food_product_pizza">
<field name="name">Pizzas Sold by Product</field>
<field name="res_model">sale_fast_food.reporting.product</field>
<field name="context_model">sale_fast_food.report.context</field>
</record>
<record model="ir.action.act_window.view" id="act_report_sale_fast_food_product_pizza_view1">
<field name="sequence" eval="10"/>
<field name="view" ref="report_sale_fast_food_product_pizza_view_list"/>
<field name="act_window" ref="act_report_sale_fast_food_product_pizza"/>
</record>
<!-- Report by Product-->
<record model="ir.ui.view" id="report_sale_fast_food_by_user_view_list">
<field name="model">sale_fast_food.reporting.by_user</field>
<field name="type">tree</field>
<field name="name">sales_by_user_list</field>
</record>
<record model="ir.action.act_window" id="act_report_sale_fast_food_by_user">
<field name="name">Sales by User</field>
<field name="res_model">sale_fast_food.reporting.by_user</field>
<field name="context_model">sale_fast_food.report.context</field>
</record>
<record model="ir.action.act_window.view" id="act_report_sale_fast_food_by_user_view1">
<field name="sequence" eval="20"/>
<field name="view" ref="report_sale_fast_food_by_user_view_list"/>
<field name="act_window" ref="act_report_sale_fast_food_by_user"/>
</record>
<!-- Report by Zone-->
<record model="ir.ui.view" id="report_sale_fast_food_zone_view_list">
<field name="model">sale_fast_food.reporting.zone</field>
<field name="type">tree</field>
<field name="name">sales_by_zone_list</field>
</record>
<record model="ir.action.act_window" id="act_report_sale_fast_food_zone">
<field name="name">Sales by Zone</field>
<field name="res_model">sale_fast_food.reporting.zone</field>
<field name="context_model">sale_fast_food.report.context</field>
</record>
<record model="ir.action.act_window.view" id="act_report_sale_fast_food_zone_view1">
<field name="sequence" eval="20"/>
<field name="view" ref="report_sale_fast_food_zone_view_list"/>
<field name="act_window" ref="act_report_sale_fast_food_zone"/>
</record>
<menuitem
name="Pizzas Sold by Product"
parent="sale.menu_reporting"
sequence="10"
id="menu_sale_fast_food_pizza"
icon="tryton-graph"/>
<menuitem
name="Sales by User"
parent="sale.menu_reporting"
sequence="20"
id="menu_sale_fast_food_by_user"
icon="tryton-graph"/>
<menuitem
name="Sales by Zone"
parent="sale.menu_reporting"
sequence="30"
id="menu_sale_fast_food_zone"
icon="tryton-graph"/>
<record model="ir.action.keyword" id="act_report_sale_fast_food_product_pizza_keyword1">
<field name="keyword">tree_open</field>
<field name="model" ref="menu_sale_fast_food_pizza"/>
<field name="action" ref="act_report_sale_fast_food_product_pizza"/>
</record>
<record model="ir.action.keyword" id="act_report_sale_fast_food_by_user_keyword1">
<field name="keyword">tree_open</field>
<field name="model" ref="menu_sale_fast_food_by_user"/>
<field name="action" ref="act_report_sale_fast_food_by_user"/>
</record>
<record model="ir.action.keyword" id="act_report_sale_fast_food_zone_keyword1">
<field name="keyword">tree_open</field>
<field name="model" ref="menu_sale_fast_food_zone"/>
<field name="action" ref="act_report_sale_fast_food_zone"/>
</record>
</data>
</tryton>

View File

@@ -43,11 +43,10 @@ class ReportCloseStatementStart(ModelView):
@classmethod
def default_shop(cls):
context = Transaction().context
if context:
shop = context['shop']
if shop:
return shop
return
shop = context['shop']
if shop:
return shop
class PrintReportCloseStatement(Wizard):
@@ -109,10 +108,10 @@ class CashRegister(Report):
return
journals = [j.id for j in device.journals]
statements = Statement.search([
('journal', 'in', journals),
('state', 'in', ['validated', 'posted']),
('date', '=', date)
])
('journal', 'in', journals),
('state', 'in', ['validated', 'posted']),
('date', '=', date)
])
return statements
def _get_invoices_by_subtype(date, shop):
@@ -174,7 +173,7 @@ class CashRegister(Report):
amount_tips.append(info_pizzas_sold['amount_tip'])
total_amount += sale.total_amount
untaxed_amount_for_tax = round((tax_amount * 100) / Decimal('8.0'), 2)
untaxed_amount_for_tax = round((tax_amount * 100)/Decimal('8.0'), 2)
statements = cls._get_statements_by_date(data['date'])
if statements:
@@ -185,7 +184,7 @@ class CashRegister(Report):
'total_amount': sum(
(line.amount for line in statement.lines
if line.description), Decimal(0))
} for statement in statements]
} for statement in statements]
report_context['total_statements'] = sum(
[s['total_amount'] for s in report_context['statements']])

View File

@@ -5,6 +5,7 @@ this repository contains the full copyright notices and license terms. -->
<data>
<record model="ir.action.report" id="report_close_statement">
<field name="name">Close statement</field>
<field name="model"></field>
<field name="report_name">sale.cash_register</field>
<field name="report">sale_fast_food/report/close_statement.fodt</field>
<field name="template_extension">odt</field>
@@ -24,4 +25,4 @@ this repository contains the full copyright notices and license terms. -->
id="menu_print_cash_register"
icon="tryton-print"/>
</data>
</tryton>
</tryton>

193
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
@@ -13,19 +14,17 @@ class Sale(metaclass=PoolMeta):
__name__ = 'sale.sale'
pizza_number = fields.Integer("Number pizza")
credito = fields.Boolean("Credito")
total_discount = fields.Function(
Monetary(
"Total Discount", digits='currency', currency='currency'),
'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'),
Monetary(
"Total Tip", digits='currency', currency='currency'),
'get_amount')
total_tip_cache = fields.Numeric(
"Total Tip cache", digits="currency")
total_tip_cache = fields.Numeric("Total Tip cache", digits="currency")
@classmethod
def __setup__(cls):
@@ -102,18 +101,13 @@ class Sale(metaclass=PoolMeta):
else:
untaxed_amount[sale.id] = round(sum(
(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(
(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)
(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] = (
@@ -124,7 +118,7 @@ class Sale(metaclass=PoolMeta):
'tax_amount': tax_amount,
'total_amount': total_amount,
'total_discount': total_discount,
'total_tip': total_tip
'total_tip' : total_tip
}
for key in list(result.keys()):
if key not in names:
@@ -147,6 +141,10 @@ class Sale(metaclass=PoolMeta):
@classmethod
def get_invoice(cls, record):
pool = Pool()
ctx = Transaction().context
Shop = pool.get('sale.shop')
shop = Shop.search([('id', '=', ctx["shop"])])[0]
if record.state != 'draft' and record.invoices:
invoice = record.invoices[0]
data = {}
@@ -168,11 +166,8 @@ class Sale(metaclass=PoolMeta):
data = {}
shop = Shop.search([('id', '=', ctx["shop"])])[0]
data["shop_name"] = shop.name
data["shop_nit"] = shop.company.party.tax_identifier.code
data["shop_address"] = shop.address.street
data['invoice'] = cls.get_invoice(record)
data['fe_cufe'] = record.fe_qrcode
data['cufe'] = record.fe_cufe
data["party"] = record.party.name
data["tax_identifier_type"] = record.party.tax_identifier.type_string
data["tax_identifier_code"] = record.party.tax_identifier.code
@@ -185,19 +180,17 @@ class Sale(metaclass=PoolMeta):
"product": line.product.name if line.type != 'title' else None,
"quantity": line.quantity if line.type != 'title' else None,
"uom": line.unit.symbol 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)) + '%'
"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["total_discount"] = str(round(record.total_discount,2))
data["untaxed_amount"] = str(record.untaxed_amount)
data["tax_amount"] = str(record.tax_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"
data["state"] = "SUBTOTAL" if record.state == "draft" else "CUENTA FINAL"
if record.payments:
data['payments'] = [{
@@ -219,18 +212,20 @@ class Sale(metaclass=PoolMeta):
data["city"] = report.invoice_address.subdivision_municipality.name
data["zone"] = report.zone.name if report.zone else ""
data["table"] = report.table.name if report.table else ""
# data["lines"] = [{
# 'type': line.type,
# "product": line.product.name if line.type != 'title' else None,
# "quantity": line.quantity if line.type != 'title' else None,
# "uom": line.unit.name if line.type != 'title' else None}
# for line in report.lines]
data["lines"] = [{
"type": line.type,
"product": line.product.name if line.type != "title" else None,
"description": line.description if line.type != "title" else None,
"quantity": line.quantity if line.type != "title" else None,
"uom": line.unit.name if line.type != "title" else None}
for line in report.lines if not line.impreso]
data["deleted_lines"] = [{
"product": line.product.name,
"quantity": str(-1 * line.quantity),
"unit": line.unit.symbol
} for line in report.delete_lines if not line.printed]
'type': line.type,
"product": line.product.name if line.type != 'title' else None,
"description": line.description if line.type != 'title' else None,
"quantity": line.quantity if line.type != 'title' else None,
"uom": line.unit.name if line.type != 'title' else None}
for line in report.lines if not line.impreso]
return data
@@ -253,10 +248,6 @@ class Sale(metaclass=PoolMeta):
line.analytic_accounts = tuple()
line.impreso = True
line.save()
for line in record.delete_lines:
line.printed = True
line.save()
record.save()
@classmethod
@@ -280,28 +271,13 @@ class Sale(metaclass=PoolMeta):
user_name = context['employee.rec_name']
else:
user_name = ""
content = {
"content": str(json.dumps(bill)),
"printer_type": "",
"ip_printer": "",
"user_name": user_name,
"idVendor": "",
"idProduct": ""}
if printer.type_ == 'network':
content["printer_type"] = "Network"
content["ip_printer"] = str(printer.ip_address)
else:
if printer.type_ == 'usb':
content["printer_type"] = "USB"
content["idVendor"] = str(printer.idVendor)
content["idProduct"] = str(printer.idProduct)
content = {"content": str(json.dumps(bill)),
"ip_printer": str(printer.ip_address),
"user_name": user_name}
headers = {"accept": 'application/json',
'Content-Type': 'application/json'}
requests.post(
url, data=json.dumps(content), headers=headers, timeout=5)
response = requests.post(url, data=json.dumps(content), headers=headers)
@classmethod
@ModelView.button
@@ -324,30 +300,14 @@ class Sale(metaclass=PoolMeta):
user_name = context['employee.rec_name']
else:
user_name = ""
content = {"content": str(json.dumps(customer_order)),
"printer_type": "",
"ip_printer": "",
"user_name": user_name,
"idVendor": "",
"idProduct": ""}
if printer.type_ == 'network':
content["printer_type"] = "Network"
content["ip_printer"] = str(printer.ip_address)
else:
if printer.type_ == 'usb':
content["printer_type"] = "USB"
content["idVendor"] = str(printer.idVendor)
content["idProduct"] = str(printer.idProduct)
"ip_printer": str(printer.ip_address),
"user_name": user_name}
headers = {"accept": 'application/json',
'Content-Type': 'application/json'}
cls.impreso([record])
requests.post(
url, data=str(json.dumps(content)),
headers=headers)
response = requests.post(url, data=json.dumps(content),
headers=headers)
@classmethod
@ModelView.button
@@ -367,34 +327,17 @@ class Sale(metaclass=PoolMeta):
url = f"http://{printer.api.ip_address}/order_bar"
customer_order = cls.report_customer_order(records)
cls.impreso([record])
if 'employee.rec_name' in context.keys():
user_name = context['employee.rec_name']
else:
user_name = ""
content = {
"content": str(json.dumps(customer_order)),
"printer_type": "",
"ip_printer": "",
"user_name": user_name,
"idVendor": "",
"idProduct": ""}
if printer.type_ == 'network':
content["printer_type"] = "Network"
content["ip_printer"] = str(printer.ip_address)
else:
if printer.type_ == 'usb':
content["printer_type"] = "USB"
content["idVendor"] = str(printer.idVendor)
content["idProduct"] = str(printer.idProduct)
headers = {
"accept": 'application/json',
'Content-Type': 'application/json'}
requests.post(url, data=json.dumps(content),
headers=headers)
content = {"content": str(json.dumps(customer_order)),
"ip_printer": str(printer.ip_address),
"user_name": user_name}
headers = {"accept": 'application/json',
'Content-Type': 'application/json'}
response = requests.post(url, data=json.dumps(content),
headers=headers)
class Line(metaclass=PoolMeta):
@@ -404,38 +347,38 @@ 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 delete(cls, lines):
for line in lines:
if line.impreso and line.type == 'line':
cls._create_sale_line_deleted_log(line)
super(Line, cls).delete(lines)
def default_rate(cls):
return 0
@fields.depends('product', 'unit', 'sale',
'_parent_sale.party', '_parent_sale.invoice_party',
'_parent_sale.pizza_number',
'_parent_product.template',
'_parent_product._parent_template.pizza',
methods=['compute_taxes', 'compute_unit_price',
'on_change_with_amount'])
def on_change_product(self):
super(Line, self).on_change_product()
if self.product and self.product.template.pizza:
if self.product and self.product.pizza:
self.pizza = self.sale.pizza_number
self.bought_pizza = True
else:
self.bought_pizza = False
def get_production(self, product_quantities):
def get_production(self):
"Return production for the sale line"
Production = super(Line, self).get_production(product_quantities)
Production = super(Line, self).get_production()
return Production
class SaleLineDeletedLog(metaclass=PoolMeta):
"""Sale Line Deleted Log"""
__name__ = 'sale.line_deleted'
printed = fields.Boolean("Printed")
@fields.depends('discount_rate')
def on_change_discount_rate(self):
if self.discount_rate:
self.rate = self.discount_rate

104
sale.xml
View File

@@ -2,57 +2,55 @@
<!--This file file is part of Tryton. The COPYRIGHT file at the top level
of this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="sale_view_tree">
<field name="model">sale.sale</field>
<field name="inherit" ref="sale.sale_view_tree"/>
<field name="name">sale_tree</field>
</record>
<record model="ir.ui.view" id="sale_view_form">
<field name="model">sale.sale</field>
<field name="inherit" ref="sale.sale_view_form"/>
<field name="name">sale_form</field>
</record>
<record model="ir.ui.view" id="sale_line_view_form">
<field name="model">sale.line</field>
<field name="inherit" ref="sale.sale_line_view_form"/>
<field name="name">sale_line_form</field>
</record>
<record model="ir.model.button" id="sale_add_pizza_button">
<field name="name">add_pizza</field>
<field name="string">Add Pizza</field>
<field name="model">sale.sale</field>
</record>
<record model="ir.model.button" id="sale_order_kitchen_button">
<field name="name">kitchen</field>
<field name="string">Kitchen</field>
<field name="model">sale.sale</field>
</record>
<record model="ir.model.button" id="sale_order_bar_button">
<field name="name">bar</field>
<field name="string">Bar</field>
<field name="model">sale.sale</field>
</record>
<record model="ir.model.button" id="sale_print_bill_button">
<field name="name">print_bill</field>
<field name="string">Bill</field>
<field name="model">sale.sale</field>
</record>
<record model="ir.model.button" id="sale_impreso_button">
<field name="name">impreso</field>
<field name="string">Impreso</field>
<field name="model">sale.sale</field>
</record>
<record model="ir.action.report" id="report_customer_order">
<field name="name">Customer Order</field>
<field name="model">sale.sale</field>
<field name="report_name">sale.customer_order</field>
<field name="report">sale_fast_food/report/customer_order.fodt</field>
</record>
<record model="ir.action.keyword" id="report_customer_order_keyword">
<field name="keyword">form_print</field>
<field name="model">sale.sale,-1</field>
<field name="action" ref="report_customer_order"/>
</record>
</data>
<record model="ir.ui.view" id="sale_view_tree">
<field name="model">sale.sale</field>
<field name="inherit" ref="sale.sale_view_tree"/>
<field name="name">sale_tree</field>
</record>
<record model="ir.ui.view" id="sale_view_form">
<field name="model">sale.sale</field>
<field name="inherit" ref="sale.sale_view_form"/>
<field name="name">sale_form</field>
</record>
<record model="ir.ui.view" id="sale_line_view_form">
<field name="model">sale.line</field>
<field name="inherit" ref="sale.sale_line_view_form"/>
<field name="name">sale_line_form</field>
</record>
<record model="ir.model.button" id="sale_add_pizza_button">
<field name="name">add_pizza</field>
<field name="string">Add Pizza</field>
<field name="model" search="[('model', '=', 'sale.sale')]"/>
</record>
<record model="ir.model.button" id="sale_order_kitchen_button">
<field name="name">kitchen</field>
<field name="string">Kitchen</field>
<field name="model" search="[('model', '=', 'sale.sale')]"/>
</record>
<record model="ir.model.button" id="sale_order_bar_button">
<field name="name">bar</field>
<field name="string">Bar</field>
<field name="model" search="[('model', '=', 'sale.sale')]"/>
</record>
<record model="ir.model.button" id="sale_print_bill_button">
<field name="name">print_bill</field>
<field name="string">Bill</field>
<field name="model" search="[('model', '=', 'sale.sale')]"/>
</record>
<record model="ir.model.button" id="sale_impreso_button">
<field name="name">impreso</field>
<field name="string">Impreso</field>
<field name="model" search="[('model', '=', 'sale.sale')]"/>
</record>
<record model="ir.action.report" id="report_customer_order">
<field name="name">Customer Order</field>
<field name="model">sale.sale</field>
<field name="report_name">sale.customer_order</field>
<field name="report">sale_fast_food/report/customer_order.fodt</field>
</record>
<record model="ir.action.keyword" id="report_customer_order_keyword">
<field name="keyword">form_print</field>
<field name="model">sale.sale,-1</field>
<field name="action" ref="report_customer_order"/>
</record>
</tryton>

View File

@@ -127,7 +127,7 @@ setup(name=name,
],
license='GPL-3',
python_requires='>=3.7',
# install_requires=requires,
install_requires=requires,
extras_require={
'test': tests_require,
},

View File

@@ -1,8 +0,0 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.tests.test_tryton import load_doc_tests
def load_tests(*args, **kwargs):
return load_doc_tests(__name__, __file__, *args, **kwargs)

View File

@@ -1,21 +1,17 @@
[tryton]
version=7.6.0
version=6.4
depends:
ir
res
product
sale
sale_discount
sale_supply_production
sale_line_delete_log
sale_printer
#sale_printer
production
account_invoice
sale_shop
sale_pos_table
xml:
product.xml
sale.xml
user.xml
report_close_statement.xml
report.xml
report_close_statement.xml

View File

@@ -1,10 +1,8 @@
from trytond.model import fields
from trytond.pool import PoolMeta
from trytond.pool import Pool, PoolMeta
class User(metaclass=PoolMeta):
"User"
__name__ = 'res.user'
waiter = fields.Boolean('Waiter')
not_restaurant = fields.Boolean('Not Restaurant')

View File

@@ -1,7 +0,0 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="product_pizza"/>
<field name="quantity" sum="1"/>
</tree>

View File

@@ -2,22 +2,19 @@
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="//field[@name='salable']" position="after">
<label name="pizza"/>
<field name="pizza"/>
<label name="pizza_topping"/>
<field name="pizza_topping"/>
<label name="tip"/>
<field name="tip"/>
<label name="kitchen"/>
<field name="kitchen"/>
<label name="bar"/>
<field name="bar"/>
</xpath>
<xpath expr="//field[@name='default_uom']" position="after">
<group id="boms">
<label name="boms"/>
<field name="boms"/>
</group>
</xpath>
<xpath expr="//field[@name='salable']" position="after">
<label name="pizza"/>
<field name="pizza"/>
<label name="pizza_topping"/>
<field name="pizza_topping"/>
<label name="tip"/>
<field name="tip"/>
<label name="kitchen"/>
<field name="kitchen"/>
<label name="bar"/>
<field name="bar"/>
<newline/>
<label name="boms"/>
<field name="boms" xexpand="1"/>
</xpath>
</data>

View File

@@ -1,11 +0,0 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<form>
<label name="from_date"/>
<group id="dates" col="-1">
<field name="from_date"/>
<label name="to_date"/>
<field name="to_date"/>
</group>
</form>

View File

@@ -12,16 +12,11 @@ this repository contains the full copyright notices and license terms. -->
</group>
<newline/>
</xpath>
<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"/>
<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>
<xpath expr="/form/notebook/page[@id='sale']/group[@id='amount']/field[@name='total_amount']"
position="after">
<label name="credito"/>
<field name="credito"/>
</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>

View File

@@ -3,10 +3,10 @@
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="//field[@name='shop']" position="after">
<field name="zone" string="Zona"/>
<field name="table" string="Mesa"/>
<field name="zone" string="Zona"/>
<field name="table" string="Mesa"/>
</xpath>
<xpath expr="//field[@name='untaxed_amount']" position="after">
<field name="total_amount"/>
<field name="total_amount"/>
</xpath>
</data>

View File

@@ -1,11 +0,0 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="user"/>
<field name="completed_sales" sum="1"/>
<field name="untaxed_amount" sum="1"/>
<field name="tax_amount" sum="1"/>
<field name="total_amount" sum="1"/>
<field name="total_tip_amount" sum="1"/>
</tree>

View File

@@ -1,12 +0,0 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="zone"/>
<field name="table"/>
<field name="completed_sales" sum="1"/>
<field name="untaxed_amount" sum="1"/>
<field name="tax_amount" sum="1"/>
<field name="total_amount" sum="1"/>
<field name="total_tip_amount" sum="1"/>
</tree>

View File

@@ -5,7 +5,5 @@
<xpath expr="//field[@name='name']" position="after">
<label name="waiter"/>
<field name="waiter"/>
<label name="not_restaurant"/>
<field name="not_restaurant"/>
</xpath>
</data>