summaryrefslogtreecommitdiff
path: root/addons/mrp_subcontracting/models
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2019-09-20 17:33:22 +0200
committerChristophe Simonis <chs@odoo.com>2019-09-20 17:34:45 +0200
commit64e43808b79badb5869a8d73cc1cc3f3b3aa8e12 (patch)
tree9a22d5f6c03073a4d10faedea8df23a5211e8b8f /addons/mrp_subcontracting/models
parent944891ced081cda3b8b3db5faf3b7ac23b6b4ce8 (diff)
parent58a83d12228fbbd4e9dde542e133d264204ee0f3 (diff)
[MERGE] forward port branch saas-12.5 up to 58a83d12228
Diffstat (limited to 'addons/mrp_subcontracting/models')
-rw-r--r--addons/mrp_subcontracting/models/mrp_bom.py4
-rw-r--r--addons/mrp_subcontracting/models/stock_move.py25
-rw-r--r--addons/mrp_subcontracting/models/stock_picking.py23
3 files changed, 36 insertions, 16 deletions
diff --git a/addons/mrp_subcontracting/models/mrp_bom.py b/addons/mrp_subcontracting/models/mrp_bom.py
index 7088d4bb93d..3375653d737 100644
--- a/addons/mrp_subcontracting/models/mrp_bom.py
+++ b/addons/mrp_subcontracting/models/mrp_bom.py
@@ -14,4 +14,6 @@ class MrpBom(models.Model):
domain = self._bom_find_domain(product_tmpl=product_tmpl, product=product, picking_type=picking_type, company_id=company_id, bom_type=bom_type)
if subcontractor:
domain = AND([domain, [('subcontractor_ids', 'in', subcontractor.id)]])
- return self.search(domain, order='sequence, product_id', limit=1)
+ return self.search(domain, order='sequence, product_id', limit=1)
+ else:
+ return self.env['mrp.bom']
diff --git a/addons/mrp_subcontracting/models/stock_move.py b/addons/mrp_subcontracting/models/stock_move.py
index 80f8badbd24..9cb940781cf 100644
--- a/addons/mrp_subcontracting/models/stock_move.py
+++ b/addons/mrp_subcontracting/models/stock_move.py
@@ -11,7 +11,7 @@ from odoo.tools.float_utils import float_compare, float_is_zero
class StockMove(models.Model):
_inherit = 'stock.move'
- is_subcontract = fields.Boolean('The move is a subcontract receipt', copy=False)
+ is_subcontract = fields.Boolean('The move is a subcontract receipt')
show_subcontracting_details_visible = fields.Boolean(
compute='_compute_show_subcontracting_details_visible'
)
@@ -38,12 +38,23 @@ class StockMove(models.Model):
move.show_details_visible = True
return res
+ def copy(self, default=None):
+ self.ensure_one()
+ if not self.is_subcontract or 'location_id' in default:
+ return super(StockMove, self).copy(default=default)
+ if not default:
+ default = {}
+ default['location_id'] = self.picking_id.location_id.id
+ return super(StockMove, self).copy(default=default)
+
def write(self, values):
""" If the initial demand is updated then also update the linked
subcontract order to the new quantity.
"""
res = super(StockMove, self).write(values)
if 'product_uom_qty' in values:
+ if self.env.context.get('cancel_backorder') is False:
+ return res
self.filtered(lambda m: m.is_subcontract and
m.state not in ['draft', 'cancel', 'done'])._update_subcontract_order_qty()
return res
@@ -88,15 +99,18 @@ class StockMove(models.Model):
for move in self:
if move.location_id.usage != 'supplier' or move.location_dest_id.usage == 'supplier':
continue
- if not move.picking_id or self.env.context.get('do_not_create_subcontract_order'):
+ if move.move_orig_ids.production_id:
continue
bom = move._get_subcontract_bom()
if not bom:
continue
+ if float_is_zero(move.product_qty, precision_rounding=move.product_uom.rounding) and\
+ move.picking_id.immediate_transfer is True:
+ raise UserError(_("To subcontract, use a planned transfer."))
subcontract_details_per_picking[move.picking_id].append((move, bom))
move.write({
'is_subcontract': True,
- 'location_id': self.picking_id.partner_id.property_stock_subcontractor.id
+ 'location_id': move.picking_id.partner_id.with_context(force_company=move.company_id.id).property_stock_subcontractor.id
})
for picking, subcontract_details in subcontract_details_per_picking.items():
picking._subcontracted_produce(subcontract_details)
@@ -154,6 +168,11 @@ operations.""") % ('\n'.join(overprocessed_moves.mapped('product_id.display_name
self.ensure_one()
return any(m.has_tracking != 'none' for m in self.move_orig_ids.production_id.move_raw_ids)
+ def _prepare_extra_move_vals(self, qty):
+ vals = super(StockMove, self)._prepare_extra_move_vals(qty)
+ vals['location_id'] = self.location_id.id
+ return vals
+
def _should_bypass_reservation(self):
""" If the move is subcontracted then ignore the reservation. """
should_bypass_reservation = super(StockMove, self)._should_bypass_reservation()
diff --git a/addons/mrp_subcontracting/models/stock_picking.py b/addons/mrp_subcontracting/models/stock_picking.py
index 734a0e51933..f638eda03a4 100644
--- a/addons/mrp_subcontracting/models/stock_picking.py
+++ b/addons/mrp_subcontracting/models/stock_picking.py
@@ -43,12 +43,7 @@ class StockPicking(models.Model):
return super(StockPicking, self).action_cancel()
def action_done(self):
- # action_done with an extra move will trigger two methods that
- # create/modify a subcontracting order, _action_confirm and a write on
- # product_uom_qty. This context will be used by _action_confirm and it
- # will not create a subcontract order. Instead the existing order will
- # be updated in the stock.move write during the merge move.
- res = super(StockPicking, self.with_context(do_not_create_subcontract_order=True)).action_done()
+ res = super(StockPicking, self).action_done()
productions = self.env['mrp.production']
for picking in self:
for move in picking.move_lines:
@@ -56,8 +51,8 @@ class StockPicking(models.Model):
continue
production = move.move_orig_ids.production_id
if move._has_tracked_subcontract_components():
- move.move_orig_ids.move_line_ids.unlink()
- move_finished_ids = move.move_orig_ids
+ move.move_orig_ids.filtered(lambda m: m.state not in ('done', 'cancel')).move_line_ids.unlink()
+ move_finished_ids = move.move_orig_ids.filtered(lambda m: m.state not in ('done', 'cancel'))
for ml in move.move_line_ids:
ml.copy({
'picking_id': False,
@@ -81,7 +76,10 @@ class StockPicking(models.Model):
produce._record_production()
productions |= production
for subcontracted_production in productions:
- subcontracted_production.button_mark_done()
+ if subcontracted_production.state == 'progress':
+ subcontracted_production.post_inventory()
+ else:
+ subcontracted_production.button_mark_done()
# For concistency, set the date on production move before the date
# on picking. (Tracability report + Product Moves menu item)
minimum_date = min(picking.move_line_ids.mapped('date'))
@@ -123,12 +121,13 @@ class StockPicking(models.Model):
product = subcontract_move.product_id
warehouse = self._get_warehouse(subcontract_move)
vals = {
+ 'company_id': subcontract_move.company_id.id,
'procurement_group_id': group.id,
'product_id': product.id,
'product_uom_id': subcontract_move.product_uom.id,
'bom_id': bom.id,
- 'location_src_id': subcontract_move.picking_id.partner_id.property_stock_subcontractor.id,
- 'location_dest_id': subcontract_move.picking_id.partner_id.property_stock_subcontractor.id,
+ 'location_src_id': subcontract_move.picking_id.partner_id.with_context(force_company=subcontract_move.company_id.id).property_stock_subcontractor.id,
+ 'location_dest_id': subcontract_move.picking_id.partner_id.with_context(force_company=subcontract_move.company_id.id).property_stock_subcontractor.id,
'product_qty': subcontract_move.product_uom_qty,
'picking_type_id': warehouse.subcontracting_type_id.id
}
@@ -137,7 +136,7 @@ class StockPicking(models.Model):
def _subcontracted_produce(self, subcontract_details):
self.ensure_one()
for move, bom in subcontract_details:
- mo = self.env['mrp.production'].create(self._prepare_subcontract_mo_vals(move, bom))
+ mo = self.env['mrp.production'].with_context(force_company=move.company_id.id).create(self._prepare_subcontract_mo_vals(move, bom))
self.env['stock.move'].create(mo._get_moves_raw_values())
mo.action_confirm()