[FIX] purchase: do not reset expected date
A misleading behavior occurs with the recomputation of scheduled date. Here is the use case: - Create a PO with 2 products - For the product 1, set the scheduled date to today + 7 days - For the product 2, set the scheduled date to today + 14 days When saving, the scheduled date of product 2 is reset to today + 7 days. This is of course unexpected, but moreover, a different behavior can happen depending on how the scheduled dates are modified. In the previous case (both products have now the same scheduled date), one can observe 2 situations. Case 1. For the product 2, set the scheduled date to today + 14 days and save. In this case, the scheduled date of product 2 is not reset. Case 2. - For the product 1, set the scheduled date to today + 8 days - For the product 2, set the scheduled date to today + 14 days In this case, the scheduled date of product 2 is reset to today + 8 days when saving The reason of a different behavior in the 2 situations is that the scheduled date of the PO is changed in case 2 and not in case 1. Since the scheduled date of the PO is changed, it triggers the inverse function `_inverse_date_planned`. When saving, it is not possible to know whether the scheduled date of the PO was changed on purpose by the user or recomputed. There are 2 solutions to get a consistent behavior: - Force the scheduled date of each line to be the same than the scheduled date of the PO. However, this makes the scheduled date of the line useless. - Do not change the scheduled date of the lines when the schedued date of the PO is changed. However, this removes the ability to reset automatically the scheduled date of the all lines at once. This is the second solution which is chosen with this commit. opw-682934 opw-684063 Closes #12904
This commit is contained in:
@@ -30,11 +30,6 @@ class PurchaseOrder(models.Model):
|
||||
'amount_total': amount_untaxed + amount_tax,
|
||||
})
|
||||
|
||||
@api.multi
|
||||
def _inverse_date_planned(self):
|
||||
for order in self:
|
||||
order.order_line.write({'date_planned': self.date_planned})
|
||||
|
||||
@api.depends('order_line.date_planned')
|
||||
def _compute_date_planned(self):
|
||||
for order in self:
|
||||
@@ -140,7 +135,8 @@ class PurchaseOrder(models.Model):
|
||||
picking_count = fields.Integer(compute='_compute_picking', string='Receptions', default=0)
|
||||
picking_ids = fields.Many2many('stock.picking', compute='_compute_picking', string='Receptions', copy=False)
|
||||
|
||||
date_planned = fields.Datetime(string='Scheduled Date', compute='_compute_date_planned', inverse='_inverse_date_planned', store=True, select=True, oldname='minimum_planned_date')
|
||||
# There is no inverse function on purpose since the date may be different on each line
|
||||
date_planned = fields.Datetime(string='Scheduled Date', compute='_compute_date_planned', store=True, select=True, oldname='minimum_planned_date')
|
||||
|
||||
amount_untaxed = fields.Monetary(string='Untaxed Amount', store=True, readonly=True, compute='_amount_all', track_visibility='always')
|
||||
amount_tax = fields.Monetary(string='Taxes', store=True, readonly=True, compute='_amount_all')
|
||||
|
||||
Reference in New Issue
Block a user