From 609ebb86e2a0a885152dbe6c0b6ebb2dd8fe7bfd Mon Sep 17 00:00:00 2001 From: hoangtiendung Date: Tue, 29 Mar 2022 03:27:29 +0000 Subject: [PATCH] [FIX] purchase: Wrong statistics RFQs Sent Last 7 Days Issues ------ Purchase Dashboard gives wong value for PO in RFQ and RFQ sent when user's language is not English Current behavior before PR: --------------------------- 1. Create some RFQ and RFQ Sent to see its statistic in dashboard 2. Swith user language to another one that is other than English 3. Statistic in the dashboard is wrong now Solution -------- Passing translated RFQ and RFQ Sent into the dashboard query in stead of passing pure text without translation. closes odoo/odoo#95248 X-original-commit: ba8ad25b413151544b85477c9aae858e99c6cfaf Signed-off-by: Arnold Moyaux (arm) Signed-off-by: Tiffany Chang --- addons/purchase/models/purchase.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 15f982d8128..dd03d670d18 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -680,6 +680,16 @@ class PurchaseOrder(models.Model): } one_week_ago = fields.Datetime.to_string(fields.Datetime.now() - relativedelta(days=7)) + + # Get list of translation values + Translation = self.env['ir.translation'] + list_old_value_char = [] + list_new_value_char = [] + field_name = 'ir.model.fields.selection,name' + for lang in self.env['res.lang'].search_read([], ['code']): + list_old_value_char.append(Translation._get_source(field_name, 'model', lang['code'], source='RFQ')) + list_new_value_char.append(Translation._get_source(field_name, 'model', lang['code'], source='RFQ Sent')) + # This query is brittle since it depends on the label values of a selection field # not changing, but we don't have a direct time tracker of when a state changes query = """SELECT COUNT(1) @@ -689,12 +699,12 @@ class PurchaseOrder(models.Model): WHERE m.create_date >= %s AND m.model = 'purchase.order' AND m.message_type = 'notification' - AND v.old_value_char = 'RFQ' - AND v.new_value_char = 'RFQ Sent' + AND v.old_value_char IN %s + AND v.new_value_char IN %s AND po.company_id = %s; """ - self.env.cr.execute(query, (one_week_ago, self.env.company.id)) + self.env.cr.execute(query, (one_week_ago, tuple(list_old_value_char), tuple(list_new_value_char), self.env.company.id)) res = self.env.cr.fetchone() result['all_sent_rfqs'] = res[0] or 0