summaryrefslogtreecommitdiff
path: root/addons/purchase_mrp/models/mrp_production.py
diff options
context:
space:
mode:
Diffstat (limited to 'addons/purchase_mrp/models/mrp_production.py')
-rw-r--r--addons/purchase_mrp/models/mrp_production.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/addons/purchase_mrp/models/mrp_production.py b/addons/purchase_mrp/models/mrp_production.py
new file mode 100644
index 00000000..c979c4ad
--- /dev/null
+++ b/addons/purchase_mrp/models/mrp_production.py
@@ -0,0 +1,45 @@
+# -*- 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', 'procurement_group_id.stock_move_ids.move_orig_ids.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 |
+ production.procurement_group_id.stock_move_ids.move_orig_ids.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 | self.procurement_group_id.stock_move_ids.move_orig_ids.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