Add module sale_mrp_usability (backport of a feature of v14)
This commit is contained in:
39
sale_mrp_usability/models/sale.py
Normal file
39
sale_mrp_usability/models/sale.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# This code is a backport from odoo v14
|
||||
# Copyright Odoo SA
|
||||
# Same licence as Odoo (LGPL)
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
mrp_production_count = fields.Integer(
|
||||
"Count of MO generated",
|
||||
compute='_compute_mrp_production_count',
|
||||
groups='mrp.group_mrp_user')
|
||||
|
||||
@api.depends('procurement_group_id.stock_move_ids.created_production_id')
|
||||
def _compute_mrp_production_count(self):
|
||||
for sale in self:
|
||||
sale.mrp_production_count = len(sale.procurement_group_id.stock_move_ids.mapped('created_production_id'))
|
||||
|
||||
def action_view_mrp_production(self):
|
||||
self.ensure_one()
|
||||
mrp_production_ids = self.procurement_group_id.stock_move_ids.mapped('created_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 Orders Generated by %s" % self.name),
|
||||
'domain': [('id', 'in', mrp_production_ids)],
|
||||
'view_mode': 'tree,form',
|
||||
})
|
||||
return action
|
||||
Reference in New Issue
Block a user