[IMP] sale_mrp: show MTO MOs in SOs portal

In order to provide more transparency, we display any MOs linked to a
SOs via MTO linkage. This includes linkages made via reception report.

Part of Task: 2662730

closes odoo/odoo#79627

Signed-off-by: Arnold Moyaux <arm@odoo.com>
This commit is contained in:
Tiffany Chang (tic)
2022-01-20 12:30:05 +00:00
parent b3fffea631
commit c899bfcd84
5 changed files with 55 additions and 14 deletions
+1
View File
@@ -177,6 +177,7 @@ class CustomerPortal(portal.CustomerPortal):
'partner_id': order_sudo.partner_id.id,
'report_type': 'html',
'action': order_sudo._get_portal_return_action(),
**order_sudo._get_additional_order_page_values(),
}
if order_sudo.company_id:
values['res_company'] = order_sudo.company_id
+4
View File
@@ -1103,6 +1103,10 @@ class SaleOrder(models.Model):
self.ensure_one()
return self.env.ref('sale.action_quotations_with_onboarding')
def _get_additional_order_page_values(self):
""" Return a dict of additional order page values for a sale.order."""
return {}
@api.model
def _prepare_down_payment_section_line(self, **optional_values):
"""
+2 -1
View File
@@ -17,7 +17,8 @@ from sales order. It adds sales name and sales Reference on production order.
'data': [
'security/ir.model.access.csv',
'views/mrp_production_views.xml',
'views/sale_order_views.xml'
'views/sale_order_views.xml',
'views/sale_portal_templates.xml'
],
'demo': [],
'installable': True,
+19 -13
View File
@@ -9,43 +9,49 @@ class SaleOrder(models.Model):
mrp_production_count = fields.Integer(
"Count of MO generated",
compute='_compute_mrp_production_count',
compute='_compute_mrp_production_ids',
groups='mrp.group_mrp_user')
mrp_production_ids = fields.Many2many(
'mrp.production',
compute='_compute_mrp_production_ids',
string='Manufacturing orders associated with this sales order.',
groups='mrp.group_mrp_user')
@api.depends('procurement_group_id.stock_move_ids.created_production_id.procurement_group_id.mrp_production_ids')
def _compute_mrp_production_count(self):
def _compute_mrp_production_ids(self):
data = self.env['procurement.group'].read_group([('sale_id', 'in', self.ids)], ['ids:array_agg(id)'], ['sale_id'])
mrp_count = dict()
mrp_productions = dict()
for item in data:
procurement_groups = self.env['procurement.group'].browse(item['ids'])
mrp_count[item['sale_id'][0]] = len(
set(procurement_groups.stock_move_ids.created_production_id.procurement_group_id.mrp_production_ids.ids) |
set(procurement_groups.mrp_production_ids.ids))
mrp_productions[item['sale_id'][0]] = procurement_groups.stock_move_ids.created_production_id.procurement_group_id.mrp_production_ids | procurement_groups.mrp_production_ids
for sale in self:
sale.mrp_production_count = mrp_count.get(sale.id)
mrp_production_ids = mrp_productions.get(sale.id, self.env['mrp.production'])
sale.mrp_production_count = len(mrp_production_ids)
sale.mrp_production_ids = mrp_production_ids
def action_view_mrp_production(self):
self.ensure_one()
procurement_groups = self.env['procurement.group'].search([('sale_id', 'in', self.ids)])
mrp_production_ids = set(procurement_groups.stock_move_ids.created_production_id.procurement_group_id.mrp_production_ids.ids) |\
set(procurement_groups.mrp_production_ids.ids)
action = {
'res_model': 'mrp.production',
'type': 'ir.actions.act_window',
}
if len(mrp_production_ids) == 1:
if len(self.mrp_production_ids) == 1:
action.update({
'view_mode': 'form',
'res_id': mrp_production_ids.pop(),
'res_id': self.mrp_production_ids.id,
})
else:
action.update({
'name': _("Manufacturing Orders Generated by %s", self.name),
'domain': [('id', 'in', list(mrp_production_ids))],
'domain': [('id', 'in', self.mrp_production_ids.ids)],
'view_mode': 'tree,form',
})
return action
def _get_additional_order_page_values(self):
rendering_context_values = super()._get_additional_order_page_values()
rendering_context_values['mrp_production_ids'] = self.mrp_production_ids
return rendering_context_values
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="sale_order_portal_content_inherit_sale_mrp" name="Orders MOs" inherit_id="sale.sale_order_portal_content">
<xpath expr="//div[@id='informations']" position="inside">
<t t-if="mrp_production_ids">
<div>
<strong>Manufacturing Orders</strong>
</div>
<div>
<t t-foreach="mrp_production_ids" t-as="mo">
<div class="d-flex flex-wrap align-items-center justify-content-between o_sale_stock_picking">
<div>
<span t-out="mo.name"/>
<div class="small d-lg-inline-block ml-3">Date:
<span class="text-muted" t-field="mo.date_finished" t-options="{'date_only': True}"/>
<span t-if="mo.state in ['draft', 'confirmed', 'progress', 'to_close']" class="text-muted" t-field="mo.date_planned_finished" t-options="{'date_only': True}"/>
</div>
</div>
<span t-if="mo.state in ['to_close', 'done']" class="small badge badge-success orders_label_text_align"><i class="fa fa-fw fa-check"/> <b>Manufactured</b></span>
<span t-if="mo.state == 'cancel'" class="small badge badge-danger orders_label_text_align"><i class="fa fa-fw fa-times"/> <b>Cancelled</b></span>
<span t-if="mo.state in ['confirmed']" class="small badge badge-info orders_label_text_align"><i class="fa fa-fw fa-clock-o"/> <b>Confirmed</b></span>
<span t-if="mo.state in ['progress']" class="small badge badge-warning orders_label_text_align"><i class="fa fa-fw fa-clock-o"/> <b>In progress</b></span>
</div>
</t>
</div>
</t>
</xpath>
</template>
</odoo>