Add module sale_mrp_usability (backport of a feature of v14)

This commit is contained in:
Alexis de Lattre
2021-05-27 23:58:03 +02:00
parent dbbd14f58a
commit 25a177eb76
8 changed files with 152 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,23 @@
# Copyright 2021 Akretion France (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Sale MRP Usability',
'version': '12.0.1.0.0',
'category': 'Sales',
'license': 'AGPL-3',
'summary': 'Usability improvements on sale_mrp module',
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': [
'sale_mrp',
'stock_usability',
],
'data': [
# Native in v14. Do no up-port to v14
'views/mrp_production.xml',
'views/sale_order.xml',
],
'installable': True,
}

View File

@@ -0,0 +1,2 @@
from . import sale
from . import mrp_production

View 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

View 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

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Backport from odoo v14
Copyright Odoo SA
Same licence as Odoo (LGPL) -->
<odoo>
<record id="mrp_production_form_view" model="ir.ui.view">
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view"/>
<field name="groups_id" eval="[(6, 0, [ref('sales_team.group_sale_salesman_all_leads')])]"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button class="oe_stat_button" name="action_view_sale_orders" type="object" icon="fa-dollar" attrs="{'invisible': [('sale_order_count', '=', 0)]}" groups="sales_team.group_sale_salesman">
<div class="o_field_widget o_stat_info">
<span class="o_stat_value"><field name="sale_order_count"/></span>
<span class="o_stat_text">Sales</span>
</div>
</button>
</xpath>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Backport from Odoo v14
Copyright Odoo SA
Same licence as Odoo (LGPL)
-->
<odoo>
<record id="view_order_form" model="ir.ui.view">
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="groups_id" eval="[(6, 0, [ref('mrp.group_mrp_user')])]"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button class="oe_stat_button" name="action_view_mrp_production" type="object" icon="fa-wrench" attrs="{'invisible': [('mrp_production_count', '=', 0)]}" groups="mrp.group_mrp_user">
<div class="o_field_widget o_stat_info">
<span class="o_stat_value"><field name="mrp_production_count"/></span>
<span class="o_stat_text">Manufacturing</span>
</div>
</button>
</xpath>
</field>
</record>
</odoo>

View File

@@ -12,6 +12,9 @@ logger = logging.getLogger(__name__)
class ProcurementGroup(models.Model):
_inherit = 'procurement.group'
# this field stock_move_ids is native in v14
stock_move_ids = fields.One2many('stock.move', 'group_id', string="Related Stock Moves")
@api.model
def _procure_orderpoint_confirm(
self, use_new_cursor=False, company_id=False):