summaryrefslogtreecommitdiff
path: root/addons/mrp_subcontracting/models
diff options
context:
space:
mode:
Diffstat (limited to 'addons/mrp_subcontracting/models')
-rw-r--r--addons/mrp_subcontracting/models/stock_move.py25
-rw-r--r--addons/mrp_subcontracting/models/stock_picking.py34
2 files changed, 40 insertions, 19 deletions
diff --git a/addons/mrp_subcontracting/models/stock_move.py b/addons/mrp_subcontracting/models/stock_move.py
index 72f50c9374e..e33f5377c0b 100644
--- a/addons/mrp_subcontracting/models/stock_move.py
+++ b/addons/mrp_subcontracting/models/stock_move.py
@@ -126,12 +126,21 @@ class StockMove(models.Model):
return res
def _action_record_components(self):
- action = self.env.ref('mrp.act_mrp_product_produce').read()[0]
- action['context'] = dict(
- default_production_id=self.move_orig_ids.production_id.id,
- default_subcontract_move_id=self.id
- )
- return action
+ self.ensure_one()
+ production = self.move_orig_ids.production_id
+ view = self.env.ref('mrp.mrp_production_form_view')
+ return {
+ 'name': _('Subcontract'),
+ 'type': 'ir.actions.act_window',
+ 'view_mode': 'form',
+ 'res_model': 'mrp.production',
+ 'views': [(view.id, 'form')],
+ 'view_id': view.id,
+ 'target': 'new',
+ 'res_id': production.id,
+ 'context': dict(self.env.context, subcontract_move_id=self.id),
+ }
+
def _check_overprocessed_subcontract_qty(self):
""" If a subcontracted move use tracked components. Do not allow to add
@@ -147,8 +156,8 @@ class StockMove(models.Model):
if not move._has_tracked_subcontract_components():
continue
rounding = move.product_uom.rounding
- if float_compare(move.quantity_done, move.move_orig_ids.production_id.qty_produced, precision_rounding=rounding) > 0:
- overprocessed_moves |= move
+# if float_compare(move.quantity_done, move.move_orig_ids.production_id.qty_produced, precision_rounding=rounding) > 0:
+# overprocessed_moves |= move
if overprocessed_moves:
raise UserError(_("""
You have to use 'Records Components' button in order to register quantity for a
diff --git a/addons/mrp_subcontracting/models/stock_picking.py b/addons/mrp_subcontracting/models/stock_picking.py
index 29c44aec51b..0ab1655a6dc 100644
--- a/addons/mrp_subcontracting/models/stock_picking.py
+++ b/addons/mrp_subcontracting/models/stock_picking.py
@@ -4,6 +4,7 @@
from datetime import timedelta
from odoo import api, fields, models
+from odoo.tools import float_is_zero
class StockPicking(models.Model):
@@ -43,7 +44,9 @@ class StockPicking(models.Model):
for move in picking.move_lines:
if not move.is_subcontract:
continue
- production = move.move_orig_ids.production_id
+ production = move.move_orig_ids.production_id.filtered(lambda p: p.state not in ('done', 'cancel'))
+ if len(production) > 1:
+ production = production[-1]
if move._has_tracked_subcontract_components():
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'))
@@ -58,16 +61,25 @@ class StockPicking(models.Model):
'location_dest_id': move_finished_ids.location_dest_id.id,
})
else:
- for move_line in move.move_line_ids:
- produce = self.env['mrp.product.produce'].with_context(default_production_id=production.id).create({
- 'production_id': production.id,
- 'qty_producing': move_line.qty_done,
- 'product_uom_id': move_line.product_uom_id.id,
- 'finished_lot_id': move_line.lot_id.id,
- 'consumption': 'strict',
- })
- produce._generate_produce_lines()
- produce._record_production()
+ if not move.move_line_ids.lot_id:
+ qty_done_production_uom = move.product_uom._compute_quantity(move.quantity_done, production.product_uom_id)
+ production.qty_producing += qty_done_production_uom
+ for move in (production.move_raw_ids | production.move_finished_ids.filtered(lambda m: m.product_id != production.product_id)):
+ if move.state in ('done', 'cancel'):
+ continue
+ if float_is_zero(move.product_uom_qty, precision_rounding=move.product_uom.rounding):
+ continue
+ new_qty = production.product_uom_id._compute_quantity(
+ (production.qty_producing - production.qty_produced) * move.unit_factor, production.product_uom_id,
+ rounding_method='HALF-UP')
+ move.move_line_ids.filtered(lambda ml: ml.state not in ('done', 'cancel')).qty_done = 0
+ vals = move._set_quantity_done_prepare_vals(new_qty)
+ if vals['to_create']:
+ for res in vals['to_create']:
+ move.move_line_ids.create(res)
+ if vals['to_write']:
+ for move_line, res in vals['to_write']:
+ move_line.write(res)
productions |= production
for subcontracted_production in productions:
if subcontracted_production.state == 'progress':