[FIX] stock, mrp: scheduler assign finished move

Usecase to reproduce
- Create a BoM with finished product A and Comp C
- Create a RR on product A with min qty 10
- Product A is tracked by serial number and have route manufacture
- Run the scheduler twice.

The finished tabs in the manufacturing order created from the order
point contains 10 move lines with 1 qty reserved and 0 quantity done.

The first run created the MO. The second run, assign the finished moves
and thus created the move lines for finished product A.

However those move line are not used by mrp because the workorder and
the produce wizard will only create new lines instead of using existing
lines with reservation. Also action_assign on MO only trigger
_action_assign on raw moves.

This commit add a hook on scheduler in order to modify the domain that
will be used in order to search moves to assign. Use the hook in order
to avoid move with the production_id many2one set.

closes odoo/odoo#32597

Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
This commit is contained in:
Arnold Moyaux
2019-04-11 07:24:49 +00:00
parent d5d93474de
commit 027ff77a9e
2 changed files with 20 additions and 3 deletions
+10
View File
@@ -5,6 +5,7 @@ from dateutil.relativedelta import relativedelta
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.osv import expression
class StockRule(models.Model):
@@ -88,3 +89,12 @@ class StockRule(models.Model):
new_move_vals = super(StockRule, self)._push_prepare_move_copy_values(move_to_copy, new_date)
new_move_vals['production_id'] = False
return new_move_vals
class ProcurementGroup(models.Model):
_inherit = 'procurement.group'
@api.model
def _get_moves_to_assign_domain(self):
domain = super(ProcurementGroup, self)._get_moves_to_assign_domain()
domain = expression.AND([domain, [('production_id', '=', False)]])
return domain
+10 -3
View File
@@ -356,15 +356,22 @@ class ProcurementGroup(models.Model):
('picking_id.backorder_id', '=', False),
('product_id', '=', values['product_id'].id)]
@api.model
def _get_moves_to_assign_domain(self):
return expression.AND([
[('state', 'in', ['confirmed', 'partially_available'])],
[('product_uom_qty', '!=', 0.0)]
])
@api.model
def _run_scheduler_tasks(self, use_new_cursor=False, company_id=False):
# Minimum stock rules
self.sudo()._procure_orderpoint_confirm(use_new_cursor=use_new_cursor, company_id=company_id)
# Search all confirmed stock_moves and try to assign them
moves_to_assign = self.env['stock.move'].search([
('state', 'in', ['confirmed', 'partially_available']), ('product_uom_qty', '!=', 0.0)
], limit=None, order='priority desc, date_expected asc')
domain = self._get_moves_to_assign_domain()
moves_to_assign = self.env['stock.move'].search(domain, limit=None,
order='priority desc, date_expected asc')
for moves_chunk in split_every(100, moves_to_assign.ids):
self.env['stock.move'].browse(moves_chunk)._action_assign()
if use_new_cursor: