Add module sale_mrp_usability (backport of a feature of v14)
This commit is contained in:
2
sale_mrp_usability/models/__init__.py
Normal file
2
sale_mrp_usability/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import sale
|
||||
from . import mrp_production
|
||||
39
sale_mrp_usability/models/mrp_production.py
Normal file
39
sale_mrp_usability/models/mrp_production.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# Backport from Odoo v14
|
||||
# Copyright Odoo SA
|
||||
# Same licence as Odoo (LGPL)
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = 'mrp.production'
|
||||
|
||||
sale_order_count = fields.Integer(
|
||||
"Count of Source SO",
|
||||
compute='_compute_sale_order_count',
|
||||
groups='sales_team.group_sale_salesman')
|
||||
|
||||
@api.depends('move_dest_ids.group_id.sale_id')
|
||||
def _compute_sale_order_count(self):
|
||||
for production in self:
|
||||
production.sale_order_count = len(production.move_dest_ids.mapped('group_id').mapped('sale_id'))
|
||||
|
||||
def action_view_sale_orders(self):
|
||||
self.ensure_one()
|
||||
sale_order_ids = self.move_dest_ids.mapped('group_id').mapped('sale_id').ids
|
||||
action = {
|
||||
'res_model': 'sale.order',
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
if len(sale_order_ids) == 1:
|
||||
action.update({
|
||||
'view_mode': 'form',
|
||||
'res_id': sale_order_ids[0],
|
||||
})
|
||||
else:
|
||||
action.update({
|
||||
'name': _("Sources Sale Orders of %s" % self.name),
|
||||
'domain': [('id', 'in', sale_order_ids)],
|
||||
'view_mode': 'tree,form',
|
||||
})
|
||||
return action
|
||||
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