Skip to content
Snippets Groups Projects
Commit 80e71545 authored by Adrien Widart's avatar Adrien Widart
Browse files

[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#80671

Signed-off-by: default avatarArnold Moyaux <arm@odoo.com>
parent 81ad4d6a
Branches
Tags
No related merge requests found
......@@ -30,8 +30,8 @@ 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)
delay_pass = fields.Float('Days to Receive', digits=(16, 2), readonly=True)
delay = fields.Float('Days to Confirm', digits=(16, 2), readonly=True, group_operator='avg')
delay_pass = fields.Float('Days to Receive', digits=(16, 2), readonly=True, 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)
......
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import datetime
from datetime import datetime, timedelta
from odoo.tests import common, Form, tagged
......@@ -78,3 +78,25 @@ class TestPurchaseOrderReport(common.TransactionCase):
self.assertEquals(res_product2.qty_ordered, 12.0, 'UoM conversion is not working')
# report should show in company currency (amount/rate) = (200/2)
self.assertEquals(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_id
po_form.date_order = datetime.now() + timedelta(days=10)
with po_form.order_line.new() as line:
line.product_id = self.product1
with po_form.order_line.new() as line:
line.product_id = self.product2
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")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment