Skip to content
Snippets Groups Projects
Commit 9547813e authored by yhu-odoo's avatar yhu-odoo
Browse files

[FIX] purchase_stock: compare only date in on-time delivery


Previously, when compute on-time delivery, we compare the date_planned
on PO line with the date on stock.move. Since they are both datetime,
the product that delivered on the scheduled date may be considered delay
because of the 'time' part is late, which is normally not what we want.
In this commit, we only compare the date part of them to decide whether
it's late or not.

Task 2346121
PR #58653

closes odoo/odoo#59386

X-original-commit: 86af7c64
Signed-off-by: default avatarArnold Moyaux <amoyaux@users.noreply.github.com>
parent f928606a
No related branches found
No related tags found
No related merge requests found
......@@ -1170,8 +1170,8 @@ class PurchaseOrderLine(models.Model):
}
def _convert_to_middle_of_day(self, date):
"""Return a datetime which is the last minute of the input date(time)
according to order user's time zone, convert to UTC time.
"""Return a datetime which is the noon of the input date(time) according
to order user's time zone, convert to UTC time.
"""
return timezone(self.order_id.user_id.tz or self.company_id.partner_id.tz or 'UTC').localize(datetime.combine(date, time(12))).astimezone(UTC).replace(tzinfo=None)
......
......@@ -25,7 +25,7 @@ class ResPartner(models.Model):
for line in order_lines:
on_time, ordered = partner_dict.get(line.partner_id, (0, 0))
ordered += line.product_uom_qty
on_time += sum(line.mapped('move_ids').filtered(lambda m: m.state == 'done' and m.date <= datetime.combine(m.purchase_line_id.date_planned, time.min)).mapped('quantity_done'))
on_time += sum(line.mapped('move_ids').filtered(lambda m: m.state == 'done' and m.date.date() <= m.purchase_line_id.date_planned.date()).mapped('quantity_done'))
partner_dict[line.partner_id] = (on_time, ordered)
seen_partner = self.env['res.partner']
for partner, numbers in partner_dict.items():
......
......@@ -31,7 +31,7 @@ SELECT m.id AS id,
Min(po.partner_id) AS partner_id,
Sum(pol.product_uom_qty) AS qty_total,
Sum(CASE
WHEN pol.date_planned >= m.date THEN ml.qty_done
WHEN (pol.date_planned::date >= m.date::date) THEN ml.qty_done
ELSE 0
END) AS qty_on_time
FROM stock_move m
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment