add customer name and upstream production to work orders. Add customer name to shop floor view on MOs.

This commit is contained in:
Marc Durepos 2024-07-03 08:44:34 -04:00
parent afb4d84e8f
commit ddaee59a59
8 changed files with 135 additions and 22 deletions

View file

@ -18,17 +18,23 @@
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
# #
{ {
'name': 'Client Name on Manufacturing Order', "name": "Client Name on Manufacturing Order",
'version': '17.0.1.0.0', "version": "17.0.2.0.0",
'summary': 'Show the customer name on manufacturing order views.', "summary": "Show the customer name on manufacturing order views.",
'category': 'Manufacturing', "category": "Manufacturing",
'author': 'Bemade Inc.', "author": "Bemade Inc.",
'website': 'http://www.bemade.org', "website": "http://www.bemade.org",
'license': 'LGPL-3', "license": "LGPL-3",
'depends': ['sale_mrp'], "depends": ["sale_mrp", "mrp_workorder", "web"],
'data': [ "data": [
'views/mrp_production_views.xml', "views/mrp_production_views.xml",
], ],
'installable': True, 'assets': {
'auto_install': False 'web.assets_backend': [
'client_name_on_manufacturing_orders/static/src/**/*.xml',
'client_name_on_manufacturing_orders/static/src/**/*.js',
]
},
"installable": True,
"auto_install": False,
} }

View file

@ -2,20 +2,40 @@ from odoo import models, fields, api
class MrpProduction(models.Model): class MrpProduction(models.Model):
_inherit = 'mrp.production' _inherit = "mrp.production"
customer_ids = fields.Many2many( customer_ids = fields.Many2many(
comodel_name='res.partner', comodel_name="res.partner",
compute="_compute_customers", compute="_compute_customers",
string="Customers", string="Customers",
store=True,
compute_sudo=True,
) )
@api.depends('procurement_group_id') upstream_production_ids = fields.Many2many(
comodel_name="mrp.production",
relation="mrp_production_upstream_rel",
column1="production_id",
column2="upstream_production_id",
compute="_compute_upstream_production_ids",
string="Upstream Manufacturing Orders",
store=True,
compute_sudo=True,
)
@api.depends("procurement_group_id")
def _compute_customers(self): def _compute_customers(self):
for rec in self: for rec in self:
rec.customer_ids = (rec.mapped('procurement_group_id'). rec.customer_ids = (
mapped('mrp_production_ids'). rec.mapped("procurement_group_id")
mapped('move_dest_ids'). .mapped("mrp_production_ids")
mapped('group_id'). .mapped("move_dest_ids")
mapped('sale_id'). .mapped("group_id")
mapped('partner_id').ids) .mapped("sale_id")
.mapped("partner_id")
.ids
)
def _compute_upstream_production_ids(self):
for rec in self:
rec.upstream_production_ids = rec._get_sources().ids

View file

@ -0,0 +1,27 @@
from odoo import models, fields, api
class MrpWorkorder(models.Model):
_inherit = "mrp.workorder"
customer_ids = fields.Many2many(
comodel_name="res.partner",
compute="_compute_customer_ids",
string="Customers",
)
upstream_production_ids = fields.Many2many(
comodel_name="mrp.production",
compute="_compute_upstream_production_ids",
string="Upstream Manufacturing Orders",
)
@api.depends("production_id.customer_ids")
def _compute_customer_ids(self):
for rec in self:
rec.customer_ids = rec.production_id.customer_ids
@api.depends("production_id.upstream_production_ids")
def _compute_upstream_production_ids(self):
for rec in self:
rec.upstream_production_ids = rec.production_id.upstream_production_ids

View file

@ -0,0 +1,18 @@
/** @odoo-module **/
import {MrpDisplay} from "@mrp_workorder/mrp_display/mrp_display";
import {patch} from "@web/core/utils/patch";
patch(MrpDisplay.prototype, {
_makeModelParams() {
var params = super._makeModelParams();
const customerFields = this.props.models.find(
(m) => m.resModel === "res.partner"
).fields;
params.config.activeFields.customer_ids.related = {
fields: customerFields,
activeFields: customerFields,
};
return params;
},
});

View file

@ -0,0 +1,14 @@
/** @odoo-module **/
import {MrpDisplayAction} from "@mrp_workorder/mrp_display/mrp_display_action";
import {patch} from "@web/core/utils/patch";
patch(MrpDisplayAction.prototype, {
get fieldsStructure() {
const vals = super.fieldsStructure;
vals["mrp.production"].push("customer_ids", "upstream_production_ids");
vals["mrp.workorder"].push("customer_ids", "upstream_production_ids");
vals["res.partner"] = ["id", "display_name"];
return vals;
},
});

View file

@ -0,0 +1,9 @@
/** @odoo-module **/
import {Many2ManyTagsField} from "@web/views/fields/many2many_tags/many2many_tags_field";
import {MrpDisplayRecord} from "@mrp_workorder/mrp_display/mrp_display_record";
MrpDisplayRecord.components = {
...MrpDisplayRecord.components,
Many2ManyTagsField,
};

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserver">
<t t-inherit="mrp_workorder.MrpDisplayRecord" t-inherit-mode="extension">
<xpath expr="//div[hasclass('card-header')]" position="inside">
<t
t-if="props.record.data.customer_ids &amp;&amp; props.record.data.customer_ids.records"
>
<Many2ManyTagsField
name="'customer_ids'"
record="props.record"
canCreate="false"
canCreateEdit="false"
canQuickCreate="false"
readonly="true"
/>
</t>
</xpath>
</t>
</templates>