feat: add x_fc_authorizer_number, x_fc_account_number, x_marked_for fields; auto-link authorizer from XML
- fusion_claims: added x_fc_authorizer_number to res.partner for ADP authorizer registration numbers - fusion_claims: XML parser auto-links authorizer contact to sale order by ADP number - fusion_claims: removed size=9 constraint from x_fc_odsp_member_id - fusion_claims: authorizer number shown on OT/PT contact form - fusion_so_to_po: added x_marked_for (Many2one) field definition on purchase.order - fusion_so_to_po: added x_fc_account_number on res.partner for vendor account numbers
This commit is contained in:
@@ -66,6 +66,10 @@ class FusionXmlParser(models.AbstractModel):
|
||||
# Step 3: Create/update profile
|
||||
profile = self._find_or_create_profile(model_vals, sale_order)
|
||||
|
||||
# Step 3b: Auto-link authorizer on sale order by ADP number
|
||||
if sale_order:
|
||||
self._link_authorizer_by_adp_number(model_vals, sale_order)
|
||||
|
||||
# Step 4: Create application data record
|
||||
model_vals['profile_id'] = profile.id
|
||||
model_vals['sale_order_id'] = sale_order.id if sale_order else False
|
||||
@@ -637,6 +641,39 @@ class FusionXmlParser(models.AbstractModel):
|
||||
# ------------------------------------------------------------------
|
||||
# PROFILE MANAGEMENT
|
||||
# ------------------------------------------------------------------
|
||||
def _link_authorizer_by_adp_number(self, vals, sale_order):
|
||||
"""Auto-link the authorizer contact on the sale order using the ADP number from XML."""
|
||||
adp_number = (vals.get('authorizer_adp_number') or '').strip()
|
||||
if not adp_number or adp_number.upper() in ('NA', 'N/A', ''):
|
||||
return
|
||||
|
||||
if sale_order.x_fc_authorizer_id:
|
||||
return
|
||||
|
||||
Partner = self.env['res.partner']
|
||||
authorizer = Partner.search([
|
||||
('x_fc_authorizer_number', '=', adp_number),
|
||||
], limit=1)
|
||||
|
||||
if not authorizer:
|
||||
first = (vals.get('authorizer_first_name') or '').strip()
|
||||
last = (vals.get('authorizer_last_name') or '').strip()
|
||||
if first and last:
|
||||
authorizer = Partner.search([
|
||||
'|',
|
||||
('name', 'ilike', f'{first} {last}'),
|
||||
('name', 'ilike', f'{last}, {first}'),
|
||||
], limit=1)
|
||||
if authorizer and not authorizer.x_fc_authorizer_number:
|
||||
authorizer.write({'x_fc_authorizer_number': adp_number})
|
||||
|
||||
if authorizer:
|
||||
sale_order.write({'x_fc_authorizer_id': authorizer.id})
|
||||
_logger.info(
|
||||
'Auto-linked authorizer %s (ADP# %s) to SO %s',
|
||||
authorizer.name, adp_number, sale_order.name,
|
||||
)
|
||||
|
||||
def _find_or_create_profile(self, vals, sale_order=None):
|
||||
"""Find or create a client profile from parsed application data."""
|
||||
Profile = self.env['fusion.client.profile']
|
||||
|
||||
Reference in New Issue
Block a user