[FIX] point_of_sale: implement todo

The link between the pos.order.line sequence and the config was lost after
creation.
Using the default with next_by_code is incorrect as every pos.config has a
sequence with the same code.
This commit is contained in:
Martin Trigaux
2017-02-16 15:33:26 +01:00
parent ebc1d24fc5
commit 645df67631
2 changed files with 18 additions and 7 deletions
+6 -4
View File
@@ -104,6 +104,9 @@ class PosConfig(models.Model):
sequence_id = fields.Many2one('ir.sequence', string='Order IDs Sequence', readonly=True,
help="This sequence is automatically created by Odoo but you can change it "
"to customize the reference numbers of your orders.", copy=False)
sequence_line_id = fields.Many2one('ir.sequence', string='Order Line IDs Sequence', readonly=True,
help="This sequence is automatically created by Odoo but you can change it "
"to customize the reference numbers of your orders lines.", copy=False)
session_ids = fields.One2many('pos.session', 'config_id', string='Sessions')
current_session_id = fields.Many2one('pos.session', compute='_compute_current_session', string="Current Session")
current_session_state = fields.Char(compute='_compute_current_session')
@@ -218,16 +221,15 @@ class PosConfig(models.Model):
# force sequence_id field to new pos.order sequence
values['sequence_id'] = IrSequence.create(val).id
# TODO master: add field sequence_line_id on model
# this make sure we always have one available per company
val.update(name=_('POS order line %s') % values['name'], code='pos.order.line')
IrSequence.create(val)
values['sequence_line_id'] = IrSequence.create(val).id
return super(PosConfig, self).create(values)
@api.multi
def unlink(self):
for pos_config in self.filtered(lambda pos_config: pos_config.sequence_id):
for pos_config in self.filtered(lambda pos_config: pos_config.sequence_id or pos_config.sequence_line_id):
pos_config.sequence_id.unlink()
pos_config.sequence_line_id.unlink()
return super(PosConfig, self).unlink()
# Methods to open the POS
+12 -3
View File
@@ -31,7 +31,7 @@ class PosOrder(models.Model):
@api.model
def _order_fields(self, ui_order):
process_line = partial(self.env['pos.order.line']._order_line_fields)
process_line = partial(self.env['pos.order.line']._order_line_fields, session_id=ui_order['pos_session_id'])
return {
'name': ui_order['name'],
'user_id': ui_order['user_id'] or False,
@@ -749,14 +749,23 @@ class PosOrderLine(models.Model):
_description = "Lines of Point of Sale"
_rec_name = "product_id"
def _order_line_fields(self, line):
def _order_line_fields(self, line, session_id=None):
if line and 'name' not in line[2]:
if session_id:
# set name based on the sequence specified on the config
session = self.env['pos.session'].browse(session_id)
line[2]['name'] = session.config_id.sequence_line_id._next()
else:
# fallback on any pos.order.line sequence
line[2]['name'] = self.env['ir.sequence'].next_by_code('pos.order.line')
if line and 'tax_ids' not in line[2]:
product = self.env['product.product'].browse(line[2]['product_id'])
line[2]['tax_ids'] = [(6, 0, [x.id for x in product.taxes_id])]
return line
company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.user.company_id)
name = fields.Char(string='Line No', required=True, copy=False, default=lambda self: self.env['ir.sequence'].next_by_code('pos.order.line'))
name = fields.Char(string='Line No', required=True, copy=False)
notice = fields.Char(string='Discount Notice')
product_id = fields.Many2one('product.product', string='Product', domain=[('sale_ok', '=', True)], required=True, change_default=True)
price_unit = fields.Float(string='Unit Price', digits=0)