feat(receiving): SO auto-create + MRP soft gate + menu structure
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,4 +2,54 @@
|
||||
# Copyright 2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
# Part of the Fusion Plating product family.
|
||||
# Placeholder — implemented in a later task.
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import models, _
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = 'mrp.production'
|
||||
|
||||
def action_confirm(self):
|
||||
"""Soft gate: warn if parts haven't been received yet.
|
||||
|
||||
Checks the linked sale order's receiving status. If parts
|
||||
are not yet received, logs a warning. This is informational
|
||||
only -- it does not block confirmation. The gate is soft
|
||||
because handshake deals and urgent jobs need flexibility.
|
||||
"""
|
||||
for production in self:
|
||||
so = production._get_source_sale_order()
|
||||
if so and so.x_fc_receiving_status in ('not_received', False):
|
||||
_logger.warning(
|
||||
'MO %s: parts not yet received for SO %s (receiving status: %s). '
|
||||
'Proceeding with confirmation.',
|
||||
production.name, so.name, so.x_fc_receiving_status,
|
||||
)
|
||||
production.message_post(
|
||||
body=_(
|
||||
'Warning: Parts not yet received for sale order '
|
||||
'<a href="/odoo/sale-order/%s">%s</a>. '
|
||||
'Manufacturing confirmed without receiving verification.'
|
||||
) % (so.id, so.name),
|
||||
)
|
||||
return super().action_confirm()
|
||||
|
||||
def _get_source_sale_order(self):
|
||||
"""Find the sale order linked to this MO via origin field."""
|
||||
self.ensure_one()
|
||||
if not self.origin:
|
||||
return False
|
||||
# origin may contain SO name like "S00001" or configurator ref "CFG-00001"
|
||||
so = self.env['sale.order'].search(
|
||||
[('name', '=', self.origin)], limit=1,
|
||||
)
|
||||
if not so:
|
||||
# Try matching by origin containing the SO name
|
||||
so = self.env['sale.order'].search(
|
||||
[('name', 'ilike', self.origin)], limit=1,
|
||||
)
|
||||
return so or False
|
||||
|
||||
@@ -2,4 +2,62 @@
|
||||
# Copyright 2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
# Part of the Fusion Plating product family.
|
||||
# Placeholder — implemented in a later task.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
x_fc_receiving_ids = fields.One2many(
|
||||
'fp.receiving', 'sale_order_id', string='Receiving Records',
|
||||
)
|
||||
x_fc_receiving_count = fields.Integer(
|
||||
string='Receiving Count', compute='_compute_receiving_count',
|
||||
)
|
||||
|
||||
@api.depends('x_fc_receiving_ids')
|
||||
def _compute_receiving_count(self):
|
||||
for rec in self:
|
||||
rec.x_fc_receiving_count = len(rec.x_fc_receiving_ids)
|
||||
|
||||
def action_confirm(self):
|
||||
"""Override to auto-create receiving record on SO confirmation."""
|
||||
res = super().action_confirm()
|
||||
for order in self:
|
||||
# Only create if no receiving record exists yet
|
||||
if not order.x_fc_receiving_ids:
|
||||
total_qty = sum(order.order_line.mapped('product_uom_qty'))
|
||||
receiving_vals = {
|
||||
'sale_order_id': order.id,
|
||||
'expected_qty': int(total_qty),
|
||||
'line_ids': [],
|
||||
}
|
||||
# Auto-create lines from SO lines
|
||||
for line in order.order_line:
|
||||
receiving_vals['line_ids'].append((0, 0, {
|
||||
'part_number': order.x_fc_part_catalog_id.part_number if order.x_fc_part_catalog_id else '',
|
||||
'description': line.name or '',
|
||||
'expected_qty': int(line.product_uom_qty),
|
||||
}))
|
||||
self.env['fp.receiving'].create(receiving_vals)
|
||||
return res
|
||||
|
||||
def action_view_receiving(self):
|
||||
"""Smart button action to view receiving records."""
|
||||
self.ensure_one()
|
||||
if self.x_fc_receiving_count == 1:
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'fp.receiving',
|
||||
'res_id': self.x_fc_receiving_ids[0].id,
|
||||
'view_mode': 'form',
|
||||
'target': 'current',
|
||||
}
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'fp.receiving',
|
||||
'view_mode': 'list,form',
|
||||
'domain': [('sale_order_id', '=', self.id)],
|
||||
'target': 'current',
|
||||
}
|
||||
|
||||
@@ -1,2 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo></odoo>
|
||||
<!--
|
||||
Copyright 2026 Nexa Systems Inc.
|
||||
License OPL-1 (Odoo Proprietary License v1.0)
|
||||
Part of the Fusion Plating product family.
|
||||
-->
|
||||
<odoo>
|
||||
|
||||
<!-- ===== Window actions (defined BEFORE menus) ===== -->
|
||||
<record id="action_fp_receiving_pending" model="ir.actions.act_window">
|
||||
<field name="name">Pending Inspection</field>
|
||||
<field name="res_model">fp.receiving</field>
|
||||
<field name="view_mode">list,form</field>
|
||||
<field name="domain">[('state', '=', 'draft')]</field>
|
||||
</record>
|
||||
|
||||
<record id="action_fp_receiving_discrepancy" model="ir.actions.act_window">
|
||||
<field name="name">Discrepancies</field>
|
||||
<field name="res_model">fp.receiving</field>
|
||||
<field name="view_mode">list,form</field>
|
||||
<field name="domain">[('state', '=', 'discrepancy')]</field>
|
||||
</record>
|
||||
|
||||
<!-- ===== RECEIVING & INSPECTION submenu ===== -->
|
||||
<menuitem id="menu_fp_receiving_root"
|
||||
name="Receiving & Inspection"
|
||||
parent="fusion_plating.menu_fp_root"
|
||||
sequence="5"
|
||||
groups="group_fp_receiving"/>
|
||||
|
||||
<menuitem id="menu_fp_receiving_all"
|
||||
name="All Receiving"
|
||||
parent="menu_fp_receiving_root"
|
||||
action="action_fp_receiving"
|
||||
sequence="10"/>
|
||||
|
||||
<menuitem id="menu_fp_receiving_pending"
|
||||
name="Pending Inspection"
|
||||
parent="menu_fp_receiving_root"
|
||||
action="action_fp_receiving_pending"
|
||||
sequence="20"/>
|
||||
|
||||
<menuitem id="menu_fp_receiving_discrepancy"
|
||||
name="Discrepancies"
|
||||
parent="menu_fp_receiving_root"
|
||||
action="action_fp_receiving_discrepancy"
|
||||
sequence="30"/>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -1,2 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo></odoo>
|
||||
<!--
|
||||
Copyright 2026 Nexa Systems Inc.
|
||||
License OPL-1 (Odoo Proprietary License v1.0)
|
||||
Part of the Fusion Plating product family.
|
||||
-->
|
||||
<odoo>
|
||||
|
||||
<!-- ===== Smart button: Receiving on SO form ===== -->
|
||||
<record id="view_sale_order_form_receiving" model="ir.ui.view">
|
||||
<field name="name">sale.order.form.fp.receiving</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale.view_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@name='button_box']" position="inside">
|
||||
<button name="action_view_receiving" type="object"
|
||||
class="oe_stat_button" icon="fa-truck"
|
||||
invisible="x_fc_receiving_count == 0">
|
||||
<field name="x_fc_receiving_count" widget="statinfo" string="Receiving"/>
|
||||
</button>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user