Browse Source

[FIX] differed the send of the ticket, since it can cause crash and wkhtmltopdf deadlock, clicking on the button in the pos just tell the system to print the ticket later

pull/26/merge
Thibault Francois 7 years ago
parent
commit
136411b71e
  1. 3
      beesdoo_pos/__openerp__.py
  2. 14
      beesdoo_pos/data/cron.xml
  3. 26
      beesdoo_pos/models/beesdoo_pos.py

3
beesdoo_pos/__openerp__.py

@ -26,7 +26,8 @@
'data': [ 'data': [
'security/ir.model.access.csv', 'security/ir.model.access.csv',
'views/beesdoo_pos.xml', 'views/beesdoo_pos.xml',
'data/email.xml'
'data/email.xml',
'data/cron.xml',
], ],
'qweb': ['static/src/xml/templates.xml'], 'qweb': ['static/src/xml/templates.xml'],
# only loaded in demonstration mode # only loaded in demonstration mode

14
beesdoo_pos/data/cron.xml

@ -0,0 +1,14 @@
<odoo>
<data noupdate="1">
<record id="ir_cron_sent_pos_ticket" model="ir.cron">
<field name="name">send ticket</field>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="model">pos.order</field>
<field name="function">_send_order_cron</field>
<field name="args">()</field>
</record>
</data>
</odoo>

26
beesdoo_pos/models/beesdoo_pos.py

@ -1,5 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from openerp import models, fields, api, _ from openerp import models, fields, api, _
import logging
_logger = logging.getLogger(__name__)
class BeesPOS(models.Model): class BeesPOS(models.Model):
_inherit = 'pos.config' _inherit = 'pos.config'
@ -29,6 +32,11 @@ class BeescoopPosOrder(models.Model):
_inherit = 'pos.order' _inherit = 'pos.order'
print_status = fields.Selection([('no_print', 'Do not Print'),
('to_print', 'To print'),
('printed', 'Printed')],
default="no_print", string="Print Status")
@api.model @api.model
def send_order(self, receipt_name): def send_order(self, receipt_name):
order = self.search([('pos_reference', '=', receipt_name)]) order = self.search([('pos_reference', '=', receipt_name)])
@ -36,9 +44,23 @@ class BeescoopPosOrder(models.Model):
return _('Error: no order found') return _('Error: no order found')
if not order.partner_id.email: if not order.partner_id.email:
return _('Cannot send the ticket, no email address found on the client') return _('Cannot send the ticket, no email address found on the client')
order.print_status = 'to_print'
return _("Ticket will be sent")
@api.model
def _send_order_cron(self):
mail_template = self.env.ref("beesdoo_pos.email_send_ticket") mail_template = self.env.ref("beesdoo_pos.email_send_ticket")
mail_template.send_mail(order.id)
return _("Ticket sent")
_logger.info("Start to send ticket")
for order in self.search([('print_status', '=', 'to_print')]):
if not order.partner_id.email:
continue
mail_template.send_mail(order.id, force_send=True)
order.print_status = 'printed'
#Make sure we commit the change to not send ticket twice
self.env.cr.commit()
class BeescoopPosPartner(models.Model): class BeescoopPosPartner(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'

Loading…
Cancel
Save