[FIX] point_of_sale: fix order naming translations

Before this fix translations of the order names missed a crusial space
that is needed to get information out of it in the front-end.

* Load Spanish-PE translation.
* Change localization preference for a user (either admin or demo) to
Spanish.
* Login to Odoo POS using the user with spanish localization.
* Go to POS, select BAR POS, select a table and place a draft order
with at least 1 order line (do not proceed to payment)
* Go back to table mgmt view and click again to the previous selected
table and the error appears.

This issue happens in any translation where pos_reference for a draft
order is not separated with white space as it happens in English. I mean
in english the pos_reference is something like "Order 00003-001-0002"
but in spanish it is "Pedido00003-001-0002" (no whitespace), so
https://github.com/odoo/odoo/blob/13.0/addons/pos_restaurant/models/pos_order.py#L143
assumes that there will always be a whitespace which is not true for
some odoo translations like spanish one.

This fix adds a variable to the translation string making it more clear
the space is part of the string. To make sure the code will also work on
languages with the words in another order `order['pos_reference'].split(' ')[1]`
is replaced by `search(r"\d{5}-\d{3}-\d{4}", order['pos_reference']).group(0)`,
we know the uid will always be formatted as nnnnn-nnn-nnnn

solves #40036

closes odoo/odoo#40302

X-original-commit: c32126da5ac55a03637d82cf520b8655be8546e6
Signed-off-by: Gert Pellin - GPE <switch87@users.noreply.github.com>
This commit is contained in:
Gert Pellin
2019-11-14 18:11:55 +00:00
committed by fw-bot
parent 3214dd56f1
commit ca57ecf446
3 changed files with 5 additions and 4 deletions
+1 -1
View File
@@ -2634,7 +2634,7 @@ msgstr ""
#: code:addons/point_of_sale/static/src/js/models.js:0
#: code:addons/point_of_sale/static/src/js/models.js:0
#, python-format
msgid "Order "
msgid "Order %s"
msgstr ""
#. module: point_of_sale
+2 -2
View File
@@ -2267,7 +2267,7 @@ exports.Order = Backbone.Model.extend({
} else {
this.sequence_number = this.pos.pos_session.sequence_number++;
this.uid = this.generate_unique_id();
this.name = _t("Order ") + this.uid;
this.name = _.str.sprintf(_t("Order %s"), this.uid);
this.validation_date = undefined;
this.fiscal_position = _.find(this.pos.fiscal_positions, function(fp) {
return fp.id === self.pos.config.default_fiscal_position_id[0];
@@ -2316,7 +2316,7 @@ exports.Order = Backbone.Model.extend({
}
this.session_id = this.pos.pos_session.id;
this.uid = json.uid;
this.name = _t("Order ") + this.uid;
this.name = _.str.sprintf(_t("Order %s"), this.uid);
this.validation_date = json.creation_date;
this.server_id = json.server_id ? json.server_id : false;
this.user_id = json.user_id;
+2 -1
View File
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from itertools import groupby
from re import search
from odoo import api, fields, models
@@ -140,7 +141,7 @@ class PosOrder(models.Model):
for order in table_orders:
order['pos_session_id'] = order['session_id'][0]
order['uid'] = order['pos_reference'].split(' ')[1]
order['uid'] = search(r"\d{5,}-\d{3,}-\d{4,}", order['pos_reference']).group(0)
order['name'] = order['pos_reference']
order['creation_date'] = order['create_date']
order['server_id'] = order['id']