[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) <arm@odoo.com> Signed-off-by: Tiffany Chang <tic@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user