Skip to content

Commit 5786bd3

Browse files
committed
[FIX] point_of_sale: prevent the new session sequencing with prefix to start with the config name
Description of the issue/feature this PR addresses: The sequencing for new PoS Session isn't right when set to another value than the default. Current behavior before PR: The PoS name was added before the intended sequence. For example, if you set the pos.session sequence to TEST/ with the Furniture Shop, it return Furniture ShopTEST/00001. Desired behavior after PR is merged: The PoS Session name should be using only the sequence if the sequence isn't the default one. When the pos.session sequence is set to TEST/ and you open the Furniture Shop, it should return TEST/00001. Steps to reproduce: - change the default sequence prefix for pos.session - open a pos session and Open Register - go to Point of Sale > Orders > Sessions - check the Session ID opw-4822673 closes odoo#212775 Signed-off-by: Adrien Guilliams (adgu) <adgu@odoo.com>
1 parent cdad436 commit 5786bd3

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

addons/point_of_sale/models/pos_session.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,9 +1746,12 @@ def set_opening_control(self, cashbox_value: int, notes: str):
17461746
return
17471747
self.state = 'opened'
17481748
self.start_at = fields.Datetime.now()
1749-
self.name = self.config_id.name + self.env['ir.sequence'].with_context(
1749+
1750+
sequence = self.env['ir.sequence'].with_context(
17501751
company_id=self.config_id.company_id.id
1751-
).next_by_code('pos.session') + (self.name if self.name != '/' else '')
1752+
).search([('code', '=', 'pos.session'), ('company_id', 'in', [self.config_id.company_id.id, False])], order='company_id', limit=1)
1753+
1754+
self.name = (self.config_id.name if sequence.prefix == '/' else '') + sequence.next_by_code('pos.session') + (self.name if self.name != '/' else '')
17521755

17531756
cash_payment_method_ids = self.config_id.payment_method_ids.filtered(lambda pm: pm.is_cash_count)
17541757
if cash_payment_method_ids:

addons/point_of_sale/tests/test_pos_basic_config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,24 @@ def open_and_check(pos_data):
889889
open_and_check(pos01_data)
890890
open_and_check(pos02_data)
891891

892+
def test_pos_session_name_sequencing(self):
893+
""" This test check if the session name is correctly set according to the sequence """
894+
895+
sequence = self.env['ir.sequence'].search([('code', '=', 'pos.session')])
896+
sequence.prefix = '/'
897+
sequence.write({'number_next_actual': 1000})
898+
name = self.config.name
899+
900+
self.open_new_session(0)
901+
self.assertEqual(self.pos_session.name, name + '/01000')
902+
903+
self.pos_session.close_session_from_ui()
904+
905+
sequence.prefix = 'TEST/'
906+
907+
self.open_new_session(0)
908+
self.assertEqual(self.pos_session.name, 'TEST/01001')
909+
892910
def test_load_data_should_not_fail(self):
893911
"""load_data shouldn't fail
894912

0 commit comments

Comments
 (0)