[FIX] purchase: compute the average of the delays in report
When consulting the Purchase Analysis, the measure "Days to Confirm" may
not be easily understandable
To reproduce the issue:
1. Create a purchase order PO:
- Order Deadline: <today + 10 days>
- Add 2 products
2. Confirm PO
3. Purchase > Reporting:
- Measures: Days to Confirm
- Group By: Order
Error: For PO, the value of "Days to Confirm" is -20, it should be -10
The report computes the sum of the delay (i.e., "Days to Confirm") of
each purchase order line. Computing an average seems more relevant
A similar flow could be reproduce with the measure "Days to Receive"
(i.e., the difference between the Order Deadline and the Receipt Date)
OPW-2678673
closes odoo/odoo#81053
X-original-commit: da3fa1f8887e06e7a86e761ef844f79cc0d06e6f
Signed-off-by: Arnold Moyaux <arm@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
@@ -34,8 +34,9 @@ class PurchaseReport(models.Model):
|
||||
company_id = fields.Many2one('res.company', 'Company', readonly=True)
|
||||
currency_id = fields.Many2one('res.currency', 'Currency', readonly=True)
|
||||
user_id = fields.Many2one('res.users', 'Purchase Representative', readonly=True)
|
||||
delay = fields.Float('Days to Confirm', digits=(16, 2), readonly=True, help="Amount of time between purchase approval and order by date.")
|
||||
delay_pass = fields.Float('Days to Receive', digits=(16, 2), readonly=True, help="Amount of time between date planned and order by date for each purchase order line.")
|
||||
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, \
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
from odoo.tests import Form, tagged
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
@@ -66,3 +66,25 @@ class TestPurchaseOrderReport(AccountTestInvoicingCommon):
|
||||
self.assertEqual(res_product2.qty_ordered, 1.0, 'No conversion needed since product_b is already a dozen')
|
||||
# report should show in company currency (amount/rate) = (200/2)
|
||||
self.assertEqual(res_product2.price_total, 100.0, 'Currency conversion is not working')
|
||||
|
||||
def test_01_delay_and_delay_pass(self):
|
||||
po_form = Form(self.env['purchase.order'])
|
||||
po_form.partner_id = self.partner_a
|
||||
po_form.date_order = datetime.now() + timedelta(days=10)
|
||||
with po_form.order_line.new() as line:
|
||||
line.product_id = self.product_a
|
||||
with po_form.order_line.new() as line:
|
||||
line.product_id = self.product_b
|
||||
po_form.date_planned = datetime.now() + timedelta(days=15)
|
||||
po = po_form.save()
|
||||
|
||||
po.button_confirm()
|
||||
|
||||
po.flush()
|
||||
report = self.env['purchase.report'].read_group(
|
||||
[('order_id', '=', po.id)],
|
||||
['order_id', 'delay', 'delay_pass'],
|
||||
['order_id'],
|
||||
)
|
||||
self.assertEqual(round(report[0]['delay']), -10, msg="The PO has been confirmed 10 days in advance")
|
||||
self.assertEqual(round(report[0]['delay_pass']), 5, msg="There are 5 days between the order date and the planned date")
|
||||
|
||||
Reference in New Issue
Block a user