Skip to content

Fix session management for automatic null receipt booking#44

Open
8191 wants to merge 1 commit into
Vorstieg:18.0from
8191:fix_session_mgmt
Open

Fix session management for automatic null receipt booking#44
8191 wants to merge 1 commit into
Vorstieg:18.0from
8191:fix_session_mgmt

Conversation

@8191

@8191 8191 commented May 22, 2026

Copy link
Copy Markdown
Contributor
  • 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')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@8191 8191 May 26, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants