diff options
| author | Rémy Voet (ryv) <ryv@odoo.com> | 2020-01-08 14:58:18 +0000 |
|---|---|---|
| committer | Rémy Voet (ryv) <ryv@odoo.com> | 2020-01-24 12:04:47 +0000 |
| commit | b0d22b5752d483da0534dad00b7f35dd11612804 (patch) | |
| tree | 0af97a761a764a47caf5c08aaa89ffb9ca684e2e /addons/purchase_mrp/models | |
| parent | e1b3a17c3bda2b2d585d930386244e3f2b0bed31 (diff) | |
[IMP] purchase_mrp: link MO<->MO<->PO in case of MTO
In case of MTO (+buy) on products used in a MO,
add the link between the MO source and the PO generated.
Also add links between MO's when MTO+manufacturing.
task-1913392
closes odoo/odoo#43366
Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
Diffstat (limited to 'addons/purchase_mrp/models')
| -rw-r--r-- | addons/purchase_mrp/models/__init__.py | 5 | ||||
| -rw-r--r-- | addons/purchase_mrp/models/mrp_production.py | 44 | ||||
| -rw-r--r-- | addons/purchase_mrp/models/purchase.py (renamed from addons/purchase_mrp/models/purchase_mrp.py) | 56 | ||||
| -rw-r--r-- | addons/purchase_mrp/models/stock_move.py | 14 |
4 files changed, 97 insertions, 22 deletions
diff --git a/addons/purchase_mrp/models/__init__.py b/addons/purchase_mrp/models/__init__.py index 6b81dc1791b..dd92304f80a 100644 --- a/addons/purchase_mrp/models/__init__.py +++ b/addons/purchase_mrp/models/__init__.py @@ -1,3 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import purchase_mrp
\ No newline at end of file + +from . import purchase +from . import mrp_production +from . import stock_move diff --git a/addons/purchase_mrp/models/mrp_production.py b/addons/purchase_mrp/models/mrp_production.py new file mode 100644 index 00000000000..87cc432dacc --- /dev/null +++ b/addons/purchase_mrp/models/mrp_production.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models, _ + + +class MrpProduction(models.Model): + _inherit = 'mrp.production' + + purchase_order_count = fields.Integer( + "Count of generated PO", + compute='_compute_purchase_order_count', + groups='purchase.group_purchase_user') + + @api.depends('procurement_group_id.stock_move_ids.created_purchase_line_id.order_id') + def _compute_purchase_order_count(self): + for production in self: + production.purchase_order_count = len(production.procurement_group_id.stock_move_ids.created_purchase_line_id.order_id) + + def action_view_purchase_orders(self): + self.ensure_one() + purchase_order_ids = self.procurement_group_id.stock_move_ids.created_purchase_line_id.order_id.ids + action = { + 'res_model': 'purchase.order', + 'type': 'ir.actions.act_window', + } + if len(purchase_order_ids) == 1: + action.update({ + 'view_mode': 'form', + 'res_id': purchase_order_ids[0], + }) + else: + action.update({ + 'name': _("Purchase Order generated from %s" % self.name), + 'domain': [('id', 'in', purchase_order_ids)], + 'view_mode': 'tree,form', + }) + return action + + def _get_document_iterate_key(self, move_raw_id): + iterate_key = super(MrpProduction, self)._get_document_iterate_key(move_raw_id) + if not iterate_key and move_raw_id.created_purchase_line_id: + iterate_key = 'created_purchase_line_id' + return iterate_key diff --git a/addons/purchase_mrp/models/purchase_mrp.py b/addons/purchase_mrp/models/purchase.py index 1f644978b35..f1e591372d3 100644 --- a/addons/purchase_mrp/models/purchase_mrp.py +++ b/addons/purchase_mrp/models/purchase.py @@ -1,19 +1,43 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import api, fields, models -from odoo.tools import float_compare +from odoo import api, fields, models, _ + + +class PurchaseOrder(models.Model): + _inherit = 'purchase.order' + + mrp_production_count = fields.Integer( + "Count of MO Source", + compute='_compute_mrp_production_count', + groups='mrp.group_mrp_user') + + @api.depends('order_line.move_dest_ids.group_id.mrp_production_id') + def _compute_mrp_production_count(self): + for purchase in self: + purchase.mrp_production_count = len(purchase.order_line.move_dest_ids.group_id.mrp_production_id) + + def action_view_mrp_productions(self): + self.ensure_one() + mrp_production_ids = self.order_line.move_dest_ids.group_id.mrp_production_id.ids + action = { + 'res_model': 'mrp.production', + 'type': 'ir.actions.act_window', + } + if len(mrp_production_ids) == 1: + action.update({ + 'view_mode': 'form', + 'res_id': mrp_production_ids[0], + }) + else: + action.update({ + 'name': _("Manufacturing Source of %s" % self.name), + 'domain': [('id', 'in', mrp_production_ids)], + 'view_mode': 'tree,form', + }) + return action -class MrpProduction(models.Model): - _inherit = 'mrp.production' - - def _get_document_iterate_key(self, move_raw_id): - iterate_key = super(MrpProduction, self)._get_document_iterate_key(move_raw_id) - if not iterate_key and move_raw_id.created_purchase_line_id: - iterate_key = 'created_purchase_line_id' - return iterate_key - class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' @@ -33,13 +57,3 @@ class PurchaseOrderLine(models.Model): def _get_upstream_documents_and_responsibles(self, visited): return [(self.order_id, self.order_id.user_id, visited)] - -class StockMove(models.Model): - _inherit = 'stock.move' - - def _prepare_phantom_move_values(self, bom_line, product_qty, quantity_done): - vals = super(StockMove, self)._prepare_phantom_move_values(bom_line, product_qty, quantity_done) - if self.purchase_line_id: - vals['purchase_line_id'] = self.purchase_line_id.id - return vals - diff --git a/addons/purchase_mrp/models/stock_move.py b/addons/purchase_mrp/models/stock_move.py new file mode 100644 index 00000000000..849a2354d7b --- /dev/null +++ b/addons/purchase_mrp/models/stock_move.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + + +class StockMove(models.Model): + _inherit = 'stock.move' + + def _prepare_phantom_move_values(self, bom_line, product_qty, quantity_done): + vals = super(StockMove, self)._prepare_phantom_move_values(bom_line, product_qty, quantity_done) + if self.purchase_line_id: + vals['purchase_line_id'] = self.purchase_line_id.id + return vals |
