Compare commits
20 Commits
fusion_acc
...
b85e208856
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b85e208856 | ||
|
|
e3001b5297 | ||
|
|
97c733b7c3 | ||
|
|
94eb7ef415 | ||
|
|
3f807d0152 | ||
|
|
842efd828c | ||
|
|
2476961f50 | ||
|
|
6b4b0c9eb7 | ||
|
|
31bd8d1e56 | ||
|
|
d437d1d959 | ||
|
|
43a26b6849 | ||
|
|
059276886d | ||
|
|
9642a07306 | ||
|
|
f55022c3d6 | ||
|
|
f0c3661277 | ||
|
|
6fa4140d11 | ||
|
|
e34c1bcc8d | ||
|
|
95db3aff0f | ||
|
|
9423a93961 | ||
|
|
057157587d |
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "Fusion Plating — MRP Bridge",
|
"name": "Fusion Plating — MRP Bridge",
|
||||||
'version': '19.0.6.10.0',
|
'version': '19.0.7.0.0',
|
||||||
'category': 'Manufacturing/Plating',
|
'category': 'Manufacturing/Plating',
|
||||||
'summary': 'Bridge Fusion Plating facilities, baths and tanks to Odoo MRP work orders.',
|
'summary': 'Bridge Fusion Plating facilities, baths and tanks to Odoo MRP work orders.',
|
||||||
'description': """
|
'description': """
|
||||||
@@ -58,6 +58,7 @@ Copyright (c) 2026 Nexa Systems Inc. All rights reserved.
|
|||||||
'data': [
|
'data': [
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'data/fp_work_role_data.xml',
|
'data/fp_work_role_data.xml',
|
||||||
|
'data/fp_cron_data.xml',
|
||||||
'wizard/fp_recipe_config_wizard_views.xml',
|
'wizard/fp_recipe_config_wizard_views.xml',
|
||||||
'views/mrp_workcenter_views.xml',
|
'views/mrp_workcenter_views.xml',
|
||||||
'views/mrp_workorder_views.xml',
|
'views/mrp_workorder_views.xml',
|
||||||
|
|||||||
@@ -58,6 +58,28 @@ class MrpProduction(models.Model):
|
|||||||
compute='_compute_override_count',
|
compute='_compute_override_count',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# ---- WO grouping + start-at-node (from direct-order wizard Phases B/C) ----
|
||||||
|
x_fc_wo_group_tag = fields.Char(
|
||||||
|
string='WO Group Tag',
|
||||||
|
help='Free-text tag shared by all SO lines batched into this MO. '
|
||||||
|
'Blank means the MO is for a single untagged line.',
|
||||||
|
tracking=True,
|
||||||
|
)
|
||||||
|
x_fc_sale_order_line_ids = fields.Many2many(
|
||||||
|
'sale.order.line',
|
||||||
|
'fp_mrp_production_sale_order_line_rel',
|
||||||
|
'production_id', 'sale_order_line_id',
|
||||||
|
string='Source SO Lines',
|
||||||
|
help='The sale.order.line rows that feed this MO. Populated when '
|
||||||
|
'bridge_mrp batches multiple lines into one MO by WO group tag.',
|
||||||
|
)
|
||||||
|
x_fc_start_at_node_id = fields.Many2one(
|
||||||
|
'fusion.plating.process.node',
|
||||||
|
string='Start at Node',
|
||||||
|
help='For rework: WO generation skips recipe nodes that come '
|
||||||
|
'before this one. Copied from the first SO line that set it.',
|
||||||
|
)
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# T1.4 — Rework / strip-and-replate
|
# T1.4 — Rework / strip-and-replate
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@@ -418,6 +440,26 @@ class MrpProduction(models.Model):
|
|||||||
for override in production.x_fc_override_ids:
|
for override in production.x_fc_override_ids:
|
||||||
override_map[override.node_id.id] = override.included
|
override_map[override.node_id.id] = override.included
|
||||||
|
|
||||||
|
# Start-at-node: if set, build the set of node IDs that are
|
||||||
|
# "at or descended from" the start node OR on its ancestor
|
||||||
|
# path (so we keep the containing recipe / sub-processes
|
||||||
|
# visible but skip sibling branches that come before the
|
||||||
|
# start point).
|
||||||
|
start_node = production.x_fc_start_at_node_id
|
||||||
|
allowed_ids = None # None = include everything
|
||||||
|
if start_node:
|
||||||
|
# Descendants (inclusive)
|
||||||
|
descendants = self.env['fusion.plating.process.node'].search([
|
||||||
|
('id', 'child_of', start_node.id),
|
||||||
|
])
|
||||||
|
# Ancestors (excluding self — already in descendants)
|
||||||
|
ancestors = self.env['fusion.plating.process.node']
|
||||||
|
cur = start_node.parent_id
|
||||||
|
while cur:
|
||||||
|
ancestors |= cur
|
||||||
|
cur = cur.parent_id
|
||||||
|
allowed_ids = set(descendants.ids) | set(ancestors.ids)
|
||||||
|
|
||||||
# Bind the source SO once per production so walk_node closure
|
# Bind the source SO once per production so walk_node closure
|
||||||
# can read coating config / spec without an extra search per WO.
|
# can read coating config / spec without an extra search per WO.
|
||||||
so = False
|
so = False
|
||||||
@@ -433,13 +475,18 @@ class MrpProduction(models.Model):
|
|||||||
|
|
||||||
def _is_node_included(node):
|
def _is_node_included(node):
|
||||||
"""Determine if a node should be included based on opt-in/out
|
"""Determine if a node should be included based on opt-in/out
|
||||||
logic and per-job overrides.
|
logic, per-job overrides, and start-at-node filter.
|
||||||
|
|
||||||
- disabled: always included (not configurable)
|
- disabled: always included (not configurable)
|
||||||
- opt_in: excluded by default, included only with override
|
- opt_in: excluded by default, included only with override
|
||||||
- opt_out: included by default, excluded only with override
|
- opt_out: included by default, excluded only with override
|
||||||
|
- If start_at_node is set, nodes outside the allowed
|
||||||
|
subtree (at-or-below start_node, plus its ancestors)
|
||||||
|
are always excluded.
|
||||||
"""
|
"""
|
||||||
nid = node.id
|
nid = node.id
|
||||||
|
if allowed_ids is not None and nid not in allowed_ids:
|
||||||
|
return False
|
||||||
opt = node.opt_in_out or 'disabled'
|
opt = node.opt_in_out or 'disabled'
|
||||||
if opt == 'disabled':
|
if opt == 'disabled':
|
||||||
return True
|
return True
|
||||||
@@ -492,6 +539,11 @@ class MrpProduction(models.Model):
|
|||||||
'workcenter_id': mrp_wc,
|
'workcenter_id': mrp_wc,
|
||||||
'duration_expected': node.estimated_duration or 0,
|
'duration_expected': node.estimated_duration or 0,
|
||||||
'sequence': seq_counter[0],
|
'sequence': seq_counter[0],
|
||||||
|
# Persist the link back to the recipe node so
|
||||||
|
# downstream behaviour (auto-complete, sign-off,
|
||||||
|
# automated-vs-manual gating, customer-visibility)
|
||||||
|
# can resolve in O(1) instead of joining by name.
|
||||||
|
'x_fc_recipe_node_id': node.id,
|
||||||
}
|
}
|
||||||
# Recipe estimated_duration also fills the WO's
|
# Recipe estimated_duration also fills the WO's
|
||||||
# x_fc_dwell_time_minutes — operators see the recipe-
|
# x_fc_dwell_time_minutes — operators see the recipe-
|
||||||
@@ -578,27 +630,69 @@ class MrpProduction(models.Model):
|
|||||||
# Recipe auto-assignment from SO coating config
|
# Recipe auto-assignment from SO coating config
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def _auto_assign_recipe_from_so(self):
|
def _auto_assign_recipe_from_so(self):
|
||||||
"""If no recipe is set, pull the default recipe from the SO's
|
"""Pull the default recipe for this MO when none is set.
|
||||||
coating config (fp.coating.config.recipe_id).
|
|
||||||
|
Resolution order:
|
||||||
|
1. SO coating config (fp.coating.config.recipe_id)
|
||||||
|
2. Recipe whose product_id matches the MO's product
|
||||||
|
(Steelhead "Product" link on the recipe)
|
||||||
|
|
||||||
|
Then, regardless of how the recipe was picked, apply its
|
||||||
|
`default_lead_time` to MO.date_planned_finished if the planner
|
||||||
|
hasn't already overridden the date.
|
||||||
"""
|
"""
|
||||||
|
from datetime import timedelta
|
||||||
|
ProcessNode = self.env['fusion.plating.process.node']
|
||||||
for mo in self:
|
for mo in self:
|
||||||
if mo.x_fc_recipe_id:
|
if not mo.x_fc_recipe_id:
|
||||||
continue # Already set — respect planner's choice
|
# 1. SO coating config (legacy path)
|
||||||
if not mo.origin:
|
so = False
|
||||||
continue
|
if mo.origin:
|
||||||
so = self.env['sale.order'].search(
|
so = self.env['sale.order'].search(
|
||||||
[('name', '=', mo.origin)], limit=1,
|
[('name', '=', mo.origin)], limit=1,
|
||||||
)
|
)
|
||||||
if not so or 'x_fc_coating_config_id' not in so._fields:
|
if so and 'x_fc_coating_config_id' in so._fields:
|
||||||
continue
|
coating = so.x_fc_coating_config_id
|
||||||
coating = so.x_fc_coating_config_id
|
if coating and coating.recipe_id:
|
||||||
if coating and coating.recipe_id:
|
mo.x_fc_recipe_id = coating.recipe_id
|
||||||
mo.x_fc_recipe_id = coating.recipe_id
|
mo.message_post(
|
||||||
mo.message_post(
|
body=_('Recipe "%s" auto-assigned from coating config "%s".') % (
|
||||||
body=_('Recipe "%s" auto-assigned from coating config "%s".') % (
|
coating.recipe_id.name, coating.name,
|
||||||
coating.recipe_id.name, coating.name,
|
),
|
||||||
),
|
)
|
||||||
|
# 2. Recipe.product_id == MO product
|
||||||
|
if not mo.x_fc_recipe_id and mo.product_id:
|
||||||
|
by_product = ProcessNode.sudo().search([
|
||||||
|
('node_type', '=', 'recipe'),
|
||||||
|
('product_id', '=', mo.product_id.id),
|
||||||
|
], limit=1)
|
||||||
|
if by_product:
|
||||||
|
mo.x_fc_recipe_id = by_product
|
||||||
|
mo.message_post(
|
||||||
|
body=_('Recipe "%s" auto-assigned from product "%s".') % (
|
||||||
|
by_product.name, mo.product_id.display_name,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
# Lead-time application — recipe lead time wins only if the
|
||||||
|
# MO's planned finish was at the model default (i.e. operator
|
||||||
|
# hasn't deliberately scheduled a date).
|
||||||
|
recipe = mo.x_fc_recipe_id
|
||||||
|
if recipe and recipe.default_lead_time and not mo.date_finished:
|
||||||
|
target = fields.Datetime.now() + timedelta(
|
||||||
|
days=recipe.default_lead_time,
|
||||||
)
|
)
|
||||||
|
# Don't overwrite if the planner already set a tighter
|
||||||
|
# (earlier) commit date — only push it later if no commit.
|
||||||
|
if not mo.date_finished or mo.date_finished < target:
|
||||||
|
mo.date_finished = target
|
||||||
|
mo.message_post(
|
||||||
|
body=_(
|
||||||
|
'Planned finish set to %s '
|
||||||
|
'(recipe "%s" default lead time = %.1f days).'
|
||||||
|
) % (target.strftime('%Y-%m-%d %H:%M'),
|
||||||
|
recipe.name, recipe.default_lead_time),
|
||||||
|
)
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# GAP 2: SO confirm → MO confirm → auto-create Portal Job + WOs
|
# GAP 2: SO confirm → MO confirm → auto-create Portal Job + WOs
|
||||||
|
|||||||
@@ -94,23 +94,132 @@ class SaleOrder(models.Model):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
def _fp_auto_create_mo(self):
|
def _fp_auto_create_mo(self):
|
||||||
"""Create one draft MO per SO that doesn't already have one.
|
"""Create draft MO(s) for this SO, grouping by x_fc_wo_group_tag.
|
||||||
|
|
||||||
Resolution order for the manufactured product:
|
Grouping rules (new in v19.0.7.x):
|
||||||
1. The configurator's part catalog → linked product (if any).
|
- Lines sharing a non-empty x_fc_wo_group_tag collapse into ONE MO
|
||||||
2. The configurator's coating config → linked product (if any).
|
with product = first line's part product, qty = sum of line
|
||||||
3. The shop's fallback FP-WIDGET (used for service-line orders).
|
qtys, recipe = first line's coating_config.recipe_id.
|
||||||
|
- Lines with blank tag each get their own MO (one-to-one with
|
||||||
|
the line).
|
||||||
|
- If the SO has no plating lines at all, fall back to the legacy
|
||||||
|
one-MO-per-SO path using configurator data.
|
||||||
|
|
||||||
Resolution for the recipe:
|
Idempotent: skips any group for which an MO with matching
|
||||||
1. configurator.coating_config_id.recipe_id (if the field exists)
|
(origin, x_fc_wo_group_tag) already exists.
|
||||||
2. configurator.part_catalog_id.recipe_id (if the field exists)
|
|
||||||
3. The first installed fp.process.node of node_type='recipe'.
|
|
||||||
"""
|
"""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
Production = self.env['mrp.production']
|
Production = self.env['mrp.production']
|
||||||
existing = Production.search_count([('origin', '=', self.name)])
|
existing_tags = set(Production.search([
|
||||||
if existing:
|
('origin', '=', self.name),
|
||||||
return # idempotent
|
]).mapped('x_fc_wo_group_tag'))
|
||||||
|
|
||||||
|
# Build groups from SO lines that carry plating data
|
||||||
|
plating_lines = self.order_line.filtered(
|
||||||
|
lambda l: l.x_fc_part_catalog_id or l.x_fc_coating_config_id
|
||||||
|
)
|
||||||
|
if not plating_lines:
|
||||||
|
return self._fp_auto_create_mo_legacy()
|
||||||
|
|
||||||
|
groups = {} # {tag_or_line_key: [lines]}
|
||||||
|
for line in plating_lines:
|
||||||
|
key = line.x_fc_wo_group_tag or ('__line__%d' % line.id)
|
||||||
|
groups.setdefault(key, []).append(line)
|
||||||
|
|
||||||
|
created = []
|
||||||
|
for key, lines in groups.items():
|
||||||
|
tag = lines[0].x_fc_wo_group_tag or False
|
||||||
|
# Skip if we already have an MO for this (origin, tag) pair.
|
||||||
|
# Untagged keys are 1:1 with lines; use the line ID in sudo
|
||||||
|
# check via existing MOs' line links.
|
||||||
|
if tag and tag in existing_tags:
|
||||||
|
continue
|
||||||
|
if not tag:
|
||||||
|
# Untagged idempotency — check if any existing MO points
|
||||||
|
# at this line via x_fc_sale_order_line_ids.
|
||||||
|
if Production.search_count([
|
||||||
|
('origin', '=', self.name),
|
||||||
|
('x_fc_sale_order_line_ids', 'in', [lines[0].id]),
|
||||||
|
]):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Resolve product: part catalog's linked product if any, else
|
||||||
|
# FP-WIDGET fallback.
|
||||||
|
product = False
|
||||||
|
for ln in lines:
|
||||||
|
pc = ln.x_fc_part_catalog_id
|
||||||
|
if pc and 'product_id' in pc._fields and pc.product_id:
|
||||||
|
product = pc.product_id
|
||||||
|
break
|
||||||
|
if not product:
|
||||||
|
product = self.env['product.product'].search(
|
||||||
|
[('default_code', '=', 'FP-WIDGET')], limit=1,
|
||||||
|
)
|
||||||
|
if not product:
|
||||||
|
self.message_post(body=_(
|
||||||
|
'Auto-MO skipped (group %s) — no manufacturable '
|
||||||
|
'product available.'
|
||||||
|
) % (tag or 'single-line'))
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Recipe: first line's coating -> recipe_id.
|
||||||
|
recipe = False
|
||||||
|
for ln in lines:
|
||||||
|
cc = ln.x_fc_coating_config_id
|
||||||
|
if cc and 'recipe_id' in cc._fields and cc.recipe_id:
|
||||||
|
recipe = cc.recipe_id
|
||||||
|
break
|
||||||
|
if not recipe:
|
||||||
|
recipe = self.env['fusion.plating.process.node'].search(
|
||||||
|
[('node_type', '=', 'recipe')], limit=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
qty = sum(ln.product_uom_qty for ln in lines) or 1
|
||||||
|
# Start-at-node: first non-blank wins
|
||||||
|
start_node = False
|
||||||
|
for ln in lines:
|
||||||
|
if ln.x_fc_start_at_node_id:
|
||||||
|
start_node = ln.x_fc_start_at_node_id
|
||||||
|
break
|
||||||
|
|
||||||
|
mo_vals = {
|
||||||
|
'product_id': product.id,
|
||||||
|
'product_qty': qty,
|
||||||
|
'product_uom_id': product.uom_id.id,
|
||||||
|
'origin': self.name,
|
||||||
|
'x_fc_wo_group_tag': tag or False,
|
||||||
|
'x_fc_sale_order_line_ids': [(6, 0, [ln.id for ln in lines])],
|
||||||
|
}
|
||||||
|
if recipe and 'x_fc_recipe_id' in Production._fields:
|
||||||
|
mo_vals['x_fc_recipe_id'] = recipe.id
|
||||||
|
if start_node:
|
||||||
|
mo_vals['x_fc_start_at_node_id'] = start_node.id
|
||||||
|
mo = Production.create(mo_vals)
|
||||||
|
created.append((mo, tag, len(lines)))
|
||||||
|
|
||||||
|
if created:
|
||||||
|
lines_html = '<br/>'.join([
|
||||||
|
_('MO <a href="/odoo/manufacturing/%s">%s</a> '
|
||||||
|
'(%s, %d source line%s)') % (
|
||||||
|
mo.id, mo.name, tag or 'untagged',
|
||||||
|
n, 's' if n != 1 else ''
|
||||||
|
)
|
||||||
|
for mo, tag, n in created
|
||||||
|
])
|
||||||
|
self.message_post(body=Markup(_(
|
||||||
|
'%d draft manufacturing order(s) auto-created:<br/>%s'
|
||||||
|
)) % (len(created), lines_html))
|
||||||
|
|
||||||
|
def _fp_auto_create_mo_legacy(self):
|
||||||
|
"""Fallback for SOs with no plating order_line data (service lines).
|
||||||
|
|
||||||
|
Preserves the pre-v19.0.7 behaviour: one MO per SO using the
|
||||||
|
configurator's part / coating / recipe references.
|
||||||
|
"""
|
||||||
|
self.ensure_one()
|
||||||
|
Production = self.env['mrp.production']
|
||||||
|
if Production.search_count([('origin', '=', self.name)]):
|
||||||
|
return
|
||||||
|
|
||||||
cfg = self.x_fc_configurator_id if 'x_fc_configurator_id' in self._fields else False
|
cfg = self.x_fc_configurator_id if 'x_fc_configurator_id' in self._fields else False
|
||||||
product = False
|
product = False
|
||||||
@@ -132,8 +241,7 @@ class SaleOrder(models.Model):
|
|||||||
)
|
)
|
||||||
if not product:
|
if not product:
|
||||||
self.message_post(body=_(
|
self.message_post(body=_(
|
||||||
'Auto-MO skipped — no manufacturable product available '
|
'Auto-MO skipped — no manufacturable product available.'
|
||||||
'(neither part catalog nor FP-WIDGET fallback resolved).'
|
|
||||||
))
|
))
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -149,8 +257,7 @@ class SaleOrder(models.Model):
|
|||||||
mo = Production.create(mo_vals)
|
mo = Production.create(mo_vals)
|
||||||
self.message_post(body=Markup(_(
|
self.message_post(body=Markup(_(
|
||||||
'Draft Manufacturing Order <a href="/odoo/manufacturing/%s">%s</a> '
|
'Draft Manufacturing Order <a href="/odoo/manufacturing/%s">%s</a> '
|
||||||
'auto-created. Accept the parts and click <b>Assign to Me</b> to '
|
'auto-created (legacy path).'
|
||||||
'release it to the floor.'
|
|
||||||
)) % (mo.id, mo.name))
|
)) % (mo.id, mo.name))
|
||||||
|
|
||||||
@api.depends(
|
@api.depends(
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Fusion Plating — Configurator',
|
'name': 'Fusion Plating — Configurator',
|
||||||
'version': '19.0.5.2.0',
|
'version': '19.0.7.2.0',
|
||||||
'category': 'Manufacturing/Plating',
|
'category': 'Manufacturing/Plating',
|
||||||
'summary': 'Quotation configurator with part catalog, coating configs, and formula-based pricing engine.',
|
'summary': 'Quotation configurator with part catalog, coating configs, and formula-based pricing engine.',
|
||||||
'description': """
|
'description': """
|
||||||
@@ -50,6 +50,7 @@ Provides:
|
|||||||
'views/fp_configurator_menu.xml',
|
'views/fp_configurator_menu.xml',
|
||||||
'views/fp_sale_description_template_views.xml',
|
'views/fp_sale_description_template_views.xml',
|
||||||
'wizard/fp_direct_order_wizard_views.xml',
|
'wizard/fp_direct_order_wizard_views.xml',
|
||||||
|
'wizard/fp_add_from_so_wizard_views.xml',
|
||||||
'wizard/fp_part_catalog_import_wizard_views.xml',
|
'wizard/fp_part_catalog_import_wizard_views.xml',
|
||||||
'data/fp_sale_description_template_data.xml',
|
'data/fp_sale_description_template_data.xml',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -12,4 +12,6 @@ from . import fp_customer_price_list
|
|||||||
from . import fp_sale_description_template
|
from . import fp_sale_description_template
|
||||||
from . import fp_quote_configurator
|
from . import fp_quote_configurator
|
||||||
from . import sale_order
|
from . import sale_order
|
||||||
|
from . import sale_order_line
|
||||||
from . import res_partner
|
from . import res_partner
|
||||||
|
from . import fp_process_node
|
||||||
|
|||||||
@@ -131,6 +131,21 @@ class FpPartCatalog(models.Model):
|
|||||||
notes = fields.Html(string='Notes')
|
notes = fields.Html(string='Notes')
|
||||||
active = fields.Boolean(string='Active', default=True)
|
active = fields.Boolean(string='Active', default=True)
|
||||||
|
|
||||||
|
# ---- Direct-order defaults (Phase C — C4) ----
|
||||||
|
x_fc_default_coating_config_id = fields.Many2one(
|
||||||
|
'fp.coating.config',
|
||||||
|
string='Default Treatment',
|
||||||
|
help='Default coating applied when this part is dropped onto a '
|
||||||
|
'direct order line. Updated when "Save as Default" is ticked.',
|
||||||
|
)
|
||||||
|
x_fc_default_treatment_ids = fields.Many2many(
|
||||||
|
'fp.treatment',
|
||||||
|
relation='fp_part_catalog_default_treatment_rel',
|
||||||
|
string='Default Additional Treatments',
|
||||||
|
help='Default additional treatments. Seeded when "Save as Default" '
|
||||||
|
'is ticked on a direct order line.',
|
||||||
|
)
|
||||||
|
|
||||||
# Substrate density mapping (g/cm³) for material weight calculation
|
# Substrate density mapping (g/cm³) for material weight calculation
|
||||||
_SUBSTRATE_DENSITY = {
|
_SUBSTRATE_DENSITY = {
|
||||||
'aluminium': 2.70,
|
'aluminium': 2.70,
|
||||||
|
|||||||
@@ -58,6 +58,254 @@ class SaleOrder(models.Model):
|
|||||||
string='Receiving Status', default='not_received', tracking=True,
|
string='Receiving Status', default='not_received', tracking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# ---- Direct Order rewrite (Phase A) ----
|
||||||
|
x_fc_customer_job_number = fields.Char(
|
||||||
|
string='Customer Job #',
|
||||||
|
help="Customer's internal job number for cross-referencing.",
|
||||||
|
tracking=True,
|
||||||
|
)
|
||||||
|
x_fc_planned_start_date = fields.Date(
|
||||||
|
string='Planned Start Date', tracking=True,
|
||||||
|
)
|
||||||
|
x_fc_internal_deadline = fields.Date(
|
||||||
|
string='Internal Deadline', tracking=True,
|
||||||
|
)
|
||||||
|
x_fc_is_blanket_order = fields.Boolean(
|
||||||
|
string='Is Blanket Sales Order',
|
||||||
|
help='Blanket orders release parts in quantities over time, '
|
||||||
|
'often with a negotiated price and a fixed expiry.',
|
||||||
|
tracking=True,
|
||||||
|
)
|
||||||
|
x_fc_block_partial_shipments = fields.Boolean(
|
||||||
|
string='Block Partial Shipments',
|
||||||
|
help='If set, the order must ship all-or-nothing. '
|
||||||
|
'Partial pickings are blocked.',
|
||||||
|
tracking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- Phase D: SO detail view polish ----
|
||||||
|
x_fc_external_note = fields.Html(
|
||||||
|
string='External Notes',
|
||||||
|
help='Customer-visible notes. Appear on the SO acknowledgement '
|
||||||
|
'and customer portal.',
|
||||||
|
)
|
||||||
|
x_fc_internal_note = fields.Html(
|
||||||
|
string='Internal Notes',
|
||||||
|
help='Internal-only notes for the estimator / planner / shop floor.',
|
||||||
|
)
|
||||||
|
x_fc_ship_via = fields.Char(
|
||||||
|
string='Ship Via',
|
||||||
|
help='Carrier or delivery method name (UPS, FedEx, customer pickup, etc.).',
|
||||||
|
tracking=True,
|
||||||
|
)
|
||||||
|
x_fc_contact_phone = fields.Char(
|
||||||
|
related='partner_id.phone', string='Contact Phone', readonly=True,
|
||||||
|
)
|
||||||
|
x_fc_deadline_countdown = fields.Char(
|
||||||
|
string='Deadline',
|
||||||
|
compute='_compute_deadline_countdown',
|
||||||
|
)
|
||||||
|
x_fc_margin_amount = fields.Monetary(
|
||||||
|
string='Margin',
|
||||||
|
compute='_compute_margin', currency_field='currency_id',
|
||||||
|
)
|
||||||
|
x_fc_margin_percent = fields.Float(
|
||||||
|
string='Margin %',
|
||||||
|
compute='_compute_margin',
|
||||||
|
)
|
||||||
|
|
||||||
|
x_fc_workorder_count = fields.Integer(
|
||||||
|
string='Active WOs',
|
||||||
|
compute='_compute_workorder_count',
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- Phase E: list view helpers ----
|
||||||
|
x_fc_wo_completion = fields.Char(
|
||||||
|
string='WO Progress',
|
||||||
|
compute='_compute_wo_completion',
|
||||||
|
help='Ratio of completed work orders, shown as "3/5 done".',
|
||||||
|
)
|
||||||
|
x_fc_invoiced_amount = fields.Monetary(
|
||||||
|
string='Invoiced',
|
||||||
|
compute='_compute_invoiced_amount',
|
||||||
|
currency_field='currency_id',
|
||||||
|
)
|
||||||
|
|
||||||
|
def _compute_wo_completion(self):
|
||||||
|
WO = self.env['mrp.workorder'].sudo()
|
||||||
|
for rec in self:
|
||||||
|
if not rec.name:
|
||||||
|
rec.x_fc_wo_completion = '0/0'
|
||||||
|
continue
|
||||||
|
total = WO.search_count([('production_id.origin', '=', rec.name)])
|
||||||
|
done = WO.search_count([
|
||||||
|
('production_id.origin', '=', rec.name),
|
||||||
|
('state', '=', 'done'),
|
||||||
|
])
|
||||||
|
rec.x_fc_wo_completion = '%d/%d' % (done, total) if total else '0/0'
|
||||||
|
|
||||||
|
# ---- Phase F: quotes list view polish ----
|
||||||
|
x_fc_follow_up_date = fields.Date(
|
||||||
|
string='Follow-Up Date',
|
||||||
|
help='Date to chase the customer for a decision on this quote.',
|
||||||
|
tracking=True,
|
||||||
|
)
|
||||||
|
x_fc_follow_up_user_id = fields.Many2one(
|
||||||
|
'res.users', string='Follow-Up Owner',
|
||||||
|
help='Who should chase the customer on the follow-up date.',
|
||||||
|
)
|
||||||
|
x_fc_email_status = fields.Selection(
|
||||||
|
[('draft', 'Draft'),
|
||||||
|
('sent', 'Sent'),
|
||||||
|
('opened', 'Opened'),
|
||||||
|
('won', 'Order Received')],
|
||||||
|
string='Email Status',
|
||||||
|
compute='_compute_email_status',
|
||||||
|
store=True,
|
||||||
|
)
|
||||||
|
x_fc_part_numbers_summary = fields.Char(
|
||||||
|
string='Part Numbers',
|
||||||
|
compute='_compute_part_numbers_summary',
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.depends('state')
|
||||||
|
def _compute_email_status(self):
|
||||||
|
"""Map state + mail tracking to a single visible pill.
|
||||||
|
|
||||||
|
- draft SO with no tracked email sent => draft
|
||||||
|
- sent (Odoo state) => sent
|
||||||
|
- sent + mail opened => opened (detected via mail.message)
|
||||||
|
- state=sale/done => won
|
||||||
|
"""
|
||||||
|
for rec in self:
|
||||||
|
if rec.state in ('sale', 'done'):
|
||||||
|
rec.x_fc_email_status = 'won'
|
||||||
|
continue
|
||||||
|
if rec.state == 'draft':
|
||||||
|
rec.x_fc_email_status = 'draft'
|
||||||
|
continue
|
||||||
|
# state == 'sent'
|
||||||
|
opened = False
|
||||||
|
if rec.id:
|
||||||
|
msgs = self.env['mail.message'].sudo().search([
|
||||||
|
('model', '=', 'sale.order'),
|
||||||
|
('res_id', '=', rec.id),
|
||||||
|
('message_type', '=', 'email'),
|
||||||
|
], limit=10)
|
||||||
|
# mail.notification tracks read timestamps
|
||||||
|
for m in msgs:
|
||||||
|
if m.notification_ids.filtered(
|
||||||
|
lambda n: n.is_read
|
||||||
|
):
|
||||||
|
opened = True
|
||||||
|
break
|
||||||
|
rec.x_fc_email_status = 'opened' if opened else 'sent'
|
||||||
|
|
||||||
|
@api.depends('order_line.x_fc_part_catalog_id.part_number')
|
||||||
|
def _compute_part_numbers_summary(self):
|
||||||
|
for rec in self:
|
||||||
|
parts = rec.order_line.mapped('x_fc_part_catalog_id.part_number')
|
||||||
|
parts = [p for p in parts if p]
|
||||||
|
if not parts:
|
||||||
|
rec.x_fc_part_numbers_summary = False
|
||||||
|
continue
|
||||||
|
if len(parts) <= 2:
|
||||||
|
rec.x_fc_part_numbers_summary = ', '.join(parts)
|
||||||
|
else:
|
||||||
|
rec.x_fc_part_numbers_summary = '%s, %s (+%d more)' % (
|
||||||
|
parts[0], parts[1], len(parts) - 2,
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.depends('invoice_ids.amount_total', 'invoice_ids.state',
|
||||||
|
'invoice_ids.move_type')
|
||||||
|
def _compute_invoiced_amount(self):
|
||||||
|
for rec in self:
|
||||||
|
posted = rec.invoice_ids.filtered(
|
||||||
|
lambda m: m.state == 'posted' and m.move_type == 'out_invoice'
|
||||||
|
)
|
||||||
|
refunds = rec.invoice_ids.filtered(
|
||||||
|
lambda m: m.state == 'posted' and m.move_type == 'out_refund'
|
||||||
|
)
|
||||||
|
rec.x_fc_invoiced_amount = (
|
||||||
|
sum(posted.mapped('amount_total'))
|
||||||
|
- sum(refunds.mapped('amount_total'))
|
||||||
|
)
|
||||||
|
|
||||||
|
def _compute_workorder_count(self):
|
||||||
|
WO = self.env['mrp.workorder'].sudo()
|
||||||
|
for rec in self:
|
||||||
|
if not rec.name:
|
||||||
|
rec.x_fc_workorder_count = 0
|
||||||
|
continue
|
||||||
|
rec.x_fc_workorder_count = WO.search_count([
|
||||||
|
('production_id.origin', '=', rec.name),
|
||||||
|
('state', 'not in', ('done', 'cancel')),
|
||||||
|
])
|
||||||
|
|
||||||
|
def action_view_workorders(self):
|
||||||
|
self.ensure_one()
|
||||||
|
return {
|
||||||
|
'type': 'ir.actions.act_window',
|
||||||
|
'name': 'Work Orders',
|
||||||
|
'res_model': 'mrp.workorder',
|
||||||
|
'view_mode': 'list,form',
|
||||||
|
'domain': [('production_id.origin', '=', self.name)],
|
||||||
|
'context': {'search_default_group_production_id': 1},
|
||||||
|
}
|
||||||
|
|
||||||
|
@api.depends('commitment_date')
|
||||||
|
def _compute_deadline_countdown(self):
|
||||||
|
from datetime import datetime
|
||||||
|
now = fields.Datetime.now()
|
||||||
|
for rec in self:
|
||||||
|
if not rec.commitment_date:
|
||||||
|
rec.x_fc_deadline_countdown = False
|
||||||
|
continue
|
||||||
|
target = rec.commitment_date
|
||||||
|
if isinstance(target, datetime):
|
||||||
|
delta = target - now
|
||||||
|
else:
|
||||||
|
from datetime import datetime as _dt
|
||||||
|
delta = _dt.combine(target, _dt.min.time()) - now
|
||||||
|
secs = int(delta.total_seconds())
|
||||||
|
if secs == 0:
|
||||||
|
rec.x_fc_deadline_countdown = 'due now'
|
||||||
|
continue
|
||||||
|
past = secs < 0
|
||||||
|
secs = abs(secs)
|
||||||
|
days = secs // 86400
|
||||||
|
hours = (secs % 86400) // 3600
|
||||||
|
mins = (secs % 3600) // 60
|
||||||
|
bits = []
|
||||||
|
if days:
|
||||||
|
bits.append('%dd' % days)
|
||||||
|
if hours:
|
||||||
|
bits.append('%dh' % hours)
|
||||||
|
if mins and not days:
|
||||||
|
bits.append('%dm' % mins)
|
||||||
|
phrase = ' '.join(bits) or '<1m'
|
||||||
|
rec.x_fc_deadline_countdown = (
|
||||||
|
'overdue %s' % phrase if past else 'in %s' % phrase
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.depends('order_line.price_subtotal', 'amount_untaxed')
|
||||||
|
def _compute_margin(self):
|
||||||
|
"""Simple margin: untaxed total minus rolled-up cost from coating configs."""
|
||||||
|
for rec in self:
|
||||||
|
cost = 0.0
|
||||||
|
for line in rec.order_line:
|
||||||
|
if line.x_fc_coating_config_id:
|
||||||
|
# If coating_config has a cost field, use it; otherwise 0.
|
||||||
|
cost_per_unit = getattr(
|
||||||
|
line.x_fc_coating_config_id, 'unit_cost', 0.0,
|
||||||
|
) or 0.0
|
||||||
|
cost += cost_per_unit * (line.product_uom_qty or 0)
|
||||||
|
rec.x_fc_margin_amount = (rec.amount_untaxed or 0) - cost
|
||||||
|
rec.x_fc_margin_percent = (
|
||||||
|
(rec.x_fc_margin_amount / rec.amount_untaxed * 100.0)
|
||||||
|
if rec.amount_untaxed else 0.0
|
||||||
|
)
|
||||||
|
|
||||||
@api.onchange('upload_rfq_file')
|
@api.onchange('upload_rfq_file')
|
||||||
def _onchange_upload_rfq_file(self):
|
def _onchange_upload_rfq_file(self):
|
||||||
"""Create attachment from uploaded binary and link it."""
|
"""Create attachment from uploaded binary and link it."""
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright 2026 Nexa Systems Inc.
|
||||||
|
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||||
|
# Part of the Fusion Plating product family.
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class SaleOrderLine(models.Model):
|
||||||
|
_inherit = 'sale.order.line'
|
||||||
|
|
||||||
|
x_fc_part_catalog_id = fields.Many2one(
|
||||||
|
'fp.part.catalog', string='Part',
|
||||||
|
)
|
||||||
|
x_fc_coating_config_id = fields.Many2one(
|
||||||
|
'fp.coating.config', string='Primary Treatment',
|
||||||
|
)
|
||||||
|
x_fc_treatment_ids = fields.Many2many(
|
||||||
|
'fp.treatment', string='Additional Treatments',
|
||||||
|
)
|
||||||
|
x_fc_part_deadline = fields.Date(string='Part Deadline')
|
||||||
|
x_fc_rush_order = fields.Boolean(string='Rush')
|
||||||
|
x_fc_wo_group_tag = fields.Char(
|
||||||
|
string='Work Order Group',
|
||||||
|
help='Lines sharing a tag (e.g. "WO#1") will be batched into one '
|
||||||
|
'manufacturing order when bridge_mrp generates MOs.',
|
||||||
|
)
|
||||||
|
x_fc_part_wo_description = fields.Text(
|
||||||
|
string='On Work Order',
|
||||||
|
help='Extra detail printed on the work order travelling sheet. '
|
||||||
|
'Separate from the customer-facing line description.',
|
||||||
|
)
|
||||||
|
x_fc_start_at_node_id = fields.Many2one(
|
||||||
|
'fusion.plating.process.node',
|
||||||
|
string='Start at Node',
|
||||||
|
help='For re-work jobs: pick the recipe step where this job '
|
||||||
|
'should begin. bridge_mrp skips ancestor steps.',
|
||||||
|
)
|
||||||
|
x_fc_is_one_off = fields.Boolean(
|
||||||
|
string='One-off Part',
|
||||||
|
help='Flag for prototype / non-catalog parts that should not be '
|
||||||
|
'reused after this order.',
|
||||||
|
)
|
||||||
|
x_fc_quote_id = fields.Many2one(
|
||||||
|
'fp.quote.configurator',
|
||||||
|
string='Linked Quote',
|
||||||
|
help='Quote that seeded this line. Links back for audit trail.',
|
||||||
|
)
|
||||||
@@ -21,6 +21,8 @@ access_fp_direct_order_wizard_estimator,fp.direct.order.wizard.estimator,model_f
|
|||||||
access_fp_direct_order_wizard_manager,fp.direct.order.wizard.manager,model_fp_direct_order_wizard,fusion_plating.group_fusion_plating_manager,1,1,1,1
|
access_fp_direct_order_wizard_manager,fp.direct.order.wizard.manager,model_fp_direct_order_wizard,fusion_plating.group_fusion_plating_manager,1,1,1,1
|
||||||
access_fp_direct_order_line_estimator,fp.direct.order.line.estimator,model_fp_direct_order_line,fusion_plating_configurator.group_fp_estimator,1,1,1,1
|
access_fp_direct_order_line_estimator,fp.direct.order.line.estimator,model_fp_direct_order_line,fusion_plating_configurator.group_fp_estimator,1,1,1,1
|
||||||
access_fp_direct_order_line_manager,fp.direct.order.line.manager,model_fp_direct_order_line,fusion_plating.group_fusion_plating_manager,1,1,1,1
|
access_fp_direct_order_line_manager,fp.direct.order.line.manager,model_fp_direct_order_line,fusion_plating.group_fusion_plating_manager,1,1,1,1
|
||||||
|
access_fp_add_from_so_wizard_estimator,fp.add.from.so.wizard.estimator,model_fp_add_from_so_wizard,fusion_plating_configurator.group_fp_estimator,1,1,1,1
|
||||||
|
access_fp_add_from_so_wizard_manager,fp.add.from.so.wizard.manager,model_fp_add_from_so_wizard,fusion_plating.group_fusion_plating_manager,1,1,1,1
|
||||||
access_fp_part_import_wizard_estimator,fp.part.catalog.import.wizard.estimator,model_fp_part_catalog_import_wizard,fusion_plating_configurator.group_fp_estimator,1,1,1,1
|
access_fp_part_import_wizard_estimator,fp.part.catalog.import.wizard.estimator,model_fp_part_catalog_import_wizard,fusion_plating_configurator.group_fp_estimator,1,1,1,1
|
||||||
access_fp_part_import_wizard_manager,fp.part.catalog.import.wizard.manager,model_fp_part_catalog_import_wizard,fusion_plating.group_fusion_plating_manager,1,1,1,1
|
access_fp_part_import_wizard_manager,fp.part.catalog.import.wizard.manager,model_fp_part_catalog_import_wizard,fusion_plating.group_fusion_plating_manager,1,1,1,1
|
||||||
access_fp_customer_price_list_operator,fp.customer.price.list.operator,model_fp_customer_price_list,fusion_plating.group_fusion_plating_operator,1,0,0,0
|
access_fp_customer_price_list_operator,fp.customer.price.list.operator,model_fp_customer_price_list,fusion_plating.group_fusion_plating_operator,1,0,0,0
|
||||||
|
|||||||
|
@@ -224,6 +224,20 @@
|
|||||||
</list>
|
</list>
|
||||||
</field>
|
</field>
|
||||||
</page>
|
</page>
|
||||||
|
<page string="Defaults" name="direct_order_defaults">
|
||||||
|
<group>
|
||||||
|
<field name="x_fc_default_coating_config_id"
|
||||||
|
options="{'no_create_edit': True}"/>
|
||||||
|
<field name="x_fc_default_treatment_ids"
|
||||||
|
widget="many2many_tags"
|
||||||
|
options="{'no_create_edit': True}"/>
|
||||||
|
</group>
|
||||||
|
<p class="text-muted">
|
||||||
|
Seeds the treatment fields on new direct-order
|
||||||
|
lines. Updated whenever "Save as Default" is
|
||||||
|
ticked while placing an order.
|
||||||
|
</p>
|
||||||
|
</page>
|
||||||
<page string="Notes" name="notes">
|
<page string="Notes" name="notes">
|
||||||
<field name="notes" placeholder="Additional notes about this part..."/>
|
<field name="notes" placeholder="Additional notes about this part..."/>
|
||||||
</page>
|
</page>
|
||||||
|
|||||||
@@ -33,6 +33,14 @@
|
|||||||
<span class="o_stat_text">PO</span>
|
<span class="o_stat_text">PO</span>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
|
<button name="action_view_workorders"
|
||||||
|
type="object"
|
||||||
|
class="oe_stat_button"
|
||||||
|
icon="fa-cogs"
|
||||||
|
invisible="x_fc_workorder_count == 0">
|
||||||
|
<field name="x_fc_workorder_count" widget="statinfo"
|
||||||
|
string="Active WOs"/>
|
||||||
|
</button>
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="//notebook" position="inside">
|
<xpath expr="//notebook" position="inside">
|
||||||
<page string="Plating" name="plating_tab">
|
<page string="Plating" name="plating_tab">
|
||||||
@@ -81,8 +89,53 @@
|
|||||||
<field name="x_fc_receiving_status"/><!-- Will become computed when fusion_plating_receiving is installed -->
|
<field name="x_fc_receiving_status"/><!-- Will become computed when fusion_plating_receiving is installed -->
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
|
<group>
|
||||||
|
<group string="Customer Reference">
|
||||||
|
<field name="x_fc_customer_job_number"/>
|
||||||
|
<field name="x_fc_contact_phone"/>
|
||||||
|
<field name="x_fc_ship_via"/>
|
||||||
|
</group>
|
||||||
|
<group string="Scheduling">
|
||||||
|
<field name="x_fc_planned_start_date"/>
|
||||||
|
<field name="x_fc_internal_deadline"/>
|
||||||
|
<field name="commitment_date" string="Customer Deadline"/>
|
||||||
|
<field name="x_fc_deadline_countdown" readonly="1"/>
|
||||||
|
<field name="x_fc_is_blanket_order"/>
|
||||||
|
<field name="x_fc_block_partial_shipments"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<group string="Margin">
|
||||||
|
<field name="x_fc_margin_amount"
|
||||||
|
widget="monetary"
|
||||||
|
options="{'currency_field': 'currency_id'}"/>
|
||||||
|
<field name="x_fc_margin_percent"
|
||||||
|
widget="percentage"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<group string="Internal Notes">
|
||||||
|
<field name="x_fc_internal_note" nolabel="1"
|
||||||
|
placeholder="Internal notes for estimator / planner / shop floor..."/>
|
||||||
|
</group>
|
||||||
|
<group string="External Notes (customer-visible)">
|
||||||
|
<field name="x_fc_external_note" nolabel="1"
|
||||||
|
placeholder="Notes that appear on the acknowledgement and portal..."/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
</page>
|
</page>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
<xpath expr="//field[@name='order_line']/list/field[@name='product_uom_qty']" position="before">
|
||||||
|
<field name="x_fc_part_catalog_id" optional="show"/>
|
||||||
|
<field name="x_fc_coating_config_id" optional="show"/>
|
||||||
|
<field name="x_fc_treatment_ids" widget="many2many_tags" optional="hide"/>
|
||||||
|
<field name="x_fc_part_deadline" optional="hide"/>
|
||||||
|
<field name="x_fc_wo_group_tag" optional="hide"/>
|
||||||
|
<field name="x_fc_start_at_node_id" optional="hide"/>
|
||||||
|
<field name="x_fc_is_one_off" optional="hide"/>
|
||||||
|
<field name="x_fc_quote_id" optional="hide"/>
|
||||||
|
<field name="x_fc_rush_order" optional="hide"/>
|
||||||
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
@@ -96,18 +149,135 @@
|
|||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="partner_id"/>
|
<field name="partner_id"/>
|
||||||
<field name="x_fc_po_number"/>
|
<field name="x_fc_po_number"/>
|
||||||
<field name="x_fc_part_catalog_id" optional="show"/>
|
<field name="x_fc_customer_job_number" optional="show"/>
|
||||||
<field name="x_fc_coating_config_id" optional="show"/>
|
<field name="x_fc_internal_deadline" optional="show"/>
|
||||||
|
<field name="commitment_date" string="Customer Deadline" optional="show"/>
|
||||||
|
<field name="x_fc_deadline_countdown" optional="show"/>
|
||||||
|
<field name="x_fc_wo_completion" optional="show"/>
|
||||||
|
<field name="x_fc_planned_start_date" optional="hide"/>
|
||||||
|
<field name="x_fc_part_catalog_id" optional="hide"/>
|
||||||
|
<field name="x_fc_coating_config_id" optional="hide"/>
|
||||||
<field name="amount_total" sum="Total"/>
|
<field name="amount_total" sum="Total"/>
|
||||||
|
<field name="x_fc_invoiced_amount" sum="Invoiced" optional="hide"
|
||||||
|
widget="monetary"
|
||||||
|
options="{'currency_field': 'currency_id'}"/>
|
||||||
|
<field name="x_fc_margin_amount" sum="Margin" optional="hide"
|
||||||
|
widget="monetary"
|
||||||
|
options="{'currency_field': 'currency_id'}"/>
|
||||||
|
<field name="x_fc_margin_percent" optional="hide"
|
||||||
|
widget="percentage"/>
|
||||||
|
<field name="x_fc_is_blanket_order" optional="hide"/>
|
||||||
<field name="x_fc_receiving_status" widget="badge"
|
<field name="x_fc_receiving_status" widget="badge"
|
||||||
decoration-warning="x_fc_receiving_status == 'not_received'"
|
decoration-warning="x_fc_receiving_status == 'not_received'"
|
||||||
decoration-success="x_fc_receiving_status in ('received','inspected')"/>
|
decoration-success="x_fc_receiving_status in ('received','inspected')"/>
|
||||||
<field name="x_fc_delivery_method" optional="show"/>
|
<field name="x_fc_delivery_method" optional="hide"/>
|
||||||
|
<field name="currency_id" column_invisible="1"/>
|
||||||
<field name="state" widget="badge"/>
|
<field name="state" widget="badge"/>
|
||||||
</list>
|
</list>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<!-- ===== Quotes list view (state in draft/sent) ===== -->
|
||||||
|
<record id="view_sale_order_list_fp_quotes" model="ir.ui.view">
|
||||||
|
<field name="name">sale.order.list.fp.quotes</field>
|
||||||
|
<field name="model">sale.order</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<list string="Quotations" decoration-muted="state == 'cancel'">
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="partner_id"/>
|
||||||
|
<field name="x_fc_part_numbers_summary" optional="show"/>
|
||||||
|
<field name="x_fc_po_number" optional="hide"/>
|
||||||
|
<field name="x_fc_customer_job_number" optional="hide"/>
|
||||||
|
<field name="create_date" string="Created" optional="show"/>
|
||||||
|
<field name="validity_date" string="Expires" optional="show"/>
|
||||||
|
<field name="x_fc_follow_up_date" optional="show"/>
|
||||||
|
<field name="x_fc_follow_up_user_id" optional="show"/>
|
||||||
|
<field name="amount_total" sum="Total"/>
|
||||||
|
<field name="x_fc_email_status" widget="badge"
|
||||||
|
decoration-info="x_fc_email_status == 'sent'"
|
||||||
|
decoration-warning="x_fc_email_status == 'opened'"
|
||||||
|
decoration-success="x_fc_email_status == 'won'"/>
|
||||||
|
<field name="currency_id" column_invisible="1"/>
|
||||||
|
<field name="state" widget="badge"/>
|
||||||
|
</list>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- ===== Quotes search view ===== -->
|
||||||
|
<record id="view_sale_order_search_fp_quotes" model="ir.ui.view">
|
||||||
|
<field name="name">sale.order.search.fp.quotes</field>
|
||||||
|
<field name="model">sale.order</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<search string="Quotations">
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="partner_id"/>
|
||||||
|
<field name="x_fc_part_numbers_summary" string="Part Number"/>
|
||||||
|
<filter name="my_quotes" string="My Quotes"
|
||||||
|
domain="[('user_id', '=', uid)]"/>
|
||||||
|
<separator/>
|
||||||
|
<filter name="draft" string="Draft"
|
||||||
|
domain="[('state', '=', 'draft')]"/>
|
||||||
|
<filter name="sent" string="Sent"
|
||||||
|
domain="[('state', '=', 'sent')]"/>
|
||||||
|
<filter name="won" string="Won"
|
||||||
|
domain="[('state', 'in', ('sale', 'done'))]"/>
|
||||||
|
<separator/>
|
||||||
|
<filter name="from_rfq" string="From RFQ"
|
||||||
|
domain="[('x_fc_rfq_attachment_id', '!=', False)]"/>
|
||||||
|
<filter name="needs_followup" string="Needs Follow-Up"
|
||||||
|
domain="[('x_fc_follow_up_date', '<=', context_today()), ('state', 'in', ('draft', 'sent'))]"/>
|
||||||
|
<filter name="expired" string="Expired"
|
||||||
|
domain="[('validity_date', '<', context_today()), ('state', 'in', ('draft', 'sent'))]"/>
|
||||||
|
<group>
|
||||||
|
<filter string="Customer" name="group_partner"
|
||||||
|
context="{'group_by': 'partner_id'}"/>
|
||||||
|
<filter string="Status" name="group_state"
|
||||||
|
context="{'group_by': 'state'}"/>
|
||||||
|
<filter string="Follow-Up Owner" name="group_followup"
|
||||||
|
context="{'group_by': 'x_fc_follow_up_user_id'}"/>
|
||||||
|
</group>
|
||||||
|
</search>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- ===== Search view for Fusion Plating SO list ===== -->
|
||||||
|
<record id="view_sale_order_search_fp" model="ir.ui.view">
|
||||||
|
<field name="name">sale.order.search.fp</field>
|
||||||
|
<field name="model">sale.order</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<search string="Sales Orders">
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="partner_id"/>
|
||||||
|
<field name="x_fc_po_number" string="Customer PO #"/>
|
||||||
|
<field name="x_fc_customer_job_number" string="Customer Job #"/>
|
||||||
|
<filter name="my_orders" string="My Orders"
|
||||||
|
domain="[('user_id', '=', uid)]"/>
|
||||||
|
<separator/>
|
||||||
|
<filter name="open_orders" string="Open"
|
||||||
|
domain="[('state', 'in', ('draft', 'sent', 'sale'))]"/>
|
||||||
|
<filter name="confirmed" string="Confirmed"
|
||||||
|
domain="[('state', '=', 'sale')]"/>
|
||||||
|
<filter name="done" string="Done"
|
||||||
|
domain="[('state', '=', 'done')]"/>
|
||||||
|
<separator/>
|
||||||
|
<filter name="blanket_orders" string="Blanket Orders"
|
||||||
|
domain="[('x_fc_is_blanket_order', '=', True)]"/>
|
||||||
|
<filter name="rush_lines" string="Has Rush Line"
|
||||||
|
domain="[('order_line.x_fc_rush_order', '=', True)]"/>
|
||||||
|
<filter name="overdue" string="Overdue"
|
||||||
|
domain="[('commitment_date', '<', context_today()), ('state', 'in', ('sale',))]"/>
|
||||||
|
<group>
|
||||||
|
<filter string="Customer" name="group_partner"
|
||||||
|
context="{'group_by': 'partner_id'}"/>
|
||||||
|
<filter string="Status" name="group_state"
|
||||||
|
context="{'group_by': 'state'}"/>
|
||||||
|
<filter string="Customer Deadline" name="group_deadline"
|
||||||
|
context="{'group_by': 'commitment_date'}"/>
|
||||||
|
</group>
|
||||||
|
</search>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
<!-- ===== Window Action — Quotations (for Fusion Plating menu) ===== -->
|
<!-- ===== Window Action — Quotations (for Fusion Plating menu) ===== -->
|
||||||
<record id="action_fp_quotations" model="ir.actions.act_window">
|
<record id="action_fp_quotations" model="ir.actions.act_window">
|
||||||
<field name="name">Quotations</field>
|
<field name="name">Quotations</field>
|
||||||
@@ -115,7 +285,8 @@
|
|||||||
<field name="view_mode">list,form,kanban</field>
|
<field name="view_mode">list,form,kanban</field>
|
||||||
<field name="domain">[('state', 'in', ('draft', 'sent'))]</field>
|
<field name="domain">[('state', 'in', ('draft', 'sent'))]</field>
|
||||||
<field name="view_ids" eval="[(5, 0, 0),
|
<field name="view_ids" eval="[(5, 0, 0),
|
||||||
(0, 0, {'view_mode': 'list', 'view_id': ref('view_sale_order_list_fp')})]"/>
|
(0, 0, {'view_mode': 'list', 'view_id': ref('view_sale_order_list_fp_quotes')})]"/>
|
||||||
|
<field name="search_view_id" ref="view_sale_order_search_fp_quotes"/>
|
||||||
<field name="context">{'default_x_fc_delivery_method': 'shipping_partner'}</field>
|
<field name="context">{'default_x_fc_delivery_method': 'shipping_partner'}</field>
|
||||||
<field name="help" type="html">
|
<field name="help" type="html">
|
||||||
<p class="o_view_nocontent_smiling_face">
|
<p class="o_view_nocontent_smiling_face">
|
||||||
|
|||||||
@@ -4,4 +4,5 @@
|
|||||||
|
|
||||||
from . import fp_direct_order_wizard
|
from . import fp_direct_order_wizard
|
||||||
from . import fp_direct_order_line
|
from . import fp_direct_order_line
|
||||||
|
from . import fp_add_from_so_wizard
|
||||||
from . import fp_part_catalog_import_wizard
|
from . import fp_part_catalog_import_wizard
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright 2026 Nexa Systems Inc.
|
||||||
|
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||||
|
# Part of the Fusion Plating product family.
|
||||||
|
|
||||||
|
from odoo import _, api, fields, models
|
||||||
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
|
class FpAddFromSoWizard(models.TransientModel):
|
||||||
|
"""Pick lines from a prior sale.order and clone them onto the direct-order wizard.
|
||||||
|
|
||||||
|
Entry: a button on the direct-order wizard. The source SO list is
|
||||||
|
filtered to the wizard's current customer. Selected SO lines are
|
||||||
|
mapped back to fp.direct.order.line rows (part, coating, qty, price,
|
||||||
|
treatments, description).
|
||||||
|
"""
|
||||||
|
_name = 'fp.add.from.so.wizard'
|
||||||
|
_description = 'Fusion Plating - Add Lines From Prior SO'
|
||||||
|
|
||||||
|
direct_order_wizard_id = fields.Many2one(
|
||||||
|
'fp.direct.order.wizard',
|
||||||
|
required=True,
|
||||||
|
ondelete='cascade',
|
||||||
|
)
|
||||||
|
partner_id = fields.Many2one(
|
||||||
|
related='direct_order_wizard_id.partner_id', readonly=True,
|
||||||
|
)
|
||||||
|
source_order_id = fields.Many2one(
|
||||||
|
'sale.order', string='Source Sales Order',
|
||||||
|
domain="[('partner_id', '=', partner_id), ('state', 'in', ('sale', 'done'))]",
|
||||||
|
help='Pick a prior confirmed order for this customer.',
|
||||||
|
)
|
||||||
|
source_line_ids = fields.Many2many(
|
||||||
|
'sale.order.line',
|
||||||
|
string='Lines to Copy',
|
||||||
|
domain="[('order_id', '=', source_order_id)]",
|
||||||
|
help='Tick the lines you want to replicate on the new direct order.',
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.onchange('source_order_id')
|
||||||
|
def _onchange_source_order_id(self):
|
||||||
|
self.source_line_ids = False
|
||||||
|
|
||||||
|
def action_copy_lines(self):
|
||||||
|
self.ensure_one()
|
||||||
|
if not self.source_order_id:
|
||||||
|
raise UserError(_('Pick a source sales order.'))
|
||||||
|
if not self.source_line_ids:
|
||||||
|
raise UserError(_('Pick at least one line to copy.'))
|
||||||
|
|
||||||
|
Line = self.env['fp.direct.order.line']
|
||||||
|
wizard = self.direct_order_wizard_id
|
||||||
|
copied = 0
|
||||||
|
for src in self.source_line_ids:
|
||||||
|
if not src.x_fc_part_catalog_id or not src.x_fc_coating_config_id:
|
||||||
|
# Skip SO lines that predate the plating fields
|
||||||
|
continue
|
||||||
|
Line.create({
|
||||||
|
'wizard_id': wizard.id,
|
||||||
|
'part_catalog_id': src.x_fc_part_catalog_id.id,
|
||||||
|
'coating_config_id': src.x_fc_coating_config_id.id,
|
||||||
|
'treatment_ids': [(6, 0, src.x_fc_treatment_ids.ids)],
|
||||||
|
'quantity': int(src.product_uom_qty) or 1,
|
||||||
|
'unit_price': src.price_unit or 0.0,
|
||||||
|
'part_deadline': src.x_fc_part_deadline,
|
||||||
|
'rush_order': src.x_fc_rush_order,
|
||||||
|
'wo_group_tag': src.x_fc_wo_group_tag or False,
|
||||||
|
'line_description': src.name,
|
||||||
|
})
|
||||||
|
copied += 1
|
||||||
|
|
||||||
|
if not copied:
|
||||||
|
raise UserError(_(
|
||||||
|
'None of the selected lines carry plating part / coating '
|
||||||
|
'fields, so there was nothing to copy. Pick lines from a '
|
||||||
|
'direct order created with the new wizard.'
|
||||||
|
))
|
||||||
|
|
||||||
|
return {
|
||||||
|
'type': 'ir.actions.act_window',
|
||||||
|
'res_model': 'fp.direct.order.wizard',
|
||||||
|
'res_id': wizard.id,
|
||||||
|
'view_mode': 'form',
|
||||||
|
'target': 'new',
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_fp_add_from_so_wizard_form" model="ir.ui.view">
|
||||||
|
<field name="name">fp.add.from.so.wizard.form</field>
|
||||||
|
<field name="model">fp.add.from.so.wizard</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="Add Lines From Prior SO">
|
||||||
|
<sheet>
|
||||||
|
<div class="oe_title">
|
||||||
|
<h1>Copy Lines From Prior Order</h1>
|
||||||
|
<p class="text-muted">
|
||||||
|
Pick one of this customer's previous confirmed orders,
|
||||||
|
then tick the lines you want replicated on the new
|
||||||
|
direct order. Each copied row can still be edited
|
||||||
|
before confirming.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<group>
|
||||||
|
<field name="direct_order_wizard_id" invisible="1"/>
|
||||||
|
<field name="partner_id" readonly="1"/>
|
||||||
|
<field name="source_order_id"
|
||||||
|
options="{'no_create': True, 'no_open': True}"/>
|
||||||
|
</group>
|
||||||
|
<separator string="Lines on Source Order"/>
|
||||||
|
<field name="source_line_ids"
|
||||||
|
invisible="not source_order_id">
|
||||||
|
<list>
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="x_fc_part_catalog_id"/>
|
||||||
|
<field name="x_fc_coating_config_id"/>
|
||||||
|
<field name="product_uom_qty"/>
|
||||||
|
<field name="price_unit"/>
|
||||||
|
<field name="x_fc_part_deadline"/>
|
||||||
|
</list>
|
||||||
|
</field>
|
||||||
|
</sheet>
|
||||||
|
<footer>
|
||||||
|
<button name="action_copy_lines"
|
||||||
|
type="object"
|
||||||
|
string="Copy Selected Lines"
|
||||||
|
class="btn-primary"/>
|
||||||
|
<button string="Cancel" special="cancel" class="btn-secondary"/>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
@@ -3,7 +3,8 @@
|
|||||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||||
# Part of the Fusion Plating product family.
|
# Part of the Fusion Plating product family.
|
||||||
|
|
||||||
from odoo import api, fields, models
|
from odoo import _, api, fields, models
|
||||||
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
class FpDirectOrderLine(models.TransientModel):
|
class FpDirectOrderLine(models.TransientModel):
|
||||||
@@ -18,16 +19,48 @@ class FpDirectOrderLine(models.TransientModel):
|
|||||||
)
|
)
|
||||||
sequence = fields.Integer(default=10)
|
sequence = fields.Integer(default=10)
|
||||||
|
|
||||||
|
# ---- Part ----
|
||||||
part_catalog_id = fields.Many2one(
|
part_catalog_id = fields.Many2one(
|
||||||
'fp.part.catalog',
|
'fp.part.catalog',
|
||||||
string='Part',
|
string='Part',
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
|
part_number = fields.Char(
|
||||||
|
related='part_catalog_id.part_number', readonly=True,
|
||||||
|
)
|
||||||
|
part_revision = fields.Char(
|
||||||
|
related='part_catalog_id.revision', readonly=True,
|
||||||
|
)
|
||||||
|
surface_area = fields.Float(
|
||||||
|
related='part_catalog_id.surface_area', readonly=True, digits=(12, 4),
|
||||||
|
)
|
||||||
|
surface_area_uom = fields.Selection(
|
||||||
|
related='part_catalog_id.surface_area_uom', readonly=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- New revision (optional) ----
|
||||||
|
create_new_revision = fields.Boolean(
|
||||||
|
string='This is a New Revision',
|
||||||
|
help='Check if the customer sent an updated drawing or 3D model. '
|
||||||
|
'A new part revision will be created and linked to this line.',
|
||||||
|
)
|
||||||
|
new_drawing_file = fields.Binary(string='New Drawing / 3D Model')
|
||||||
|
new_drawing_filename = fields.Char(string='Filename')
|
||||||
|
revision_note = fields.Char(string='Revision Note')
|
||||||
|
|
||||||
|
# ---- Treatments ----
|
||||||
coating_config_id = fields.Many2one(
|
coating_config_id = fields.Many2one(
|
||||||
'fp.coating.config',
|
'fp.coating.config',
|
||||||
string='Primary Treatment',
|
string='Primary Treatment',
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
|
treatment_ids = fields.Many2many(
|
||||||
|
'fp.treatment',
|
||||||
|
string='Additional Treatments',
|
||||||
|
help='Extra pre/post treatments applied to this line.',
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- Qty / price ----
|
||||||
quantity = fields.Integer(string='Qty', default=1, required=True)
|
quantity = fields.Integer(string='Qty', default=1, required=True)
|
||||||
currency_id = fields.Many2one(related='wizard_id.currency_id')
|
currency_id = fields.Many2one(related='wizard_id.currency_id')
|
||||||
unit_price = fields.Monetary(
|
unit_price = fields.Monetary(
|
||||||
@@ -40,7 +73,206 @@ class FpDirectOrderLine(models.TransientModel):
|
|||||||
compute='_compute_line_subtotal',
|
compute='_compute_line_subtotal',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# ---- Scheduling / fulfilment ----
|
||||||
|
part_deadline = fields.Date(
|
||||||
|
string='Part Deadline',
|
||||||
|
help='Per-line deadline. Defaults to SO customer deadline if blank.',
|
||||||
|
)
|
||||||
|
rush_order = fields.Boolean(string='Rush')
|
||||||
|
wo_group_tag = fields.Char(
|
||||||
|
string='WO Group',
|
||||||
|
help='Free-text tag. Lines sharing a tag (e.g. "WO#1", "WO#2") '
|
||||||
|
'will be batched into one manufacturing order.',
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- Phase C: polish ----
|
||||||
|
part_wo_description = fields.Text(
|
||||||
|
string='On Work Order',
|
||||||
|
help='Extra detail printed on the work order travelling sheet. '
|
||||||
|
'Kept separate from the customer-facing description.',
|
||||||
|
)
|
||||||
|
start_at_node_id = fields.Many2one(
|
||||||
|
'fusion.plating.process.node',
|
||||||
|
string='Start at Node',
|
||||||
|
domain="[('parent_id', 'child_of', coating_config_id and coating_config_id.recipe_id.id)]",
|
||||||
|
help='For re-work jobs: pick the recipe step where this job should '
|
||||||
|
'begin. Skips ancestor steps in the generated work order.',
|
||||||
|
)
|
||||||
|
is_one_off = fields.Boolean(
|
||||||
|
string='One-off Part',
|
||||||
|
help='Do not save this as a reusable part in the catalog after the '
|
||||||
|
'order is created. Useful for quote-only or prototype parts.',
|
||||||
|
)
|
||||||
|
push_to_defaults = fields.Boolean(
|
||||||
|
string='Save as Default',
|
||||||
|
help='After submit, write this line\'s coating + additional '
|
||||||
|
'treatments back onto the part catalog as its new defaults.',
|
||||||
|
)
|
||||||
|
quote_id = fields.Many2one(
|
||||||
|
'fp.quote.configurator',
|
||||||
|
string='Linked Quote',
|
||||||
|
domain="[('partner_id', '=', parent.partner_id), ('state', 'in', ['sent','accepted','won'])]",
|
||||||
|
help='Optional: link this line to a prior quote. The unit price '
|
||||||
|
'auto-fills from the quote\'s final price (or override).',
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- Description ----
|
||||||
|
description_template_id = fields.Many2one(
|
||||||
|
'fp.sale.description.template',
|
||||||
|
string='Description Template',
|
||||||
|
)
|
||||||
|
line_description = fields.Text(
|
||||||
|
string='Line Description',
|
||||||
|
help='This text becomes the description of the sale order line. '
|
||||||
|
'Edit freely — your changes override the template.',
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- Missing info per line ----
|
||||||
|
is_missing_info = fields.Boolean(
|
||||||
|
string='Missing Info',
|
||||||
|
compute='_compute_is_missing_info',
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- Computes ----
|
||||||
@api.depends('quantity', 'unit_price')
|
@api.depends('quantity', 'unit_price')
|
||||||
def _compute_line_subtotal(self):
|
def _compute_line_subtotal(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec.line_subtotal = (rec.quantity or 0) * (rec.unit_price or 0.0)
|
rec.line_subtotal = (rec.quantity or 0) * (rec.unit_price or 0.0)
|
||||||
|
|
||||||
|
@api.depends('part_catalog_id', 'coating_config_id', 'unit_price', 'quantity')
|
||||||
|
def _compute_is_missing_info(self):
|
||||||
|
for rec in self:
|
||||||
|
rec.is_missing_info = not (
|
||||||
|
rec.part_catalog_id
|
||||||
|
and rec.coating_config_id
|
||||||
|
and rec.unit_price
|
||||||
|
and rec.quantity
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- Onchange ----
|
||||||
|
@api.onchange('quote_id')
|
||||||
|
def _onchange_quote_id(self):
|
||||||
|
"""Auto-fill part, coating, and unit price from the linked quote."""
|
||||||
|
if not self.quote_id:
|
||||||
|
return
|
||||||
|
q = self.quote_id
|
||||||
|
if q.part_catalog_id and not self.part_catalog_id:
|
||||||
|
self.part_catalog_id = q.part_catalog_id
|
||||||
|
if q.coating_config_id and not self.coating_config_id:
|
||||||
|
self.coating_config_id = q.coating_config_id
|
||||||
|
if not self.unit_price:
|
||||||
|
final = q.estimator_override_price or q.calculated_price
|
||||||
|
if final and q.quantity:
|
||||||
|
self.unit_price = final / q.quantity
|
||||||
|
|
||||||
|
@api.onchange('part_catalog_id')
|
||||||
|
def _onchange_part_defaults(self):
|
||||||
|
"""When a part is picked, seed coating + treatments from its catalog defaults."""
|
||||||
|
if not self.part_catalog_id:
|
||||||
|
return
|
||||||
|
if not self.coating_config_id and self.part_catalog_id.x_fc_default_coating_config_id:
|
||||||
|
self.coating_config_id = self.part_catalog_id.x_fc_default_coating_config_id
|
||||||
|
if not self.treatment_ids and self.part_catalog_id.x_fc_default_treatment_ids:
|
||||||
|
self.treatment_ids = self.part_catalog_id.x_fc_default_treatment_ids
|
||||||
|
|
||||||
|
@api.onchange('coating_config_id', 'quantity', 'part_catalog_id')
|
||||||
|
def _onchange_lookup_price(self):
|
||||||
|
"""Auto-fill unit_price from customer price list when available."""
|
||||||
|
if self.unit_price:
|
||||||
|
return
|
||||||
|
partner = self.wizard_id.partner_id
|
||||||
|
if not (partner and self.coating_config_id):
|
||||||
|
return
|
||||||
|
price = self.env['fp.customer.price.list']._find_price(
|
||||||
|
partner.id,
|
||||||
|
self.coating_config_id.id,
|
||||||
|
quantity=self.quantity or 1,
|
||||||
|
)
|
||||||
|
if price:
|
||||||
|
self.unit_price = price.unit_price
|
||||||
|
|
||||||
|
@api.onchange('description_template_id')
|
||||||
|
def _onchange_description_template(self):
|
||||||
|
if self.description_template_id:
|
||||||
|
self.line_description = self.description_template_id.description
|
||||||
|
|
||||||
|
@api.onchange('part_catalog_id', 'coating_config_id')
|
||||||
|
def _onchange_suggest_template(self):
|
||||||
|
"""Offer a sensible default template — part-specific wins.
|
||||||
|
|
||||||
|
Priority (first non-empty result wins):
|
||||||
|
1. This part's lowest-sequence active template
|
||||||
|
2. This customer's templates (no part)
|
||||||
|
3. This coating's templates (no part)
|
||||||
|
4. Don't auto-pick — user has to choose
|
||||||
|
"""
|
||||||
|
if self.description_template_id or self.line_description:
|
||||||
|
return
|
||||||
|
Template = self.env['fp.sale.description.template']
|
||||||
|
partner = self.wizard_id.partner_id
|
||||||
|
|
||||||
|
if self.part_catalog_id:
|
||||||
|
match = Template.search([
|
||||||
|
('active', '=', True),
|
||||||
|
('part_catalog_id', '=', self.part_catalog_id.id),
|
||||||
|
], order='sequence', limit=1)
|
||||||
|
if match:
|
||||||
|
self.description_template_id = match.id
|
||||||
|
self.line_description = match.description
|
||||||
|
return
|
||||||
|
|
||||||
|
if partner:
|
||||||
|
match = Template.search([
|
||||||
|
('active', '=', True),
|
||||||
|
('part_catalog_id', '=', False),
|
||||||
|
('partner_id', '=', partner.id),
|
||||||
|
], order='sequence', limit=1)
|
||||||
|
if match:
|
||||||
|
self.description_template_id = match.id
|
||||||
|
self.line_description = match.description
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.coating_config_id:
|
||||||
|
match = Template.search([
|
||||||
|
('active', '=', True),
|
||||||
|
('part_catalog_id', '=', False),
|
||||||
|
('partner_id', '=', False),
|
||||||
|
('coating_config_id', '=', self.coating_config_id.id),
|
||||||
|
], order='sequence', limit=1)
|
||||||
|
if match:
|
||||||
|
self.description_template_id = match.id
|
||||||
|
self.line_description = match.description
|
||||||
|
|
||||||
|
# ---- Helpers ----
|
||||||
|
def _get_or_bump_revision(self):
|
||||||
|
"""Return the part to use for the SO line, optionally bumping revision."""
|
||||||
|
self.ensure_one()
|
||||||
|
part = self.part_catalog_id
|
||||||
|
if not self.create_new_revision:
|
||||||
|
return part
|
||||||
|
if not self.new_drawing_file:
|
||||||
|
raise UserError(_(
|
||||||
|
'Line %s: upload the new drawing before confirming.'
|
||||||
|
) % (part.name or part.part_number or '?'))
|
||||||
|
|
||||||
|
drawing_att = self.env['ir.attachment'].create({
|
||||||
|
'name': self.new_drawing_filename or 'drawing.pdf',
|
||||||
|
'datas': self.new_drawing_file,
|
||||||
|
'res_model': 'fp.part.catalog',
|
||||||
|
'res_id': part.id,
|
||||||
|
})
|
||||||
|
part.action_create_revision()
|
||||||
|
new_rev = self.env['fp.part.catalog'].search([
|
||||||
|
('parent_part_id', '=', (part.parent_part_id or part).id),
|
||||||
|
('is_latest_revision', '=', True),
|
||||||
|
], limit=1, order='revision_number desc')
|
||||||
|
if not new_rev:
|
||||||
|
return part
|
||||||
|
|
||||||
|
new_rev.write({'revision_note': self.revision_note or False})
|
||||||
|
fname = (self.new_drawing_filename or '').lower()
|
||||||
|
if fname.endswith(('.step', '.stp', '.stl', '.iges', '.igs', '.brep', '.brp')):
|
||||||
|
new_rev.model_attachment_id = drawing_att.id
|
||||||
|
else:
|
||||||
|
new_rev.drawing_attachment_ids = [(4, drawing_att.id)]
|
||||||
|
return new_rev
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||||
# Part of the Fusion Plating product family.
|
# Part of the Fusion Plating product family.
|
||||||
|
|
||||||
from odoo import api, fields, models, _
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
@@ -11,64 +11,56 @@ class FpDirectOrderWizard(models.TransientModel):
|
|||||||
"""Direct order entry for repeat customers.
|
"""Direct order entry for repeat customers.
|
||||||
|
|
||||||
Skips the quotation stage when the customer has already sent a PO.
|
Skips the quotation stage when the customer has already sent a PO.
|
||||||
Creates a sale.order and calls action_confirm() in one step.
|
Creates a sale.order with one sale.order.line per wizard line and
|
||||||
Optionally bumps the part catalog revision when a new drawing is uploaded.
|
calls action_confirm() in one step.
|
||||||
"""
|
"""
|
||||||
_name = 'fp.direct.order.wizard'
|
_name = 'fp.direct.order.wizard'
|
||||||
_description = 'Fusion Plating — Direct Order Entry'
|
_description = 'Fusion Plating - Direct Order Entry'
|
||||||
|
|
||||||
|
# ---- Customer ----
|
||||||
partner_id = fields.Many2one(
|
partner_id = fields.Many2one(
|
||||||
'res.partner', string='Customer', required=True,
|
'res.partner', string='Customer', required=True,
|
||||||
domain="[('customer_rank', '>', 0)]",
|
domain="[('customer_rank', '>', 0)]",
|
||||||
)
|
)
|
||||||
|
partner_invoice_id = fields.Many2one(
|
||||||
# Part selection
|
'res.partner', string='Invoice Address',
|
||||||
part_catalog_id = fields.Many2one(
|
domain="['|', ('id', '=', partner_id), "
|
||||||
'fp.part.catalog', string='Part', required=True,
|
"('parent_id', '=', partner_id)]",
|
||||||
domain="[('partner_id', '=', partner_id), ('is_latest_revision', '=', True)]",
|
|
||||||
)
|
)
|
||||||
part_number = fields.Char(related='part_catalog_id.part_number', readonly=True)
|
partner_shipping_id = fields.Many2one(
|
||||||
current_revision = fields.Char(related='part_catalog_id.revision', readonly=True)
|
'res.partner', string='Delivery Address',
|
||||||
surface_area = fields.Float(
|
domain="['|', ('id', '=', partner_id), "
|
||||||
related='part_catalog_id.surface_area', readonly=True, digits=(12, 4),
|
"('parent_id', '=', partner_id)]",
|
||||||
)
|
)
|
||||||
surface_area_uom = fields.Selection(
|
customer_job_number = fields.Char(
|
||||||
related='part_catalog_id.surface_area_uom', readonly=True,
|
string='Customer Job #',
|
||||||
|
help="Customer's internal job number for cross-referencing. "
|
||||||
|
"Appears on work orders and invoices.",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Revision upload (optional — creates a new revision of the part)
|
# ---- Scheduling ----
|
||||||
create_new_revision = fields.Boolean(
|
planned_start_date = fields.Date(
|
||||||
string='This is a New Revision',
|
string='Planned Start', default=fields.Date.context_today,
|
||||||
help='Check if the customer sent an updated drawing or 3D model. '
|
|
||||||
'A new part revision will be created and linked to this order.',
|
|
||||||
)
|
)
|
||||||
new_drawing_file = fields.Binary(
|
internal_deadline = fields.Date(string='Internal Deadline')
|
||||||
string='New Drawing / 3D Model',
|
customer_deadline = fields.Date(string='Customer Deadline')
|
||||||
help='STEP, STL, IGES, or PDF. Used when creating a new revision.',
|
|
||||||
|
# ---- Order flags (Phase B) ----
|
||||||
|
is_blanket_order = fields.Boolean(
|
||||||
|
string='Blanket Sales Order',
|
||||||
|
help='Blanket orders release parts in quantities over time.',
|
||||||
)
|
)
|
||||||
new_drawing_filename = fields.Char(string='Filename')
|
block_partial_shipments = fields.Boolean(
|
||||||
revision_note = fields.Char(
|
string='Block Partial Shipments',
|
||||||
string='Revision Note', help='What changed in this revision?',
|
help='Ship all-or-nothing; partial pickings are blocked.',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Order details
|
# ---- PO (required — that's what makes this a "direct" order) ----
|
||||||
coating_config_id = fields.Many2one(
|
po_number = fields.Char(string='Customer PO #', required=True)
|
||||||
'fp.coating.config', string='Coating', required=True,
|
po_attachment_file = fields.Binary(string='PO Document', required=True)
|
||||||
)
|
po_attachment_filename = fields.Char(string='PO Filename')
|
||||||
quantity = fields.Integer(string='Quantity', required=True, default=1)
|
|
||||||
currency_id = fields.Many2one(
|
# ---- Fulfilment (order-level) ----
|
||||||
'res.currency', string='Currency',
|
|
||||||
default=lambda self: self.env.company.currency_id,
|
|
||||||
)
|
|
||||||
unit_price = fields.Monetary(
|
|
||||||
string='Unit Price', currency_field='currency_id',
|
|
||||||
help='Negotiated price per part. Leave blank to set later.',
|
|
||||||
)
|
|
||||||
line_subtotal = fields.Monetary(
|
|
||||||
string='Line Subtotal', currency_field='currency_id',
|
|
||||||
compute='_compute_line_subtotal',
|
|
||||||
)
|
|
||||||
rush_order = fields.Boolean(string='Rush Order')
|
|
||||||
delivery_method = fields.Selection(
|
delivery_method = fields.Selection(
|
||||||
[('local_delivery', 'Local Delivery'),
|
[('local_delivery', 'Local Delivery'),
|
||||||
('shipping_partner', 'Shipping Partner'),
|
('shipping_partner', 'Shipping Partner'),
|
||||||
@@ -76,12 +68,11 @@ class FpDirectOrderWizard(models.TransientModel):
|
|||||||
string='Delivery Method',
|
string='Delivery Method',
|
||||||
)
|
)
|
||||||
|
|
||||||
# PO (required — that's what makes this a "direct" order)
|
# ---- Currency + invoicing ----
|
||||||
po_number = fields.Char(string='Customer PO #', required=True)
|
currency_id = fields.Many2one(
|
||||||
po_attachment_file = fields.Binary(string='PO Document', required=True)
|
'res.currency', string='Currency',
|
||||||
po_attachment_filename = fields.Char(string='PO Filename')
|
default=lambda self: self.env.company.currency_id,
|
||||||
|
)
|
||||||
# Invoice strategy (pulled from partner default if set)
|
|
||||||
invoice_strategy = fields.Selection(
|
invoice_strategy = fields.Selection(
|
||||||
[('deposit', 'Deposit'), ('progress', 'Progress Billing'),
|
[('deposit', 'Deposit'), ('progress', 'Progress Billing'),
|
||||||
('net_terms', 'Net Terms'), ('cod_prepay', 'COD / Prepay')],
|
('net_terms', 'Net Terms'), ('cod_prepay', 'COD / Prepay')],
|
||||||
@@ -89,163 +80,104 @@ class FpDirectOrderWizard(models.TransientModel):
|
|||||||
)
|
)
|
||||||
deposit_percent = fields.Float(string='Deposit %')
|
deposit_percent = fields.Float(string='Deposit %')
|
||||||
progress_initial_percent = fields.Float(
|
progress_initial_percent = fields.Float(
|
||||||
string='Progress — Initial %', default=50.0,
|
string='Progress - Initial %', default=50.0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# ---- Notes ----
|
||||||
notes = fields.Text(string='Internal Notes')
|
notes = fields.Text(string='Internal Notes')
|
||||||
|
|
||||||
# Description template picker — the domain is dynamically narrowed to
|
# ---- Lines ----
|
||||||
# this part's canned descriptions first. When no part is chosen it
|
line_ids = fields.One2many(
|
||||||
# falls through to generic templates.
|
'fp.direct.order.line', 'wizard_id', string='Order Lines',
|
||||||
description_template_id = fields.Many2one(
|
|
||||||
'fp.sale.description.template',
|
|
||||||
string='Description Template',
|
|
||||||
domain="[('active','=',True), "
|
|
||||||
" '|', '|', '|', "
|
|
||||||
" ('part_catalog_id','=',part_catalog_id), "
|
|
||||||
" ('part_catalog_id','=',False), "
|
|
||||||
" ('partner_id','=',partner_id), "
|
|
||||||
" ('coating_config_id','=',coating_config_id)]",
|
|
||||||
help='Pick a saved description and tweak it below. Part-specific '
|
|
||||||
'descriptions appear first, then customer / coating / generic.',
|
|
||||||
)
|
)
|
||||||
line_description = fields.Text(
|
total_amount = fields.Monetary(
|
||||||
string='Line Description',
|
string='Order Total',
|
||||||
help='This text becomes the description of the sale order line. '
|
compute='_compute_totals', currency_field='currency_id',
|
||||||
'Edit freely — your changes override the template.',
|
)
|
||||||
|
total_qty = fields.Integer(string='Total Qty', compute='_compute_totals')
|
||||||
|
total_line_count = fields.Integer(
|
||||||
|
string='Line Count', compute='_compute_totals',
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.depends('quantity', 'unit_price')
|
# ---- Missing info banner ----
|
||||||
def _compute_line_subtotal(self):
|
missing_info_msg = fields.Char(compute='_compute_missing_info_msg')
|
||||||
|
|
||||||
|
# ---- Computes ----
|
||||||
|
@api.depends('line_ids.line_subtotal', 'line_ids.quantity')
|
||||||
|
def _compute_totals(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec.line_subtotal = (rec.quantity or 0) * (rec.unit_price or 0.0)
|
rec.total_amount = sum(rec.line_ids.mapped('line_subtotal'))
|
||||||
|
rec.total_qty = sum(rec.line_ids.mapped('quantity'))
|
||||||
|
rec.total_line_count = len(rec.line_ids)
|
||||||
|
|
||||||
|
@api.depends('line_ids.part_catalog_id', 'line_ids.coating_config_id',
|
||||||
|
'line_ids.unit_price', 'line_ids.quantity')
|
||||||
|
def _compute_missing_info_msg(self):
|
||||||
|
for rec in self:
|
||||||
|
has_missing = False
|
||||||
|
for line in rec.line_ids:
|
||||||
|
if (not line.part_catalog_id
|
||||||
|
or not line.coating_config_id
|
||||||
|
or not line.unit_price
|
||||||
|
or not line.quantity):
|
||||||
|
has_missing = True
|
||||||
|
break
|
||||||
|
rec.missing_info_msg = (
|
||||||
|
'Some lines are missing quote information '
|
||||||
|
'(part / treatment / price / qty). '
|
||||||
|
'Verify before confirming the order.'
|
||||||
|
if has_missing else False
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- Onchange ----
|
||||||
@api.onchange('partner_id')
|
@api.onchange('partner_id')
|
||||||
def _onchange_partner_id(self):
|
def _onchange_partner_id(self):
|
||||||
"""Reset part selection when customer changes + pull invoice defaults."""
|
"""Seed invoice defaults + default addresses when customer changes."""
|
||||||
self.part_catalog_id = False
|
|
||||||
if self.partner_id and 'x_fc_default_invoice_strategy' in self.partner_id._fields:
|
if self.partner_id and 'x_fc_default_invoice_strategy' in self.partner_id._fields:
|
||||||
self.invoice_strategy = self.partner_id.x_fc_default_invoice_strategy or False
|
self.invoice_strategy = self.partner_id.x_fc_default_invoice_strategy or False
|
||||||
self.deposit_percent = self.partner_id.x_fc_default_deposit_percent or 0.0
|
self.deposit_percent = self.partner_id.x_fc_default_deposit_percent or 0.0
|
||||||
|
|
||||||
@api.onchange('description_template_id')
|
|
||||||
def _onchange_description_template(self):
|
|
||||||
"""Copy the template's text into the editable paragraph — user tweaks from there."""
|
|
||||||
if self.description_template_id:
|
|
||||||
self.line_description = self.description_template_id.description
|
|
||||||
|
|
||||||
@api.onchange('part_catalog_id', 'coating_config_id', 'partner_id')
|
|
||||||
def _onchange_suggest_template(self):
|
|
||||||
"""Offer a sensible default template — part-specific wins.
|
|
||||||
|
|
||||||
Priority (first non-empty result wins):
|
|
||||||
1. This part's lowest-sequence active template
|
|
||||||
2. This customer's templates (no part)
|
|
||||||
3. This coating's templates (no part)
|
|
||||||
4. Don't auto-pick — user has to choose
|
|
||||||
"""
|
|
||||||
if self.description_template_id or self.line_description:
|
|
||||||
return # respect user's choice
|
|
||||||
Template = self.env['fp.sale.description.template']
|
|
||||||
|
|
||||||
# 1. Part-specific
|
|
||||||
if self.part_catalog_id:
|
|
||||||
match = Template.search([
|
|
||||||
('active', '=', True),
|
|
||||||
('part_catalog_id', '=', self.part_catalog_id.id),
|
|
||||||
], order='sequence', limit=1)
|
|
||||||
if match:
|
|
||||||
self.description_template_id = match.id
|
|
||||||
self.line_description = match.description
|
|
||||||
return
|
|
||||||
|
|
||||||
# 2. Customer (no part)
|
|
||||||
if self.partner_id:
|
if self.partner_id:
|
||||||
match = Template.search([
|
addrs = self.partner_id.address_get(['invoice', 'delivery'])
|
||||||
('active', '=', True),
|
self.partner_invoice_id = addrs.get('invoice') or self.partner_id.id
|
||||||
('part_catalog_id', '=', False),
|
self.partner_shipping_id = addrs.get('delivery') or self.partner_id.id
|
||||||
('partner_id', '=', self.partner_id.id),
|
else:
|
||||||
], order='sequence', limit=1)
|
self.partner_invoice_id = False
|
||||||
if match:
|
self.partner_shipping_id = False
|
||||||
self.description_template_id = match.id
|
|
||||||
self.line_description = match.description
|
|
||||||
return
|
|
||||||
|
|
||||||
# 3. Coating (no part, no customer restriction)
|
# ---- Actions ----
|
||||||
if self.coating_config_id:
|
def action_add_from_prior_so(self):
|
||||||
match = Template.search([
|
"""Open a sub-wizard to copy lines from a prior sale.order."""
|
||||||
('active', '=', True),
|
self.ensure_one()
|
||||||
('part_catalog_id', '=', False),
|
if not self.partner_id:
|
||||||
('partner_id', '=', False),
|
raise UserError(_('Pick a customer first.'))
|
||||||
('coating_config_id', '=', self.coating_config_id.id),
|
sub = self.env['fp.add.from.so.wizard'].create({
|
||||||
], order='sequence', limit=1)
|
'direct_order_wizard_id': self.id,
|
||||||
if match:
|
})
|
||||||
self.description_template_id = match.id
|
return {
|
||||||
self.line_description = match.description
|
'type': 'ir.actions.act_window',
|
||||||
return
|
'name': _('Add Lines From Prior SO'),
|
||||||
|
'res_model': 'fp.add.from.so.wizard',
|
||||||
@api.onchange('coating_config_id', 'quantity', 'partner_id')
|
'res_id': sub.id,
|
||||||
def _onchange_lookup_price(self):
|
'view_mode': 'form',
|
||||||
"""Auto-fill unit_price from customer price list when available."""
|
'target': 'new',
|
||||||
if not (self.partner_id and self.coating_config_id):
|
}
|
||||||
return
|
|
||||||
# Don't overwrite a manually-entered price
|
|
||||||
if self.unit_price:
|
|
||||||
return
|
|
||||||
price = self.env['fp.customer.price.list']._find_price(
|
|
||||||
self.partner_id.id, self.coating_config_id.id,
|
|
||||||
quantity=self.quantity or 1,
|
|
||||||
)
|
|
||||||
if price:
|
|
||||||
self.unit_price = price.unit_price
|
|
||||||
|
|
||||||
def action_create_order(self):
|
def action_create_order(self):
|
||||||
"""Create and confirm the sale order, optionally bumping part revision."""
|
"""Create and confirm the sale order with one SO line per wizard line."""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
|
if not self.line_ids:
|
||||||
|
raise UserError(_('Add at least one part line before confirming.'))
|
||||||
|
if not self.po_attachment_file:
|
||||||
|
raise UserError(_('Upload the customer PO document.'))
|
||||||
|
|
||||||
if self.create_new_revision and not self.new_drawing_file:
|
# 1. Save the PO attachment once
|
||||||
raise UserError(_(
|
|
||||||
'Please upload the new drawing when creating a new revision.'
|
|
||||||
))
|
|
||||||
if self.quantity <= 0:
|
|
||||||
raise UserError(_('Quantity must be positive.'))
|
|
||||||
|
|
||||||
# 1. Optional: create a new part revision from the uploaded drawing
|
|
||||||
part = self.part_catalog_id
|
|
||||||
if self.create_new_revision:
|
|
||||||
drawing_att = self.env['ir.attachment'].create({
|
|
||||||
'name': self.new_drawing_filename or 'drawing.pdf',
|
|
||||||
'datas': self.new_drawing_file,
|
|
||||||
'res_model': 'fp.part.catalog',
|
|
||||||
'res_id': part.id,
|
|
||||||
})
|
|
||||||
# action_create_revision returns an action dict; we keep the part
|
|
||||||
part.action_create_revision()
|
|
||||||
new_rev = self.env['fp.part.catalog'].search(
|
|
||||||
[('parent_part_id', '=', (part.parent_part_id or part).id),
|
|
||||||
('is_latest_revision', '=', True)],
|
|
||||||
limit=1, order='revision_number desc',
|
|
||||||
)
|
|
||||||
if new_rev:
|
|
||||||
new_rev.write({
|
|
||||||
'revision_note': self.revision_note or False,
|
|
||||||
})
|
|
||||||
# Attach drawing/model based on extension
|
|
||||||
fname = (self.new_drawing_filename or '').lower()
|
|
||||||
if fname.endswith(('.step', '.stp', '.stl', '.iges', '.igs', '.brep', '.brp')):
|
|
||||||
new_rev.model_attachment_id = drawing_att.id
|
|
||||||
else:
|
|
||||||
new_rev.drawing_attachment_ids = [(4, drawing_att.id)]
|
|
||||||
part = new_rev
|
|
||||||
|
|
||||||
# 2. Save the PO attachment
|
|
||||||
po_att = self.env['ir.attachment'].create({
|
po_att = self.env['ir.attachment'].create({
|
||||||
'name': self.po_attachment_filename or 'po.pdf',
|
'name': self.po_attachment_filename or 'po.pdf',
|
||||||
'datas': self.po_attachment_file,
|
'datas': self.po_attachment_file,
|
||||||
'mimetype': 'application/pdf',
|
'mimetype': 'application/pdf',
|
||||||
})
|
})
|
||||||
|
|
||||||
# 3. Find or create the generic plating service product (same as configurator)
|
# 2. Find or create the generic plating service product
|
||||||
product = self.env['product.product'].search(
|
product = self.env['product.product'].search(
|
||||||
[('default_code', '=', 'FP-SERVICE')], limit=1,
|
[('default_code', '=', 'FP-SERVICE')], limit=1,
|
||||||
)
|
)
|
||||||
@@ -259,53 +191,85 @@ class FpDirectOrderWizard(models.TransientModel):
|
|||||||
'purchase_ok': False,
|
'purchase_ok': False,
|
||||||
})
|
})
|
||||||
|
|
||||||
# Canonical line label (always present)
|
# 3. Build SO header
|
||||||
header = '%s — %s Rev %s (x%d)' % (
|
|
||||||
self.coating_config_id.name,
|
|
||||||
part.name,
|
|
||||||
part.revision or part.revision_number,
|
|
||||||
self.quantity,
|
|
||||||
)
|
|
||||||
# Optional extended description from template / user tweak
|
|
||||||
extended = (self.line_description or '').strip()
|
|
||||||
if extended:
|
|
||||||
line_desc = '%s\n\n%s' % (header, extended)
|
|
||||||
else:
|
|
||||||
line_desc = header
|
|
||||||
|
|
||||||
# Bump template usage counter so popular ones float to the top over time
|
|
||||||
if self.description_template_id:
|
|
||||||
self.description_template_id._register_usage()
|
|
||||||
|
|
||||||
so_vals = {
|
so_vals = {
|
||||||
'partner_id': self.partner_id.id,
|
'partner_id': self.partner_id.id,
|
||||||
'x_fc_part_catalog_id': part.id,
|
'partner_invoice_id': (
|
||||||
'x_fc_coating_config_id': self.coating_config_id.id,
|
self.partner_invoice_id.id or self.partner_id.id
|
||||||
'x_fc_rush_order': self.rush_order,
|
),
|
||||||
'x_fc_delivery_method': self.delivery_method,
|
'partner_shipping_id': (
|
||||||
|
self.partner_shipping_id.id or self.partner_id.id
|
||||||
|
),
|
||||||
'x_fc_po_number': self.po_number,
|
'x_fc_po_number': self.po_number,
|
||||||
'x_fc_po_attachment_id': po_att.id,
|
'x_fc_po_attachment_id': po_att.id,
|
||||||
'x_fc_po_received': True,
|
'x_fc_po_received': True,
|
||||||
|
'x_fc_customer_job_number': self.customer_job_number or False,
|
||||||
|
'x_fc_planned_start_date': self.planned_start_date,
|
||||||
|
'x_fc_internal_deadline': self.internal_deadline,
|
||||||
|
'commitment_date': self.customer_deadline,
|
||||||
'x_fc_invoice_strategy': self.invoice_strategy,
|
'x_fc_invoice_strategy': self.invoice_strategy,
|
||||||
'x_fc_deposit_percent': self.deposit_percent,
|
'x_fc_deposit_percent': self.deposit_percent,
|
||||||
'x_fc_progress_initial_percent': self.progress_initial_percent,
|
'x_fc_progress_initial_percent': self.progress_initial_percent,
|
||||||
|
'x_fc_delivery_method': self.delivery_method,
|
||||||
|
'x_fc_is_blanket_order': self.is_blanket_order,
|
||||||
|
'x_fc_block_partial_shipments': self.block_partial_shipments,
|
||||||
'origin': 'Direct Order',
|
'origin': 'Direct Order',
|
||||||
'note': self.notes or False,
|
'note': self.notes or False,
|
||||||
'order_line': [(0, 0, {
|
'order_line': [],
|
||||||
|
}
|
||||||
|
|
||||||
|
# 4. One SO line per wizard line
|
||||||
|
for line in self.line_ids:
|
||||||
|
part = line._get_or_bump_revision()
|
||||||
|
header = '%s - %s Rev %s (x%d)' % (
|
||||||
|
line.coating_config_id.name,
|
||||||
|
part.name,
|
||||||
|
part.revision or part.revision_number,
|
||||||
|
line.quantity,
|
||||||
|
)
|
||||||
|
extended = (line.line_description or '').strip()
|
||||||
|
line_desc = (header + '\n\n' + extended) if extended else header
|
||||||
|
if line.description_template_id:
|
||||||
|
line.description_template_id._register_usage()
|
||||||
|
|
||||||
|
so_vals['order_line'].append((0, 0, {
|
||||||
'product_id': product.id,
|
'product_id': product.id,
|
||||||
'name': line_desc,
|
'name': line_desc,
|
||||||
'product_uom_qty': self.quantity,
|
'product_uom_qty': line.quantity,
|
||||||
'price_unit': self.unit_price or 0.0,
|
'price_unit': line.unit_price or 0.0,
|
||||||
})],
|
'x_fc_part_catalog_id': part.id,
|
||||||
}
|
'x_fc_coating_config_id': line.coating_config_id.id,
|
||||||
|
'x_fc_treatment_ids': [(6, 0, line.treatment_ids.ids)],
|
||||||
|
'x_fc_part_deadline': line.part_deadline,
|
||||||
|
'x_fc_rush_order': line.rush_order,
|
||||||
|
'x_fc_wo_group_tag': line.wo_group_tag or False,
|
||||||
|
'x_fc_part_wo_description': line.part_wo_description or False,
|
||||||
|
'x_fc_start_at_node_id': line.start_at_node_id.id or False,
|
||||||
|
'x_fc_is_one_off': line.is_one_off,
|
||||||
|
'x_fc_quote_id': line.quote_id.id or False,
|
||||||
|
}))
|
||||||
|
|
||||||
|
# 5. Create + confirm
|
||||||
so = self.env['sale.order'].create(so_vals)
|
so = self.env['sale.order'].create(so_vals)
|
||||||
# Immediately confirm — skips quote/send step entirely
|
|
||||||
so.action_confirm()
|
so.action_confirm()
|
||||||
so.message_post(
|
|
||||||
body=_(
|
# 6. Push-to-defaults (C4) — after the part has been resolved /
|
||||||
'Direct order created from PO %s. Quotation stage skipped.'
|
# revision-bumped, write coating + treatments back onto the part
|
||||||
) % self.po_number,
|
# catalog entry so the next order inherits the same defaults.
|
||||||
)
|
for line in self.line_ids:
|
||||||
|
if not line.push_to_defaults:
|
||||||
|
continue
|
||||||
|
part = line.part_catalog_id
|
||||||
|
if not part or line.is_one_off:
|
||||||
|
continue
|
||||||
|
part.write({
|
||||||
|
'x_fc_default_coating_config_id': line.coating_config_id.id or False,
|
||||||
|
'x_fc_default_treatment_ids': [(6, 0, line.treatment_ids.ids)],
|
||||||
|
})
|
||||||
|
so.message_post(body=_(
|
||||||
|
'Direct order created from PO %s with %d line(s). '
|
||||||
|
'Quotation stage skipped.'
|
||||||
|
) % (self.po_number, len(self.line_ids)))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
|
|||||||
@@ -6,11 +6,17 @@
|
|||||||
<field name="model">fp.direct.order.wizard</field>
|
<field name="model">fp.direct.order.wizard</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Direct Order Entry">
|
<form string="Direct Order Entry">
|
||||||
|
<div class="alert alert-warning mb-0"
|
||||||
|
role="alert"
|
||||||
|
invisible="not missing_info_msg">
|
||||||
|
<i class="fa fa-exclamation-triangle me-2"/>
|
||||||
|
<field name="missing_info_msg" readonly="1" nolabel="1"/>
|
||||||
|
</div>
|
||||||
<sheet>
|
<sheet>
|
||||||
<div class="oe_title">
|
<div class="oe_title">
|
||||||
<h1>New Direct Order</h1>
|
<h1>New Direct Order</h1>
|
||||||
<p class="text-muted">
|
<p class="text-muted">
|
||||||
Skip the quotation stage — create a confirmed order
|
Skip the quotation stage - create a confirmed order
|
||||||
when the customer has already sent a PO.
|
when the customer has already sent a PO.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -18,59 +24,32 @@
|
|||||||
<group>
|
<group>
|
||||||
<group string="Customer">
|
<group string="Customer">
|
||||||
<field name="partner_id" options="{'no_create_edit': True}"/>
|
<field name="partner_id" options="{'no_create_edit': True}"/>
|
||||||
|
<field name="partner_invoice_id"
|
||||||
|
options="{'no_create_edit': True}"
|
||||||
|
invisible="not partner_id"/>
|
||||||
|
<field name="partner_shipping_id"
|
||||||
|
options="{'no_create_edit': True}"
|
||||||
|
invisible="not partner_id"/>
|
||||||
|
<field name="customer_job_number"/>
|
||||||
</group>
|
</group>
|
||||||
<group string="Purchase Order">
|
<group string="Purchase Order">
|
||||||
<field name="po_number"/>
|
<field name="po_number"/>
|
||||||
<field name="po_attachment_file" filename="po_attachment_filename"/>
|
<field name="po_attachment_file"
|
||||||
|
filename="po_attachment_filename"/>
|
||||||
<field name="po_attachment_filename" invisible="1"/>
|
<field name="po_attachment_filename" invisible="1"/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
<group string="Part">
|
|
||||||
<group>
|
|
||||||
<field name="part_catalog_id"
|
|
||||||
options="{'no_create_edit': True}"
|
|
||||||
context="{'default_partner_id': partner_id}"/>
|
|
||||||
<field name="part_number" invisible="not part_catalog_id"/>
|
|
||||||
<field name="current_revision" invisible="not part_catalog_id"/>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<label for="surface_area" invisible="not part_catalog_id"/>
|
|
||||||
<div class="o_row" invisible="not part_catalog_id">
|
|
||||||
<field name="surface_area" nolabel="1" class="oe_inline"/>
|
|
||||||
<field name="surface_area_uom" nolabel="1" class="oe_inline"/>
|
|
||||||
</div>
|
|
||||||
</group>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<group string="New Revision (optional)">
|
|
||||||
<field name="create_new_revision"/>
|
|
||||||
<field name="new_drawing_file"
|
|
||||||
filename="new_drawing_filename"
|
|
||||||
invisible="not create_new_revision"
|
|
||||||
required="create_new_revision"/>
|
|
||||||
<field name="new_drawing_filename" invisible="1"/>
|
|
||||||
<field name="revision_note" invisible="not create_new_revision"/>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<group>
|
<group>
|
||||||
<group string="Order">
|
<group string="Scheduling">
|
||||||
<field name="coating_config_id"/>
|
<field name="planned_start_date"/>
|
||||||
<field name="quantity"/>
|
<field name="internal_deadline"/>
|
||||||
<field name="currency_id" invisible="1"/>
|
<field name="customer_deadline"/>
|
||||||
<field name="unit_price" widget="monetary"
|
<field name="is_blanket_order"/>
|
||||||
options="{'currency_field': 'currency_id'}"/>
|
<field name="block_partial_shipments"/>
|
||||||
<field name="line_subtotal" widget="monetary"
|
|
||||||
options="{'currency_field': 'currency_id'}"/>
|
|
||||||
</group>
|
</group>
|
||||||
<group string="Fulfilment">
|
<group string="Fulfilment & Invoicing">
|
||||||
<field name="rush_order"/>
|
|
||||||
<field name="delivery_method"/>
|
<field name="delivery_method"/>
|
||||||
</group>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<group string="Invoicing">
|
|
||||||
<group>
|
|
||||||
<field name="invoice_strategy"/>
|
<field name="invoice_strategy"/>
|
||||||
<label for="deposit_percent"
|
<label for="deposit_percent"
|
||||||
invisible="invoice_strategy != 'deposit'"/>
|
invisible="invoice_strategy != 'deposit'"/>
|
||||||
@@ -89,19 +68,120 @@
|
|||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
<!-- ===== Line description — template picker + editable paragraph ===== -->
|
<notebook>
|
||||||
<group string="Line Description">
|
<page string="Lines" name="lines">
|
||||||
<field name="description_template_id"
|
<div class="mb-2">
|
||||||
options="{'no_create': True, 'no_open': True}"
|
<button name="action_add_from_prior_so"
|
||||||
placeholder="Start typing to search saved descriptions..."/>
|
type="object"
|
||||||
<field name="line_description" nolabel="1" colspan="2"
|
string="+ Add From Prior SO"
|
||||||
placeholder="Pick a template above, then tweak the text here. Whatever you leave in this box lands on the sale order line."/>
|
class="btn-secondary"
|
||||||
</group>
|
invisible="not partner_id"/>
|
||||||
|
</div>
|
||||||
<group string="Internal Notes">
|
<field name="line_ids">
|
||||||
<field name="notes" nolabel="1" colspan="2"
|
<list editable="bottom"
|
||||||
placeholder="Notes for the estimator / planner — not shown to the customer."/>
|
decoration-warning="is_missing_info">
|
||||||
</group>
|
<field name="is_missing_info" column_invisible="1"/>
|
||||||
|
<field name="sequence" widget="handle"/>
|
||||||
|
<field name="part_catalog_id"
|
||||||
|
context="{'default_partner_id': parent.partner_id}"
|
||||||
|
domain="[('partner_id', '=', parent.partner_id), ('is_latest_revision', '=', True)]"
|
||||||
|
options="{'no_create_edit': True}"/>
|
||||||
|
<field name="coating_config_id"/>
|
||||||
|
<field name="treatment_ids"
|
||||||
|
widget="many2many_tags"
|
||||||
|
optional="hide"/>
|
||||||
|
<field name="quantity"/>
|
||||||
|
<field name="unit_price"
|
||||||
|
widget="monetary"
|
||||||
|
options="{'currency_field': 'currency_id'}"/>
|
||||||
|
<field name="line_subtotal"
|
||||||
|
widget="monetary"
|
||||||
|
options="{'currency_field': 'currency_id'}"
|
||||||
|
sum="Total"/>
|
||||||
|
<field name="part_deadline"/>
|
||||||
|
<field name="wo_group_tag" optional="show"/>
|
||||||
|
<field name="rush_order" optional="hide"/>
|
||||||
|
<field name="currency_id" column_invisible="1"/>
|
||||||
|
</list>
|
||||||
|
<form string="Order Line">
|
||||||
|
<group>
|
||||||
|
<group string="Part & Treatment">
|
||||||
|
<field name="part_catalog_id"
|
||||||
|
context="{'default_partner_id': parent.partner_id}"
|
||||||
|
domain="[('partner_id', '=', parent.partner_id), ('is_latest_revision', '=', True)]"/>
|
||||||
|
<field name="part_number"
|
||||||
|
invisible="not part_catalog_id"/>
|
||||||
|
<field name="part_revision"
|
||||||
|
invisible="not part_catalog_id"/>
|
||||||
|
<field name="coating_config_id"/>
|
||||||
|
<field name="treatment_ids"
|
||||||
|
widget="many2many_tags"/>
|
||||||
|
</group>
|
||||||
|
<group string="Qty & Price">
|
||||||
|
<field name="quote_id"
|
||||||
|
options="{'no_create': True, 'no_open': True}"/>
|
||||||
|
<field name="quantity"/>
|
||||||
|
<field name="unit_price"
|
||||||
|
widget="monetary"
|
||||||
|
options="{'currency_field': 'currency_id'}"/>
|
||||||
|
<field name="line_subtotal"
|
||||||
|
widget="monetary"
|
||||||
|
options="{'currency_field': 'currency_id'}"/>
|
||||||
|
<field name="part_deadline"/>
|
||||||
|
<field name="rush_order"/>
|
||||||
|
<field name="wo_group_tag"/>
|
||||||
|
<field name="currency_id" invisible="1"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
<group string="New Revision (optional)">
|
||||||
|
<field name="create_new_revision"/>
|
||||||
|
<field name="new_drawing_file"
|
||||||
|
filename="new_drawing_filename"
|
||||||
|
invisible="not create_new_revision"
|
||||||
|
required="create_new_revision"/>
|
||||||
|
<field name="new_drawing_filename" invisible="1"/>
|
||||||
|
<field name="revision_note"
|
||||||
|
invisible="not create_new_revision"/>
|
||||||
|
</group>
|
||||||
|
<group string="Line Description">
|
||||||
|
<field name="description_template_id"
|
||||||
|
options="{'no_create': True, 'no_open': True}"
|
||||||
|
placeholder="Start typing to search saved descriptions..."/>
|
||||||
|
<field name="line_description"
|
||||||
|
nolabel="1" colspan="2"
|
||||||
|
placeholder="Pick a template above, then tweak the text here."/>
|
||||||
|
</group>
|
||||||
|
<group string="Work Order (internal)">
|
||||||
|
<field name="part_wo_description"
|
||||||
|
nolabel="1" colspan="2"
|
||||||
|
placeholder="Extra detail for the travelling sheet. Not shown to the customer."/>
|
||||||
|
<field name="start_at_node_id"
|
||||||
|
options="{'no_create': True}"/>
|
||||||
|
<field name="is_one_off"/>
|
||||||
|
<field name="push_to_defaults"
|
||||||
|
invisible="is_one_off"/>
|
||||||
|
</group>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
<group class="mt-3">
|
||||||
|
<group>
|
||||||
|
<field name="total_line_count" readonly="1"/>
|
||||||
|
<field name="total_qty" readonly="1"/>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<field name="total_amount"
|
||||||
|
widget="monetary"
|
||||||
|
options="{'currency_field': 'currency_id'}"
|
||||||
|
readonly="1"/>
|
||||||
|
<field name="currency_id" invisible="1"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
</page>
|
||||||
|
<page string="Notes" name="notes">
|
||||||
|
<field name="notes" nolabel="1"
|
||||||
|
placeholder="Internal notes for the estimator / planner - not shown to the customer."/>
|
||||||
|
</page>
|
||||||
|
</notebook>
|
||||||
|
|
||||||
</sheet>
|
</sheet>
|
||||||
<footer>
|
<footer>
|
||||||
|
|||||||
Reference in New Issue
Block a user