|
7 | 7 | class MrpProduction(models.Model):
|
8 | 8 | _inherit = "mrp.production"
|
9 | 9 |
|
10 |
| - @api.onchange("date_planned_start", "product_id") |
11 |
| - def _onchange_date_planned_start(self): |
12 |
| - res = super(MrpProduction, self)._onchange_date_planned_start() |
13 |
| - if self.date_planned_start and not self.is_planned: |
| 10 | + @api.depends("company_id", "date_planned_start", "is_planned", "product_id") |
| 11 | + def _compute_date_planned_finished(self): |
| 12 | + res = super(MrpProduction, self)._compute_date_planned_finished() |
| 13 | + productions = self.filtered(lambda p: p.date_planned_start and not p.is_planned) |
| 14 | + for production in productions: |
14 | 15 | warehouse = self.picking_type_id.warehouse_id
|
15 | 16 | if warehouse.calendar_id:
|
16 |
| - if self.product_id.produce_delay: |
17 |
| - self.date_planned_finished = warehouse.calendar_id.plan_days( |
18 |
| - +1 * self.product_id.produce_delay + 1, self.date_planned_start |
| 17 | + if production.product_id.produce_delay: |
| 18 | + production.date_planned_finished = ( |
| 19 | + warehouse.calendar_id.plan_days( |
| 20 | + +1 * production.product_id.produce_delay + 1, |
| 21 | + production.date_planned_start, |
| 22 | + ) |
19 | 23 | )
|
20 |
| - if self.company_id.manufacturing_lead: |
21 |
| - self.date_planned_finished = warehouse.calendar_id.plan_days( |
22 |
| - +1 * self.company_id.manufacturing_lead + 1, |
23 |
| - self.date_planned_finished, |
| 24 | + if production.company_id.manufacturing_lead: |
| 25 | + production.date_planned_finished = ( |
| 26 | + warehouse.calendar_id.plan_days( |
| 27 | + +1 * production.company_id.manufacturing_lead + 1, |
| 28 | + production.date_planned_finished, |
| 29 | + ) |
24 | 30 | )
|
25 |
| - self.move_finished_ids = [ |
26 |
| - (1, m.id, {"date": self.date_planned_finished}) |
27 |
| - for m in self.move_finished_ids |
| 31 | + production.move_finished_ids = [ |
| 32 | + (1, m.id, {"date": production.date_planned_finished}) |
| 33 | + for m in production.move_finished_ids |
28 | 34 | ]
|
29 | 35 | return res
|
30 | 36 |
|
|
0 commit comments