[REM] purchase: remove avg_days_to_purchase field
Since https://github.com/odoo/enterprise/pull/31641, this field is not used anymore. Then remove it and remove the override of read_group linked to. odoo/upgrade#4162 Part-of: odoo/odoo#108977
This commit is contained in:
@@ -5,11 +5,7 @@
|
||||
# Please note that these reports are not multi-currency !!!
|
||||
#
|
||||
|
||||
import re
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.osv.expression import AND, expression
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class PurchaseReport(models.Model):
|
||||
@@ -37,10 +33,6 @@ class PurchaseReport(models.Model):
|
||||
delay = fields.Float('Days to Confirm', digits=(16, 2), readonly=True, group_operator='avg', help="Amount of time between purchase approval and order by date.")
|
||||
delay_pass = fields.Float('Days to Receive', digits=(16, 2), readonly=True, group_operator='avg',
|
||||
help="Amount of time between date planned and order by date for each purchase order line.")
|
||||
avg_days_to_purchase = fields.Float(
|
||||
'Average Days to Purchase', digits=(16, 2), readonly=True, store=False, # needs store=False to prevent showing up as a 'measure' option
|
||||
help="Amount of time between purchase approval and document creation date. Due to a hack needed to calculate this, \
|
||||
every record will show the same average value, therefore only use this as an aggregated value with group_operator=avg")
|
||||
price_total = fields.Float('Total', readonly=True)
|
||||
price_average = fields.Float('Average Cost', readonly=True, group_operator="avg")
|
||||
nbr_lines = fields.Integer('# of Lines', readonly=True)
|
||||
@@ -148,46 +140,3 @@ class PurchaseReport(models.Model):
|
||||
currency_table.rate
|
||||
"""
|
||||
return group_by_str
|
||||
|
||||
@api.model
|
||||
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
|
||||
""" This is a hack to allow us to correctly calculate the average of PO specific date values since
|
||||
the normal report query result will duplicate PO values across its PO lines during joins and
|
||||
lead to incorrect aggregation values.
|
||||
|
||||
Only the AVG operator is supported for avg_days_to_purchase.
|
||||
"""
|
||||
avg_days_to_purchase = next((field for field in fields if re.search(r'\bavg_days_to_purchase\b', field)), False)
|
||||
|
||||
if avg_days_to_purchase:
|
||||
fields.remove(avg_days_to_purchase)
|
||||
if any(field.split(':')[1].split('(')[0] != 'avg' for field in [avg_days_to_purchase] if field):
|
||||
raise UserError(_("Value: 'avg_days_to_purchase' should only be used to show an average. If you are seeing this message then it is being accessed incorrectly."))
|
||||
|
||||
res = []
|
||||
if fields:
|
||||
res = super(PurchaseReport, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
|
||||
|
||||
if not res and avg_days_to_purchase:
|
||||
res = [{}]
|
||||
|
||||
if avg_days_to_purchase:
|
||||
self.check_access_rights('read')
|
||||
query = """ SELECT AVG(days_to_purchase.po_days_to_purchase)::decimal(16,2) AS avg_days_to_purchase
|
||||
FROM (
|
||||
SELECT extract(epoch from age(po.date_approve,po.create_date))/(24*60*60) AS po_days_to_purchase
|
||||
FROM purchase_order po
|
||||
WHERE po.id IN (
|
||||
SELECT "purchase_report"."order_id" FROM %s WHERE %s)
|
||||
) AS days_to_purchase
|
||||
"""
|
||||
|
||||
subdomain = AND([domain, [('company_id', '=', self.env.company.id), ('date_approve', '!=', False)]])
|
||||
subtables, subwhere, subparams = expression(subdomain, self).query.get_sql()
|
||||
|
||||
self.env.cr.execute(query % (subtables, subwhere), subparams)
|
||||
res[0].update({
|
||||
'__count': 1,
|
||||
avg_days_to_purchase.split(':')[0]: self.env.cr.fetchall()[0][0],
|
||||
})
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user