fix print report invoice or sale

This commit is contained in:
Wilson Gomez 2023-05-25 16:01:50 -05:00
parent 6f140bc525
commit 693f32f13b
3 changed files with 68 additions and 17 deletions

View File

@ -368,9 +368,16 @@ class FrontWindow(QMainWindow):
self._password_admin = self._config.get('password_admin_pos')
self._password_force_assign = self._config.get('password_force_assign')
self._action_report, = self.ActionReport.find([
self._action_report_invoice, = self.ActionReport.find([
('report_name', '=', 'account.invoice'),
])
self._action_report_invoice_e, = self.ActionReport.find([
('report_name', '=', 'electronic_invoice_co.invoice_face'),
])
self._action_report_sale = self.ActionReport.find([
('report_name', '=', 'sale.sale'),
])
if self._config['show_stock_pos'] in ('value', 'icon'):
self.stock_context = {
'stock_date_end': date.today().strftime("%Y-%m-%d"),

View File

@ -28,6 +28,7 @@ from app.commons.model import TableModel
from app.commons.menu_buttons import MenuDash
from .localdb import LocalDB
from .reporting import Receipt
from .proxy import Report
from .buttonpad import ButtonsStacked, ButtonsFunction, StartButtons
from .states import STATES, RE_SIGN
from .commons.custom_button import CustomButton
@ -1540,23 +1541,64 @@ class AppWindow(FrontWindow):
if printer_id == '1':
self.print_invoice(sale_id, type_doc=type_doc)
else:
self.print_odt_invoice(sale)
self.print_odt_report(sale, type_doc)
def print_odt_invoice(self, sale):
if not sale.get('invoices'):
return
invoice_id = sale['invoices'][0]
model = u'account.invoice'
data = {
'model': model,
'action_id': self._action_report['id'],
'id': invoice_id,
'ids': [invoice_id],
}
ctx = {'date_format': u'%d/%m/%Y'}
ctx.update(self.ctx)
Action.exec_report(self.conn, u'account.invoice',
data, direct_print=True, context=ctx)
def print_odt_report(self, sale, type_doc):
if type_doc == 'order':
model = 'sale.sale'
sale_id = sale['id']
action_id = self._action_report_sale[-1]['id']
data = {
'model': model,
'action_id': action_id,
}
ctx = {'date_format': '%d/%m/%Y'}
ctx.update(self.ctx)
report = Report(ctx)
values = {
'report_name': model,
'args': data,
'record': sale_id,
'records': [sale_id],
}
oext, content, direct_print, file_name = report.get(values)
result = {
'oext': oext,
'content': content,
'direct_print': direct_print,
'name': file_name,
}
report.open(result)
elif type_doc == 'invoice':
if not sale.get('invoices'):
return
invoice_id = sale['invoices'][0]
model = 'account.invoice'
action_id = self._action_report_invoice['id']
if sale['invoice_type'] == '1':
action_id = self._action_report_invoice_e['id']
data = {
'model': model,
'action_id': action_id,
}
ctx = {'date_format': u'%d/%m/%Y'}
ctx.update(self.ctx)
report = Report(ctx)
values = {
'report_name': model,
'args': data,
'record': invoice_id,
'records': [invoice_id],
}
oext, content, direct_print, file_name = report.get(values)
result = {
'oext': oext,
'content': content,
'direct_print': direct_print,
'name': file_name,
}
report.open(result)
def action_comment(self):
self.dialog_comment.exec_()

View File

@ -259,6 +259,8 @@ class Report(object):
args_ = {
'report': values['report_name'],
'data': values['args'],
'records': values['records'],
'record': values['record'],
'context': self.ctx,
}
res = self.get_connection('POST', '/report', args_)