[FIX] point_of_sale: use valid sequence on pos.order.line
2 sequences are created when a pos.config is created:
- one for pos.order, stored in sequence_id field
- one for pos.order.line, link is lost, like dust in the wind ♫
When creating a pos.order.line from a new order, the default value was using the
first sequence if found using the code 'pos.order.line' (returning the latest
created).
The name of the line was always using the same sequence, whatever the config
used.
In master, the field has been stored at 645df676 but in stable version, the
following hack is done:
As the sequences are created in the same transaction as the pos.config, the
create_date will be the same to the microsecond.
The name of the config can not be used as too easily changed (e.g. duplicate)
and may not be unique.
Done in SQL to avoid ORM cleaning of microseconds, not working with a search.
opw-703092
This commit is contained in:
@@ -1529,6 +1529,31 @@ class pos_order_line(osv.osv):
|
||||
res[line.id] = line.order_id.fiscal_position_id.map_tax(line.tax_ids)
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def create(self, values):
|
||||
if values.get('order_id') and not values.get('name'):
|
||||
# set name based on the sequence specified on the config
|
||||
config_id = self.env['pos.order'].browse(values['order_id']).session_id.config_id.id
|
||||
# HACK: sequence created in the same transaction as the config
|
||||
# cf TODO master is pos.config create
|
||||
# remove me saas-15
|
||||
self.env.cr.execute("""
|
||||
SELECT s.id
|
||||
FROM ir_sequence s
|
||||
JOIN pos_config c
|
||||
ON s.create_date=c.create_date
|
||||
WHERE c.id = %s
|
||||
AND s.code = 'pos.order.line'
|
||||
LIMIT 1
|
||||
""", (config_id,))
|
||||
sequence = self.env.cr.fetchone()
|
||||
if sequence:
|
||||
values['name'] = self.env['ir.sequence'].browse(sequence[0])._next()
|
||||
if not values.get('name'):
|
||||
# fallback on any pos.order sequence
|
||||
values['name'] = self.env['ir.sequence'].next_by_code('pos.order.line')
|
||||
return super(pos_order_line, self).create(values)
|
||||
|
||||
_columns = {
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
'name': fields.char('Line No', required=True, copy=False),
|
||||
@@ -1566,7 +1591,6 @@ class pos_order_line(osv.osv):
|
||||
|
||||
|
||||
_defaults = {
|
||||
'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').next_by_code(cr, uid, 'pos.order.line', context=context),
|
||||
'qty': lambda *a: 1,
|
||||
'discount': lambda *a: 0.0,
|
||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
|
||||
|
||||
Reference in New Issue
Block a user