Compare commits
2 Commits
d13517071c
...
7dea212c13
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7dea212c13 | ||
|
|
10e3ada9e9 |
6
fusion-plating/fusion_plating_invoicing/__init__.py
Normal file
6
fusion-plating/fusion_plating_invoicing/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
# Part of the Fusion Plating product family.
|
||||
|
||||
from . import models
|
||||
46
fusion-plating/fusion_plating_invoicing/__manifest__.py
Normal file
46
fusion-plating/fusion_plating_invoicing/__manifest__.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
# Part of the Fusion Plating product family.
|
||||
|
||||
{
|
||||
'name': 'Fusion Plating — Invoicing',
|
||||
'version': '19.0.1.0.0',
|
||||
'category': 'Manufacturing/Plating',
|
||||
'summary': 'Invoice strategy engine with deposit, progress billing, net terms, COD/prepay, and account holds.',
|
||||
'description': """
|
||||
Fusion Plating — Invoicing
|
||||
===========================
|
||||
|
||||
Part of the Fusion Plating product family by Nexa Systems Inc.
|
||||
|
||||
Provides:
|
||||
- Four invoice strategies: deposit, progress billing, net terms, COD/prepay
|
||||
- Customer-level default strategy with auto-fill on sale orders
|
||||
- Account hold flag on customers to block SO confirmation and invoicing
|
||||
- Automated deposit and full invoice creation on SO confirmation
|
||||
""",
|
||||
'author': 'Nexa Systems Inc.',
|
||||
'website': 'https://www.nexasystems.ca',
|
||||
'maintainer': 'Nexa Systems Inc.',
|
||||
'support': 'support@nexasystems.ca',
|
||||
'license': 'OPL-1',
|
||||
'price': 0.00,
|
||||
'currency': 'CAD',
|
||||
'depends': [
|
||||
'fusion_plating_configurator',
|
||||
'sale_management',
|
||||
'account',
|
||||
],
|
||||
'data': [
|
||||
'security/fp_invoicing_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'views/fp_invoice_strategy_views.xml',
|
||||
'views/res_partner_views.xml',
|
||||
'views/sale_order_views.xml',
|
||||
'views/fp_invoicing_menu.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': False,
|
||||
'auto_install': False,
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
# Part of the Fusion Plating product family.
|
||||
|
||||
from . import fp_invoice_strategy_default
|
||||
from . import res_partner
|
||||
from . import sale_order
|
||||
from . import account_move
|
||||
@@ -0,0 +1,28 @@
|
||||
# -*- 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 models, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = 'account.move'
|
||||
|
||||
def action_post(self):
|
||||
"""Check account hold before posting invoices."""
|
||||
for move in self:
|
||||
if move.move_type in ('out_invoice', 'out_refund') and move.partner_id:
|
||||
if move.partner_id.x_fc_account_hold:
|
||||
is_manager = self.env.user.has_group(
|
||||
'fusion_plating.group_fusion_plating_manager'
|
||||
)
|
||||
if not is_manager:
|
||||
raise UserError(_(
|
||||
'Cannot post invoice — customer "%s" is on account hold.\n'
|
||||
'Reason: %s\n\n'
|
||||
'Contact a manager to override.'
|
||||
) % (move.partner_id.name,
|
||||
move.partner_id.x_fc_account_hold_reason or 'No reason specified'))
|
||||
return super().action_post()
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- 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 FpInvoiceStrategyDefault(models.Model):
|
||||
"""Customer-level default invoice strategy.
|
||||
|
||||
When a new sale order is created for this customer, the invoice
|
||||
strategy and deposit percentage auto-fill from this record.
|
||||
"""
|
||||
_name = 'fp.invoice.strategy.default'
|
||||
_description = 'Fusion Plating — Invoice Strategy Default'
|
||||
_order = 'partner_id'
|
||||
|
||||
partner_id = fields.Many2one(
|
||||
'res.partner', string='Customer', required=True, ondelete='cascade',
|
||||
domain="[('customer_rank', '>', 0)]",
|
||||
)
|
||||
default_strategy = fields.Selection(
|
||||
[('deposit', 'Deposit'), ('progress', 'Progress Billing'),
|
||||
('net_terms', 'Net Terms'), ('cod_prepay', 'COD / Prepay')],
|
||||
string='Default Strategy', required=True,
|
||||
)
|
||||
default_deposit_percent = fields.Float(
|
||||
string='Deposit %', help='Deposit percentage if strategy is Deposit (e.g. 50.0).',
|
||||
)
|
||||
payment_term_id = fields.Many2one(
|
||||
'account.payment.term', string='Payment Terms',
|
||||
)
|
||||
notes = fields.Text(string='Notes')
|
||||
|
||||
_sql_constraints = [
|
||||
('fp_invoice_strategy_partner_uniq', 'unique(partner_id)',
|
||||
'Only one invoice strategy default per customer.'),
|
||||
]
|
||||
@@ -0,0 +1,22 @@
|
||||
# -*- 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 ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
x_fc_account_hold = fields.Boolean(
|
||||
string='Account Hold', tracking=True,
|
||||
help='When active, blocks SO confirmation, invoicing, and shipping.',
|
||||
)
|
||||
x_fc_account_hold_reason = fields.Text(string='Hold Reason')
|
||||
x_fc_account_hold_date = fields.Datetime(
|
||||
string='Hold Date', help='When the hold was placed.',
|
||||
)
|
||||
x_fc_account_hold_by_id = fields.Many2one(
|
||||
'res.users', string='Hold Placed By',
|
||||
)
|
||||
106
fusion-plating/fusion_plating_invoicing/models/sale_order.py
Normal file
106
fusion-plating/fusion_plating_invoicing/models/sale_order.py
Normal file
@@ -0,0 +1,106 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
# Part of the Fusion Plating product family.
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
@api.onchange('partner_id')
|
||||
def _onchange_partner_id_invoice_strategy(self):
|
||||
"""Auto-fill invoice strategy from customer defaults."""
|
||||
if self.partner_id:
|
||||
default = self.env['fp.invoice.strategy.default'].search(
|
||||
[('partner_id', '=', self.partner_id.id)], limit=1,
|
||||
)
|
||||
if default:
|
||||
self.x_fc_invoice_strategy = default.default_strategy
|
||||
self.x_fc_deposit_percent = default.default_deposit_percent
|
||||
if default.payment_term_id:
|
||||
self.payment_term_id = default.payment_term_id
|
||||
|
||||
def action_confirm(self):
|
||||
"""Override to check account hold and trigger invoice strategy."""
|
||||
for order in self:
|
||||
# --- Account hold check ---
|
||||
if order.partner_id.x_fc_account_hold:
|
||||
is_manager = self.env.user.has_group(
|
||||
'fusion_plating.group_fusion_plating_manager'
|
||||
)
|
||||
if not is_manager:
|
||||
raise UserError(_(
|
||||
'Cannot confirm — customer "%s" is on account hold.\n'
|
||||
'Reason: %s\n\n'
|
||||
'Contact a manager to override.'
|
||||
) % (order.partner_id.name,
|
||||
order.partner_id.x_fc_account_hold_reason or 'No reason specified'))
|
||||
else:
|
||||
# Manager gets a warning in chatter but can proceed
|
||||
order.message_post(
|
||||
body=_(
|
||||
'Warning: Customer "%s" is on account hold (reason: %s). '
|
||||
'Order confirmed by manager override.'
|
||||
) % (order.partner_id.name,
|
||||
order.partner_id.x_fc_account_hold_reason or 'N/A'),
|
||||
)
|
||||
|
||||
res = super().action_confirm()
|
||||
|
||||
# --- Invoice strategy automation ---
|
||||
for order in self:
|
||||
strategy = order.x_fc_invoice_strategy
|
||||
if not strategy:
|
||||
continue
|
||||
|
||||
if strategy == 'deposit' and order.x_fc_deposit_percent:
|
||||
order._create_deposit_invoice()
|
||||
elif strategy == 'cod_prepay':
|
||||
order._create_full_invoice()
|
||||
|
||||
return res
|
||||
|
||||
def _create_deposit_invoice(self):
|
||||
"""Create a deposit (down payment) invoice for the deposit percentage."""
|
||||
self.ensure_one()
|
||||
percent = self.x_fc_deposit_percent
|
||||
if not percent or percent <= 0:
|
||||
return
|
||||
|
||||
try:
|
||||
# Use Odoo's standard down payment mechanism
|
||||
wizard = self.env['sale.advance.payment.inv'].create({
|
||||
'advance_payment_method': 'percentage',
|
||||
'amount': percent,
|
||||
})
|
||||
wizard.with_context(active_ids=self.ids, active_model='sale.order').create_invoices()
|
||||
self.message_post(
|
||||
body=_('Deposit invoice (%.0f%%) created automatically — strategy: Deposit.') % percent,
|
||||
)
|
||||
except Exception as e:
|
||||
_logger.warning('Failed to create deposit invoice for SO %s: %s', self.name, e)
|
||||
self.message_post(
|
||||
body=_('Failed to auto-create deposit invoice: %s. Create manually.') % str(e),
|
||||
)
|
||||
|
||||
def _create_full_invoice(self):
|
||||
"""Create a full invoice immediately (COD/Prepay strategy)."""
|
||||
self.ensure_one()
|
||||
try:
|
||||
invoices = self._create_invoices()
|
||||
if invoices:
|
||||
self.message_post(
|
||||
body=_('Full invoice created automatically — strategy: COD / Prepay.'),
|
||||
)
|
||||
except Exception as e:
|
||||
_logger.warning('Failed to create COD invoice for SO %s: %s', self.name, e)
|
||||
self.message_post(
|
||||
body=_('Failed to auto-create invoice: %s. Create manually.') % str(e),
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2026 Nexa Systems Inc.
|
||||
License OPL-1 (Odoo Proprietary License v1.0)
|
||||
Part of the Fusion Plating product family.
|
||||
-->
|
||||
<odoo>
|
||||
|
||||
<record id="group_fp_accounting" model="res.groups">
|
||||
<field name="name">Accounting</field>
|
||||
<field name="sequence">58</field>
|
||||
<field name="privilege_id" ref="fusion_plating.res_groups_privilege_fusion_plating"/>
|
||||
<field name="implied_ids" eval="[(4, ref('fusion_plating.group_fusion_plating_supervisor'))]"/>
|
||||
<field name="user_ids" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -0,0 +1,4 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_fp_invoice_strategy_operator,fp.invoice.strategy.default.operator,model_fp_invoice_strategy_default,fusion_plating.group_fusion_plating_operator,1,0,0,0
|
||||
access_fp_invoice_strategy_accounting,fp.invoice.strategy.default.accounting,model_fp_invoice_strategy_default,group_fp_accounting,1,1,1,0
|
||||
access_fp_invoice_strategy_manager,fp.invoice.strategy.default.manager,model_fp_invoice_strategy_default,fusion_plating.group_fusion_plating_manager,1,1,1,1
|
||||
|
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2026 Nexa Systems Inc.
|
||||
License OPL-1 (Odoo Proprietary License v1.0)
|
||||
Part of the Fusion Plating product family.
|
||||
-->
|
||||
<odoo>
|
||||
|
||||
<!-- ===== Strategy Default List View ===== -->
|
||||
<record id="view_fp_invoice_strategy_default_list" model="ir.ui.view">
|
||||
<field name="name">fp.invoice.strategy.default.list</field>
|
||||
<field name="model">fp.invoice.strategy.default</field>
|
||||
<field name="arch" type="xml">
|
||||
<list string="Invoice Strategy Defaults">
|
||||
<field name="partner_id"/>
|
||||
<field name="default_strategy"/>
|
||||
<field name="default_deposit_percent"/>
|
||||
<field name="payment_term_id"/>
|
||||
</list>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- ===== Strategy Default Form View ===== -->
|
||||
<record id="view_fp_invoice_strategy_default_form" model="ir.ui.view">
|
||||
<field name="name">fp.invoice.strategy.default.form</field>
|
||||
<field name="model">fp.invoice.strategy.default</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Invoice Strategy Default">
|
||||
<sheet>
|
||||
<group>
|
||||
<group>
|
||||
<field name="partner_id"/>
|
||||
<field name="default_strategy"/>
|
||||
<field name="default_deposit_percent"
|
||||
invisible="default_strategy != 'deposit'"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="payment_term_id"/>
|
||||
</group>
|
||||
</group>
|
||||
<group>
|
||||
<field name="notes" placeholder="Internal notes about this customer's billing preferences..."/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- ===== Strategy Default Search View ===== -->
|
||||
<record id="view_fp_invoice_strategy_default_search" model="ir.ui.view">
|
||||
<field name="name">fp.invoice.strategy.default.search</field>
|
||||
<field name="model">fp.invoice.strategy.default</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="partner_id"/>
|
||||
<separator/>
|
||||
<filter string="Deposit" name="deposit" domain="[('default_strategy','=','deposit')]"/>
|
||||
<filter string="Progress Billing" name="progress" domain="[('default_strategy','=','progress')]"/>
|
||||
<filter string="Net Terms" name="net_terms" domain="[('default_strategy','=','net_terms')]"/>
|
||||
<filter string="COD / Prepay" name="cod_prepay" domain="[('default_strategy','=','cod_prepay')]"/>
|
||||
<group>
|
||||
<filter string="Strategy" name="group_strategy" context="{'group_by':'default_strategy'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- ===== Window Action ===== -->
|
||||
<record id="action_fp_invoice_strategy_default" model="ir.actions.act_window">
|
||||
<field name="name">Invoice Strategy Defaults</field>
|
||||
<field name="res_model">fp.invoice.strategy.default</field>
|
||||
<field name="view_mode">list,form</field>
|
||||
<field name="search_view_id" ref="view_fp_invoice_strategy_default_search"/>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
No invoice strategy defaults defined yet
|
||||
</p>
|
||||
<p>
|
||||
Set a default invoice strategy per customer so new sale orders
|
||||
auto-fill with the correct billing method.
|
||||
</p>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2026 Nexa Systems Inc.
|
||||
License OPL-1 (Odoo Proprietary License v1.0)
|
||||
Part of the Fusion Plating product family.
|
||||
-->
|
||||
<odoo>
|
||||
|
||||
<!-- ===== Window actions (BEFORE menus) ===== -->
|
||||
<record id="action_fp_account_holds" model="ir.actions.act_window">
|
||||
<field name="name">Account Holds</field>
|
||||
<field name="res_model">res.partner</field>
|
||||
<field name="view_mode">list,form</field>
|
||||
<field name="domain">[('x_fc_account_hold', '=', True)]</field>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
No customers on account hold
|
||||
</p>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- ===== Menu items under Configuration ===== -->
|
||||
<menuitem id="menu_fp_invoice_strategy"
|
||||
name="Invoice Strategy Defaults"
|
||||
parent="fusion_plating.menu_fp_config"
|
||||
action="action_fp_invoice_strategy_default"
|
||||
sequence="60"
|
||||
groups="group_fp_accounting"/>
|
||||
|
||||
<menuitem id="menu_fp_account_holds"
|
||||
name="Account Holds"
|
||||
parent="fusion_plating.menu_fp_config"
|
||||
action="action_fp_account_holds"
|
||||
sequence="70"
|
||||
groups="group_fp_accounting"/>
|
||||
|
||||
</odoo>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2026 Nexa Systems Inc.
|
||||
License OPL-1 (Odoo Proprietary License v1.0)
|
||||
Part of the Fusion Plating product family.
|
||||
-->
|
||||
<odoo>
|
||||
|
||||
<record id="view_partner_form_account_hold" model="ir.ui.view">
|
||||
<field name="name">res.partner.form.fp.account.hold</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="inherit_id" ref="base.view_partner_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//sheet" position="before">
|
||||
<div class="alert alert-danger mb-0" role="alert"
|
||||
invisible="not x_fc_account_hold">
|
||||
<strong>Account Hold Active</strong> —
|
||||
<field name="x_fc_account_hold_reason" readonly="1" nolabel="1"/>
|
||||
<br/>
|
||||
<small>
|
||||
Placed by <field name="x_fc_account_hold_by_id" readonly="1" nolabel="1"/>
|
||||
on <field name="x_fc_account_hold_date" readonly="1" nolabel="1"/>
|
||||
</small>
|
||||
</div>
|
||||
</xpath>
|
||||
<xpath expr="//notebook" position="inside">
|
||||
<page string="Account Hold" name="account_hold_tab"
|
||||
groups="fusion_plating_invoicing.group_fp_accounting">
|
||||
<group>
|
||||
<group>
|
||||
<field name="x_fc_account_hold"/>
|
||||
<field name="x_fc_account_hold_reason"
|
||||
invisible="not x_fc_account_hold"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="x_fc_account_hold_date"
|
||||
invisible="not x_fc_account_hold"/>
|
||||
<field name="x_fc_account_hold_by_id"
|
||||
invisible="not x_fc_account_hold"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2026 Nexa Systems Inc.
|
||||
License OPL-1 (Odoo Proprietary License v1.0)
|
||||
Part of the Fusion Plating product family.
|
||||
-->
|
||||
<odoo>
|
||||
|
||||
<!-- ===== Account hold warning banner on SO form ===== -->
|
||||
<record id="view_sale_order_form_hold_banner" model="ir.ui.view">
|
||||
<field name="name">sale.order.form.fp.hold.banner</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale.view_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//form/header" position="before">
|
||||
<div class="alert alert-danger" role="alert"
|
||||
invisible="not partner_id or not partner_id.x_fc_account_hold">
|
||||
<strong>Account Hold</strong> — This customer is on account hold.
|
||||
SO confirmation, invoicing, and shipping are blocked for non-managers.
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user