fix: clean home
This commit is contained in:
parent
4e0c39fd78
commit
b737a14857
95
sale.py
95
sale.py
@ -1,11 +1,11 @@
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.model import ModelView, fields
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.exceptions import UserError
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
|
||||
class Sale(metaclass=PoolMeta):
|
||||
"Sale Fast Food"
|
||||
__name__ = 'sale.sale'
|
||||
@ -23,7 +23,6 @@ class Sale(metaclass=PoolMeta):
|
||||
'impreso': {},
|
||||
})
|
||||
|
||||
|
||||
@classmethod
|
||||
def default_pizza_number(cls):
|
||||
return 0
|
||||
@ -32,7 +31,8 @@ class Sale(metaclass=PoolMeta):
|
||||
if subtype:
|
||||
resolution = subtype.sequence.invoice_resolution
|
||||
if resolution:
|
||||
return dict([('resolution_number', resolution.resolution_number),
|
||||
return dict([
|
||||
('resolution_number', resolution.resolution_number),
|
||||
('resolution_prefix', resolution.prefix),
|
||||
('valid_date_time_from', str(resolution.valid_date_time_from)),
|
||||
('valid_date_time_to', str(resolution.valid_date_time_to)),
|
||||
@ -50,7 +50,6 @@ class Sale(metaclass=PoolMeta):
|
||||
data = {}
|
||||
data['invoice_number'] = invoice.number
|
||||
subtype = invoice.subtype
|
||||
#raise UserError(str(subtype))
|
||||
data['resolution'] = cls.get_invoice_resolution(subtype)
|
||||
|
||||
return data
|
||||
@ -63,14 +62,11 @@ class Sale(metaclass=PoolMeta):
|
||||
pool = Pool()
|
||||
ctx = Transaction().context
|
||||
record = records[0]
|
||||
User = pool.get('res.user')
|
||||
Shop = pool.get('sale.shop')
|
||||
data = {}
|
||||
user = User(Transaction().user)
|
||||
shop = Shop.search([('id', '=', ctx["shop"])])[0]
|
||||
data["shop_name"] = shop.name
|
||||
data["shop_address"] = shop.address.street
|
||||
#data["user"] = user.name
|
||||
data['invoice'] = cls.get_invoice(record)
|
||||
data["party"] = record.party.name
|
||||
data["tax_identifier_type"] = record.party.tax_identifier.type_string
|
||||
@ -79,12 +75,14 @@ class Sale(metaclass=PoolMeta):
|
||||
data["city"] = record.invoice_address.subdivision_municipality.name
|
||||
data["zone"] = record.zone.name if record.zone else ""
|
||||
data["table"] = record.table.name if record.table else ""
|
||||
data["lines"] = [{'type': line.type,
|
||||
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.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))+'%' if line.type != 'title' and line.taxes 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]
|
||||
|
||||
data["untaxed_amount"] = str(record.untaxed_amount)
|
||||
@ -92,7 +90,8 @@ class Sale(metaclass=PoolMeta):
|
||||
data["total"] = str(record.total_amount)
|
||||
|
||||
if record.payments:
|
||||
data['payments'] = [{"statement": payment.statement.journal.name,
|
||||
data['payments'] = [{
|
||||
"statement": payment.statement.journal.name,
|
||||
"amount": str(payment.amount)} for payment in record.payments]
|
||||
|
||||
return data
|
||||
@ -101,14 +100,8 @@ class Sale(metaclass=PoolMeta):
|
||||
if not records:
|
||||
return
|
||||
|
||||
pool = Pool()
|
||||
ctx = Transaction().context
|
||||
report = records[0]
|
||||
User = pool.get('res.user')
|
||||
data = {}
|
||||
user = User(Transaction().user)
|
||||
#raise UserError(str(Transaction().user))
|
||||
#data["user"] = user.name
|
||||
data["party"] = report.party.name
|
||||
data["tax_identifier_type"] = report.party.tax_identifier.type_string
|
||||
data["tax_identifier_code"] = report.party.tax_identifier.code
|
||||
@ -116,26 +109,29 @@ 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,
|
||||
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]
|
||||
"uom": line.unit.name if line.type != 'title' else None}
|
||||
for line in report.lines]
|
||||
|
||||
data["lines"] = [{'type': line.type,
|
||||
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 if line.impreso == False]
|
||||
"uom": line.unit.name if line.type != 'title' else None}
|
||||
for line in report.lines if not line.impreso]
|
||||
|
||||
return data
|
||||
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
def add_pizza(cls, records):
|
||||
pool = Pool()
|
||||
saleLine = pool.get('sale.line')
|
||||
for record in records:
|
||||
record.pizza_number +=1
|
||||
record.pizza_number += 1
|
||||
record.lines += (saleLine(type="title",
|
||||
description="Pizza Combinada"),)
|
||||
record.save()
|
||||
@ -145,7 +141,7 @@ class Sale(metaclass=PoolMeta):
|
||||
def impreso(cls, records):
|
||||
record = records[0]
|
||||
for line in record.lines:
|
||||
#line.analytic_accounts = tuple()
|
||||
line.analytic_accounts = tuple()
|
||||
line.impreso = True
|
||||
line.save()
|
||||
record.save()
|
||||
@ -157,17 +153,22 @@ class Sale(metaclass=PoolMeta):
|
||||
context = Transaction().context
|
||||
shop = context['shop']
|
||||
Printer = pool.get('sale.printer')
|
||||
printers = Printer.search([('zone', '=', 'reception'), ('shop', '=', shop)])
|
||||
printers = Printer.search([
|
||||
('zone', '=', 'reception'),
|
||||
('shop', '=', shop)])
|
||||
if not printers:
|
||||
return
|
||||
|
||||
printer = printers[0]
|
||||
|
||||
url = f"http://{printer.api.ip_address}/print_bill"
|
||||
|
||||
bill = cls.report_bill(records)
|
||||
content = {"content": str(json.dumps(bill)), "ip_printer": str(printer.ip_address)}
|
||||
headers = {"accept": 'application/json', 'Content-Type': 'application/json'}
|
||||
user_name = context['employee.rec_name']
|
||||
content = {"content": str(json.dumps(bill)),
|
||||
"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)
|
||||
|
||||
@ -178,24 +179,25 @@ class Sale(metaclass=PoolMeta):
|
||||
context = Transaction().context
|
||||
shop = context['shop']
|
||||
Printer = pool.get('sale.printer')
|
||||
printers = Printer.search([('zone', '=', 'kitchen'), ('shop', '=', shop)])
|
||||
printers = Printer.search([('zone', '=', 'kitchen'),
|
||||
('shop', '=', shop)])
|
||||
record = records[0]
|
||||
#raise UserError(str(printers))
|
||||
if not printers:
|
||||
return
|
||||
|
||||
printer = printers[0]
|
||||
|
||||
url = f"http://{printer.api.ip_address}/order_kitchen"
|
||||
|
||||
customer_order = cls.report_customer_order(records)
|
||||
content = {"content": str(json.dumps(customer_order)), "ip_printer": str(printer.ip_address)}
|
||||
headers = {"accept": 'application/json', 'Content-Type': 'application/json'}
|
||||
user_name = context['employee.rec_name']
|
||||
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'}
|
||||
cls.impreso([record])
|
||||
|
||||
response = requests.post(url, data=json.dumps(content), headers=headers)
|
||||
|
||||
#return response.status_code
|
||||
response = requests.post(url, data=json.dumps(content),
|
||||
headers=headers)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@ -204,7 +206,8 @@ class Sale(metaclass=PoolMeta):
|
||||
context = Transaction().context
|
||||
shop = context['shop']
|
||||
Printer = pool.get('sale.printer')
|
||||
printers = Printer.search([('zone', '=', 'bar'), ('shop', '=', shop)])
|
||||
printers = Printer.search([('zone', '=', 'bar'),
|
||||
('shop', '=', shop)])
|
||||
record = records[0]
|
||||
|
||||
if not printers:
|
||||
@ -212,17 +215,16 @@ class Sale(metaclass=PoolMeta):
|
||||
|
||||
printer = printers[0]
|
||||
url = f"http://{printer.api.ip_address}/order_bar"
|
||||
|
||||
customer_order = cls.report_customer_order(records)
|
||||
cls.impreso([record])
|
||||
|
||||
#cls.impreso(records)
|
||||
|
||||
content = {"content": str(json.dumps(customer_order)), "ip_printer": str(printer.ip_address)}
|
||||
headers = {"accept": 'application/json', 'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url, data=json.dumps(content), headers=headers)
|
||||
|
||||
user_name = context['employee.rec_name']
|
||||
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):
|
||||
@ -245,6 +247,5 @@ class Line(metaclass=PoolMeta):
|
||||
def get_production(self):
|
||||
"Return production for the sale line"
|
||||
Production = super(Line, self).get_production()
|
||||
#Production.bom = self.product.template.boms.id
|
||||
|
||||
return Production
|
||||
|
Loading…
Reference in New Issue
Block a user