changes
This commit is contained in:
@@ -15,6 +15,18 @@ _logger = logging.getLogger(__name__)
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
# Explicit related field — dotted refs like `partner_id.x_fc_account_hold`
|
||||
# in `invisible=` modifiers are fragile in Odoo 19 (the related field
|
||||
# has to be in the record cache for the evaluator). Surfacing it as a
|
||||
# plain field on sale.order makes the banner condition deterministic.
|
||||
# We resolve through `commercial_partner_id` so a hold placed on the
|
||||
# company also blocks SOs entered against any of its child contacts.
|
||||
x_fc_partner_account_hold = fields.Boolean(
|
||||
string='Customer on Account Hold',
|
||||
related='partner_id.commercial_partner_id.x_fc_account_hold',
|
||||
store=True, readonly=True,
|
||||
)
|
||||
|
||||
@api.onchange('partner_id')
|
||||
def _onchange_partner_id_invoice_strategy(self):
|
||||
"""Auto-fill plating defaults from customer profile.
|
||||
@@ -119,24 +131,27 @@ class SaleOrder(models.Model):
|
||||
) % {'so': order.name})
|
||||
|
||||
# --- Account hold check ---
|
||||
if order.partner_id.x_fc_account_hold:
|
||||
is_manager = self.env.user.has_group(
|
||||
'fusion_plating.group_fusion_plating_manager'
|
||||
)
|
||||
# Hold lives on the commercial_partner (the company). Resolve
|
||||
# through that so a hold on the parent applies to every child
|
||||
# contact too — typical case is "all of Acme is on hold", not
|
||||
# "specifically the AP clerk's contact card".
|
||||
hold_partner = order.partner_id.commercial_partner_id
|
||||
if hold_partner.x_fc_account_hold:
|
||||
is_manager = self.env['res.partner']._fp_user_can_override_account_hold()
|
||||
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'))
|
||||
) % (hold_partner.name,
|
||||
hold_partner.x_fc_account_hold_reason or 'No reason specified'))
|
||||
else:
|
||||
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'),
|
||||
) % (hold_partner.name,
|
||||
hold_partner.x_fc_account_hold_reason or 'N/A'),
|
||||
)
|
||||
|
||||
res = super().action_confirm()
|
||||
|
||||
Reference in New Issue
Block a user