Skip to content

Commit 239a5cb

Browse files
committed
[FIX] point_of_sale: prevent traceback with sequence prefix
**Steps to reproduce:** - Go to the sequence interface, and chose the config #1 for a pos.order - In the prefix field, enter something with characters that are not numbers - Go to a PoS with config #1 active and make a purchase - A traceback appears saying that we can't convert the sequence to an Integer **Why the fix:** Having a custom prefix with letters used to work, but in version 19, we now store the sequence_number with the prefix, which can be composed of characters which can not be stored in an Integer field such as sequence_number. To prevent this error, we remove the prefix and the suffix (which has the same issue) from the sequence_number before storing it. We then add the prefix and the suffix back when computing the order's name, so that it's consistant with the prefix and the suffix the user chose. This is the way the order's name was computed before version 19.0, which saw the prefix and suffix disappear from the order's name. opw-5386575 closes odoo#244366 X-original-commit: 67fc637 Signed-off-by: Adrien Guilliams (adgu) <adgu@odoo.com> Signed-off-by: Arthur Nanson (artn) <artn@odoo.com>
1 parent 8444c6b commit 239a5cb

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

addons/point_of_sale/models/pos_order.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,13 @@ def create(self, vals_list):
571571
return super().create(vals_list)
572572

573573
def _update_sequence_number(self, session, values):
574-
values['sequence_number'] = session.config_id.order_seq_id._next() # Some localization needs orders to have a sequence number
574+
# Some localization needs orders to have a sequence number
575+
values['sequence_number'] = (
576+
session.config_id.order_seq_id
577+
._next()
578+
.removeprefix(session.config_id.order_seq_id.prefix or '')
579+
.removesuffix(session.config_id.order_seq_id.suffix or '')
580+
)
575581

576582
@api.model
577583
def _complete_values_from_session(self, session, values):
@@ -692,7 +698,9 @@ def _compute_order_name(self, session=None):
692698
return _('%(refunded_order)s REFUND', refunded_order=self.refunded_order_id.name)
693699
else:
694700
last_reference_part = self.get_reference_last_part()
695-
return f"{session.config_id.name} - {last_reference_part}"
701+
prefix = session.config_id.order_seq_id.prefix or session.config_id.name
702+
suffix = f" - {session.config_id.order_seq_id.suffix}" if session.config_id.order_seq_id.suffix else ''
703+
return f"{prefix} - {last_reference_part}{suffix}"
696704

697705
def get_reference_last_part(self):
698706
return self.pos_reference.split('-')[-1]

addons/point_of_sale/tests/test_point_of_sale_flow.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,3 +2099,38 @@ def test_filter_local_data_no_errors(self):
20992099
self.env.clear()
21002100
data = current_session.with_company(self.env.company).filter_local_data({'product.product': [product.id]})
21012101
self.assertIn(product.id, data['product.product'])
2102+
2103+
def test_string_sequence_number(self):
2104+
self.pos_config_usd.open_ui()
2105+
current_session = self.pos_config_usd.current_session_id
2106+
current_session.config_id.order_seq_id.prefix = '/AA'
2107+
current_session.config_id.order_seq_id.suffix = '1.B'
2108+
product_order = {
2109+
'amount_paid': 750,
2110+
'amount_tax': 0,
2111+
'amount_return': 0,
2112+
'amount_total': 750,
2113+
'date_order': fields.Datetime.to_string(fields.Datetime.now()),
2114+
'lines': [[0, 0, {
2115+
'price_unit': 750.0,
2116+
'product_id': self.product.id,
2117+
'price_subtotal': 750.0,
2118+
'price_subtotal_incl': 750.0,
2119+
'tax_ids': [[6, False, []]],
2120+
'qty': 1,
2121+
}]],
2122+
'name': 'Order 12345-123-1234',
2123+
'partner_id': False,
2124+
'session_id': current_session.id,
2125+
'payment_ids': [[0, 0, {
2126+
'amount': 750,
2127+
'name': fields.Datetime.now(),
2128+
'payment_method_id': self.bank_payment_method.id
2129+
}]],
2130+
'uuid': '12345-123-1234',
2131+
'user_id': self.env.uid,
2132+
'to_invoice': False}
2133+
2134+
self.env['pos.order'].sync_from_ui([product_order])
2135+
order = self.env['pos.order'].search([])
2136+
self.assertEqual(order.name, f"/AA - {order.pos_reference.split('-')[-1]} - 1.B")

0 commit comments

Comments
 (0)