Fix session management for automatic null receipt booking#44
Conversation
8191
commented
May 22, 2026
- Session name to correspond to normal sales sessions by setting name after creating the session, as Odoo overrides the passed session name in the PosSession.create() method.
- Use the opening_note as an identifier instead of the session name to derive if the session was opened by this module during booking of the null receipt.
* Session name to correspond to normal sales sessions by setting name after creating the session, as Odoo overrides the passed session name in the PosSession.create() method. * Use the opening_note as an identifier instead of the session name to derive if the session was opened by this module during booking of the null receipt.
| 'start_at': fields.Datetime.now(), | ||
| 'opening_notes': opening_notes, | ||
| }) | ||
| pos_session.name = self.env['ir.sequence'].with_context(company_id=pos_config_rec.company_id.id).next_by_code('pos.session') |
There was a problem hiding this comment.
I am not sure why this line would be needed. We can just let the default create methode set the name. I did not test it yet, but I believe this would even introduce gaps in the sequence.
There was a problem hiding this comment.
That line is actually the essence of this PR... 😄
Odoo overrides the passed name in the create method.
From Odoo 18.0 upstream:
class PosSession(models.Model):
_name = 'pos.session'
...
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
config_id = vals.get('config_id') or self.env.context.get('default_config_id')
name_counter = 0
if not vals.get('rescue'):
config_name = self.env['pos.config'].browse(config_id).name
vals['name'] = config_name + '/'
sessions = self.sudo().search_read([('name', 'ilike', vals['name'])], ['name'], order='name desc', limit=1)
if len(sessions):
name_counter = int(sessions[0]['name'].split('/')[-1]) + 1
vals['name'] += str(name_counter).zfill(5)So Odoo overrides the name upon session creation, but this addon relies on the session name to be persisted, as otherwise the session is not found anymore when trying to close it.
Additionally, in Odoo 18.0 the session name is changed again, once the user starts the opening control. Because this is not done by this addon, the created session names from pos_registrierkasse differ from all others, which is simply odd... Therefore the new session name needs to be set directly.
This line was actually copied from the upstream:
def set_opening_control(self, cashbox_value: int, notes: str):
if self.state != 'opening_control':
return
self._set_opening_control_data(cashbox_value, notes)
if not self.rescue:
self.name = self.env['ir.sequence'].with_context(company_id=self.config_id.company_id.id).next_by_code('pos.session')There was a problem hiding this comment.
I'd say the switch to using the opening notes to match the correct session to close is the essence of this PR. Since we no longer rely on the name we can just let odoo handle it.