616 lines
24 KiB
Python
616 lines
24 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from odoo import models, fields, api, _
|
|
from odoo.exceptions import UserError, ValidationError, Warning
|
|
from dateutil.parser import parse
|
|
import re
|
|
from odoo.osv import expression
|
|
SAUDI_MOBILE_PATTERN = r"^(\+?966)?0?5[013456789][0-9]{7}$"
|
|
|
|
class IrActionsServer(models.Model):
|
|
_inherit = 'ir.actions.server'
|
|
|
|
groups_id = fields.Many2many('res.groups', 'res_groups_server_rel', 'uid', 'gid', string='Groups')
|
|
|
|
|
|
class sponsor(models.Model):
|
|
_name = 'takaful.sponsor'
|
|
|
|
|
|
class ResPartner(models.Model):
|
|
_name = 'res.partner'
|
|
_inherit = ['res.partner', 'mail.thread']
|
|
|
|
|
|
account_number = fields.Char(string="Account Number")
|
|
bank_entity_name = fields.Char(string="Bank Entity Name")
|
|
name = fields.Char(string="Name", compute='get_partner_name', store=True, readonly=False)
|
|
|
|
#Location
|
|
branch_custom_id = fields.Many2one('branch.settings', string="Branch")
|
|
district_id = fields.Many2one('res.districts', string="District", domain="[('branch_custom_id','=',branch_custom_id)]")
|
|
|
|
# New Added
|
|
notify_by_app = fields.Boolean(string='Notify By App', default=True)
|
|
notify_by_sms = fields.Boolean(string='Notify By SMS', default=True)
|
|
notify_for_pay = fields.Boolean(string='Paying Notify By App', default=True)
|
|
notify_pay_by_app = fields.Boolean(string='Paying Notify By App', default=True)
|
|
notify_pay_by_sms = fields.Boolean(string='Paying Notify By SMS', default=True)
|
|
|
|
name_in_certificate = fields.Boolean(string='Beneficiaries Names In Certificate', default=True)
|
|
type_in_certificate = fields.Boolean(string='Beneficiaries Type In Certificate', default=True)
|
|
duration_in_certificate = fields.Boolean(string='Sponsorship Duration In Certificate', default=True)
|
|
|
|
notify_month_day = fields.Integer(string="Notify Month Day", default=1)
|
|
wait_cancel_day = fields.Integer(string="Waiting For Cancellation", default=2)
|
|
# operation_ids = fields.One2many('takaful.sponsor.operation', 'sponsor_id', string="Operations Records")
|
|
benefit_ids = fields.One2many('family.member', 'sponsor_related_id', string="Benefits Records")
|
|
related_benefits_count = fields.Integer(compute="_compute_related_benefits_count")
|
|
kafel_id = fields.Many2one('res.users')
|
|
|
|
state = fields.Selection([
|
|
('draft', 'Draft'),
|
|
('verified', 'Verified')
|
|
], string='State',default='draft', tracking=True)
|
|
|
|
check_lines = fields.Boolean()
|
|
def _get_default_preferred_communication(self):
|
|
"""Get first preferred communication method as default"""
|
|
# Check if table exists before searching (safe during module installation)
|
|
from odoo.tools import sql
|
|
if not sql.table_exists(self.env.cr, 'preferred_communication'):
|
|
return False
|
|
try:
|
|
first_comm = self.env['preferred.communication'].search([], limit=1, order='id asc')
|
|
return first_comm.id if first_comm else False
|
|
except Exception:
|
|
return False
|
|
|
|
preferred_communication = fields.Many2one('preferred.communication', string="Preferred Communication", default=_get_default_preferred_communication)
|
|
serial_code = fields.Char(string="Serial Code", readonly=True, copy=False)
|
|
|
|
responsible_user_ids = fields.Many2many(
|
|
'res.users',
|
|
'takaful_sponsor_user_rel',
|
|
'sponsor_id',
|
|
'user_id',
|
|
string='Responsible Employees'
|
|
)
|
|
|
|
operation_count = fields.Integer(
|
|
compute='_compute_operation_count',
|
|
string="# Of Operations",
|
|
readonly=True
|
|
)
|
|
|
|
kafalat_count = fields.Integer(
|
|
compute='_compute_kafalat_count',
|
|
string="# of Kafalat",
|
|
readonly=True
|
|
)
|
|
contribution_count = fields.Integer(
|
|
compute='_compute_contribution_count',
|
|
string="# of Contributions",
|
|
readonly=True
|
|
)
|
|
|
|
active_counts = fields.Integer(
|
|
string="Active Sponsors Count",
|
|
)
|
|
active = fields.Boolean(default=True)
|
|
|
|
gift_count = fields.Integer(
|
|
compute='_compute_gift_count',
|
|
string="# of Gifts",
|
|
readonly=True
|
|
)
|
|
donation_line_ids = fields.Many2many( 'donations.details.lines',
|
|
string="Donation Lines",
|
|
)
|
|
kafel_state = fields.Selection([
|
|
('active', "Active"),
|
|
('not_active', "Not Active")] ,string='Status' , compute="get_sponser_state", store=True)
|
|
|
|
|
|
_sql_constraints = [
|
|
('id_number_uniq', 'unique (id_number)', 'The ID Number Already Exist!'),
|
|
]
|
|
|
|
|
|
@api.depends('donation_line_ids.state', 'donation_line_ids.sponsorship_duration')
|
|
def get_sponser_state(self):
|
|
for rec in self:
|
|
state = 'not_active'
|
|
if rec.donation_line_ids:
|
|
for line in rec.donation_line_ids:
|
|
# permanent sponsorship → active if not in draft/closed/cancel
|
|
if line.sponsorship_duration == 'permanent' and line.state not in ['draft', 'closed', 'cancel']:
|
|
state = 'active'
|
|
break
|
|
# temporary sponsorship → active if state is active
|
|
if line.state == 'active':
|
|
state = 'active'
|
|
break
|
|
rec.kafel_state = state
|
|
|
|
def view_sponsorship_payment_action(self):
|
|
"""Enable The Sponsor To Pay Sponsorships Entries"""
|
|
sponsorship_id = self.env['takaful.sponsorship'].sudo().search([('sponsor_id', '=', self.id), ('has_delay', '=', True)], limit=1)
|
|
|
|
context = dict(self.env.context or {})
|
|
context['default_sponsor_id'] = self.id or False
|
|
context['default_sponsorship_id'] = sponsorship_id.id or False
|
|
return {
|
|
'name': _('Sponsorship Payment'),
|
|
'view_type': 'form',
|
|
'view_mode': 'tree,form',
|
|
'views': [(self.env.ref(
|
|
'odex_takaful.takaful_sponsorship_payment_tree').id, 'tree'),
|
|
(self.env.ref('odex_takaful.takaful_sponsorship_payment_form').id, 'form')],
|
|
'type': 'ir.actions.act_window',
|
|
'res_model': 'sponsorship.payment',
|
|
'domain': "[('sponsor_id','=',%s)]" % (self.id or False),
|
|
'target': 'current',
|
|
'context': context,
|
|
}
|
|
|
|
|
|
@api.constrains('is_family', 'is_benefit', 'is_donor', 'is_sponsor_portal')
|
|
def _check_family_beneficiary_exclusivity(self):
|
|
for rec in self:
|
|
is_family_or_beneficiary = rec.is_family or rec.is_benefit
|
|
|
|
is_donor_vendor_sponsor = rec.is_donor or rec.is_sponsor_portal or rec.is_vendor
|
|
|
|
if is_family_or_beneficiary and is_donor_vendor_sponsor:
|
|
raise ValidationError(_("A contact cannot be both Family/Beneficiary and Donor/Member/Sponsor at the same time!"))
|
|
|
|
def _normalize_phone_search_args(self, args):
|
|
"""Normalize phone/mobile values in domain by stripping a leading '0' if present."""
|
|
|
|
def _normalize(term):
|
|
# Term can be an operator ('&', '|', '!') or a domain triplet/list (possibly nested)
|
|
if isinstance(term, list):
|
|
# Domain leaf: ['phone', 'ilike', '0123'] or ['mobile', '=', '0123']
|
|
if len(term) == 3 and term[0] in ('phone', 'mobile') and isinstance(term[2], str):
|
|
val = term[2]
|
|
if val and val.startswith('0'):
|
|
term = [term[0], term[1], val[1:]]
|
|
else:
|
|
# Nested list: normalize inner items
|
|
term = [_normalize(t) for t in term]
|
|
return term
|
|
|
|
return [_normalize(t) for t in args] if args else args
|
|
|
|
@api.model
|
|
def search(self, args, offset=0, limit=None, order=None, count=False):
|
|
|
|
# if not self.env.context.get('from_contact_search'):
|
|
# return super().search(args, offset=offset, limit=limit, order=order, count=count)
|
|
|
|
if self.env.context.get('mail_read') or self.env.context.get('mail_message_origin'):
|
|
return super().search(args, offset=offset, limit=limit, order=order, count=count)
|
|
|
|
# Normalize phone/mobile search values (strip leading zero)
|
|
normalized_args = self._normalize_phone_search_args(args)
|
|
|
|
base_results = super().search(normalized_args, offset=offset, limit=limit, order=order)
|
|
|
|
if not base_results:
|
|
return base_results
|
|
|
|
children = super().search([('parent_id', 'in', base_results.ids)])
|
|
|
|
final_ids = list(set(base_results.ids + children.ids))
|
|
|
|
return super().search([('id', 'in', final_ids)], offset=0, limit=limit, order=order, count=count)
|
|
|
|
@api.model
|
|
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
|
|
if not args:
|
|
args = []
|
|
|
|
# If no name is provided, use standard Odoo search behavior
|
|
# This fixes the issue where empty name causes invalid domain
|
|
if not name:
|
|
return super()._name_search(name, args=args, operator=operator, limit=limit, name_get_uid=name_get_uid)
|
|
|
|
# Build search domains for the raw name and (optionally) the name
|
|
# without leading zero, to "ignore" a starting 0 in the search term.
|
|
search_terms = [name]
|
|
if name.startswith('0'):
|
|
search_terms.append(name[1:])
|
|
|
|
domain = []
|
|
for term in search_terms:
|
|
term_domain = ['|', '|',
|
|
('name', operator, term),
|
|
('id_number', operator, term),
|
|
('mobile', operator, term)]
|
|
domain = term_domain if not domain else expression.OR([domain, term_domain])
|
|
|
|
domain = expression.AND([domain, args])
|
|
parent_record_ids = self.search(domain).ids
|
|
domain = expression.OR([domain, [('parent_id', 'in', parent_record_ids)]])
|
|
return self._search(domain, limit=limit, access_rights_uid=name_get_uid)
|
|
|
|
def _compute_related_benefits_count(self):
|
|
for record in self:
|
|
record.related_benefits_count = self.env['family.member'].search_count([
|
|
('sponsor_related_id', '=', record.id)
|
|
])
|
|
def action_open_benefit_records(self):
|
|
"""Open related account.move records."""
|
|
return {
|
|
'type': 'ir.actions.act_window',
|
|
'name': 'Related Benefits',
|
|
'view_mode': 'tree,form',
|
|
'res_model': 'family.member',
|
|
'domain': [('id', 'in', self.benefit_ids.ids)],
|
|
'context': {'create': False},
|
|
}
|
|
|
|
def _compute_operation_count(self):
|
|
# Get operation_count
|
|
operation_count = self.env['takaful.sponsor.operation'].sudo().search_count([('sponsor_id', '=', self.id)])
|
|
|
|
if operation_count >0:
|
|
self.operation_count = operation_count
|
|
else:
|
|
self.operation_count = 0
|
|
|
|
|
|
def _compute_kafalat_count(self):
|
|
# Get kafalat
|
|
kafalat_count = self.env['takaful.sponsorship'].sudo().search_count([('sponsor_id', '=', self.id)])
|
|
|
|
if kafalat_count >0:
|
|
self.kafalat_count = kafalat_count
|
|
else:
|
|
self.kafalat_count = 0
|
|
|
|
def _compute_contribution_count(self):
|
|
# The current user may not have access rights for contributions.
|
|
for partner in self:
|
|
try:
|
|
partner.contribution_count = len(partner.id) * 2
|
|
except Exception:
|
|
partner.contribution_count = 50
|
|
|
|
def _compute_gift_count(self):
|
|
# The current user may not have access rights for gifts.
|
|
for partner in self:
|
|
try:
|
|
partner.gift_count = len(partner.id) * 3
|
|
except Exception:
|
|
partner.gift_count = 75
|
|
|
|
#Validition here
|
|
def check_bank_info_value(self):
|
|
# all values true
|
|
bank_info = [self.account_number,
|
|
self.iban,
|
|
self.bank_id,
|
|
self.bank_entity_name,
|
|
]
|
|
|
|
res = all(bank_info)
|
|
return res
|
|
|
|
def unlink(self):
|
|
related_contact = self.env['res.partner'].search([('parent_id', 'in', self.ids)])
|
|
sponsorships = self.env['takaful.sponsorship'].search([('sponsor_id', 'in', self.ids)])
|
|
if sponsorships or related_contact:
|
|
raise UserError(_('Contacts are associated with sponsorships') )
|
|
self.user_id.sudo().write({
|
|
"active": False
|
|
})
|
|
return super(ResPartner, self).unlink()
|
|
|
|
def on_activate_sponsor_multi(self):
|
|
for record in self:
|
|
if not record.active:
|
|
if record.user_id:
|
|
record.user_id.sudo().write({
|
|
"active": True
|
|
})
|
|
record.active = True
|
|
else:
|
|
raise UserError(_('Sponsor is already active'))
|
|
|
|
def action_save_and_close(self):
|
|
"""Save and close the form wizard - used when creating new sponsor from sponsorship form"""
|
|
self.ensure_one()
|
|
# The form will close automatically and return to parent form
|
|
return {'type': 'ir.actions.act_window_close'}
|
|
|
|
@api.model
|
|
def create(self, values):
|
|
mobile_number = values.get('mobile', False)
|
|
context = self.env.context
|
|
|
|
if mobile_number:
|
|
self._check_phone_numbers(values['mobile'])
|
|
validated_mobile_number = self.phone_format(mobile_number)
|
|
values.update({'mobile': validated_mobile_number})
|
|
|
|
if context.get('sponsor_contact'):
|
|
values.update({'lang': 'ar_001'})
|
|
values.update({'tz': 'Asia/Riyadh'})
|
|
# values.update({'account_type':'sponsor'})
|
|
values.update({'is_sponsor_portal': True})
|
|
if not values.get('serial_code'):
|
|
values['serial_code'] = self.env['ir.sequence'].next_by_code('takaful.sponsor.sequence') or 'S/0000'
|
|
|
|
res = super(ResPartner, self).create(values)
|
|
|
|
if context.get('sponsor_contact'):
|
|
if context.get('parent_model') == 'takaful.sponsorship' and context.get('parent_id'):
|
|
parent_record = self.env[context['parent_model']].browse(context['parent_id'])
|
|
parent_record.sponsor_id = res.id
|
|
|
|
|
|
# OPTIMIZATION: Skip user creation during bulk import for performance
|
|
# The context 'import_file=True' is set by Odoo's base_import module.
|
|
# Many core modules (auth_signup, base_automation, etc.) use this pattern.
|
|
# Users can be created later via a separate action or scheduled job.
|
|
if self.env.context.get('import_file'):
|
|
return res
|
|
|
|
if 'is_sponsor_portal' in values or 'is_donor' in values:
|
|
# Use .get() to safely check boolean values (handles case where only one key exists)
|
|
is_sponsor = values.get('is_sponsor_portal', False)
|
|
is_donor_val = values.get('is_donor', False)
|
|
if (is_sponsor == True or is_donor_val == True) and res.mobile:
|
|
# IMPORTANT: branch_custom_id is a RELATED field on res.users
|
|
# (related='partner_id.branch_custom_id') with store=False.
|
|
# It will be automatically computed from the partner_id.
|
|
# DO NOT pass it directly to create() - this causes unnecessary overhead.
|
|
kafeel = self.env['res.users'].sudo().create({
|
|
'name': res.name,
|
|
'sel_groups_1_9_10': 9,
|
|
'partner_id': res.id,
|
|
'login': res.mobile,
|
|
'otp_mobile_phone': res.mobile,
|
|
'otp_enabled': True,
|
|
})
|
|
res.kafel_id = kafeel
|
|
|
|
return res
|
|
|
|
def write(self, vals):
|
|
if 'mobile' in vals:
|
|
self._check_phone_numbers(vals['mobile'])
|
|
vals['mobile'] = self.phone_format(vals['mobile'])
|
|
if 'name' in vals :
|
|
if self.kafel_id:
|
|
self.kafel_id.name = vals['name']
|
|
|
|
if 'mobile' in vals :
|
|
if self.kafel_id:
|
|
self.kafel_id.login = vals['mobile']
|
|
|
|
if 'mobile' in vals and self.mobile == False:
|
|
# IMPORTANT: branch_custom_id is a RELATED field on res.users
|
|
# (related='partner_id.branch_custom_id') with store=False.
|
|
# It will be automatically computed from the partner_id.
|
|
kafeel = self.env['res.users'].sudo().create({
|
|
'name': self.name,
|
|
'sel_groups_1_9_10': 9,
|
|
'partner_id': self.id,
|
|
'login': vals['mobile'],
|
|
'otp_mobile_phone': vals['mobile'],
|
|
'otp_enabled': True,
|
|
})
|
|
self.kafel_id = kafeel
|
|
|
|
res = super(ResPartner, self).write(vals)
|
|
return res
|
|
|
|
def create_user(self):
|
|
for follower in self.message_follower_ids:
|
|
follower.sudo().unlink()
|
|
# If you add 'no_reset_password' to the context to True, it won't send an email.
|
|
# You can then set the password manually (and find a way to let the user know it).
|
|
user = self.env['res.users'].sudo().with_context(no_reset_password=False).create({
|
|
'name': self.name,
|
|
'login': self.mobile,
|
|
'phone': self.mobile,
|
|
'mobile': self.mobile,
|
|
'partner_id': self.id,
|
|
'active': True,
|
|
'city': self.city_id.name if self.city_id else False,
|
|
'lang':'ar_001',
|
|
'tz': 'Asia/Riyadh',
|
|
})
|
|
|
|
# Add groups to the user as sponsor
|
|
user.sudo().write({'groups_id': [
|
|
# in odoo relation field accept a list of commands
|
|
# command 4 means add the id in the second position must be an integer
|
|
# ref return an object so we return the id
|
|
(4, self.env.ref('odex_takaful.takaful_group_user_sponsor').id),
|
|
(3, self.env.ref('base.group_user', False).id),
|
|
(4, self.env.ref('base.group_portal', False).id)]
|
|
})
|
|
self.user_id = user.id
|
|
return self
|
|
|
|
def action_generate_users_for_imported_sponsors(self):
|
|
"""
|
|
Batch create users for imported sponsors that don't have kafel_id.
|
|
This should be called after bulk import to create portal users.
|
|
Can be triggered via a server action or manually.
|
|
"""
|
|
# Find sponsors without users that should have them
|
|
sponsors_without_users = self.search([
|
|
('is_sponsor_portal', '=', True),
|
|
('kafel_id', '=', False),
|
|
('mobile', '!=', False),
|
|
])
|
|
|
|
created_count = 0
|
|
for sponsor in sponsors_without_users:
|
|
try:
|
|
kafeel = self.env['res.users'].sudo().create({
|
|
'name': sponsor.name,
|
|
'sel_groups_1_9_10': 9,
|
|
'partner_id': sponsor.id,
|
|
'login': sponsor.mobile,
|
|
'otp_mobile_phone': sponsor.mobile,
|
|
'otp_enabled': True,
|
|
})
|
|
sponsor.kafel_id = kafeel
|
|
created_count += 1
|
|
except Exception as e:
|
|
# Log error but continue with other sponsors
|
|
import logging
|
|
_logger = logging.getLogger(__name__)
|
|
_logger.warning(f"Failed to create user for sponsor {sponsor.id}: {e}")
|
|
|
|
return {
|
|
'type': 'ir.actions.client',
|
|
'tag': 'display_notification',
|
|
'params': {
|
|
'title': _('User Generation Complete'),
|
|
'message': _('Created %s users for imported sponsors.') % created_count,
|
|
'type': 'success',
|
|
'sticky': False,
|
|
}
|
|
}
|
|
|
|
|
|
def action_open_sponsor_operation(self):
|
|
"""Open Operations History for a Sponsor"""
|
|
domain = [('sponsor_id', '=', self.id or False)]
|
|
context = dict(self.env.context or {})
|
|
context['default_sponsor_id'] = self.id or False
|
|
|
|
return {
|
|
'name': _('Sponsor Operations'),
|
|
'view_type': 'form',
|
|
'view_mode': 'tree,form',
|
|
'view_id': False,
|
|
'res_model': 'takaful.sponsor.operation',
|
|
'type': 'ir.actions.act_window',
|
|
'target': 'current',
|
|
'domain': domain,
|
|
'context': context,
|
|
}
|
|
|
|
|
|
def view_sponsorship_action(self):
|
|
"""List Sponsorships For The Sponsor"""
|
|
domain = [('sponsor_id', '=', self.id or False)]
|
|
context = dict(self.env.context or {})
|
|
context['default_sponsor_id'] = self.id or False
|
|
|
|
# view = self.env.ref('odex_takaful.takaful_sponsorship_tree')
|
|
return {
|
|
'name': _('Sponsorships'),
|
|
'view_type': 'form',
|
|
'view_mode': 'tree,form',
|
|
'view_id': False,
|
|
'res_model': 'takaful.sponsorship',
|
|
'type': 'ir.actions.act_window',
|
|
'target': 'current',
|
|
'domain': domain,
|
|
'context': context,
|
|
}
|
|
|
|
@api.model
|
|
def get_active_sponsors_users(self):
|
|
sponsors_users = self.env['res.users'].sudo().search([
|
|
("active", "=", True),
|
|
("groups_id", "=", self.env.ref("odex_takaful.takaful_group_user_sponsor").id)])#self.env['res.users'].sudo().search([])
|
|
|
|
count = len(sponsors_users) or 0
|
|
sponsors = self.env['res.partner'].sudo().search([])
|
|
for rec in sponsors:
|
|
rec.update({
|
|
"active_counts": count,
|
|
})
|
|
|
|
def show_active_sponsor_report_report(self):
|
|
self.sudo().get_active_sponsors_users()
|
|
ctx = self.env.context.copy()
|
|
return {
|
|
'name': _('Active Sponsors Count Report'),
|
|
'type': 'ir.actions.act_window',
|
|
'res_model': 'res.partner',
|
|
'view_type': 'form',
|
|
'view_mode': 'pivot',
|
|
'view_id': self.env.ref('odex_takaful.active_sponsor_report_pivot_view').id,
|
|
'target': 'main',
|
|
'context': ctx,
|
|
}
|
|
|
|
def _check_phone_numbers(self, mobile_number):
|
|
for rec in self:
|
|
mobile = str(mobile_number).strip().replace(" ", "").replace("-", "")
|
|
if not re.fullmatch(SAUDI_MOBILE_PATTERN, mobile):
|
|
raise ValidationError(_('Enter a valid Saudi mobile number'))
|
|
|
|
def action_unlink_sponsor_and_related(self):
|
|
member_ids = self.env["family.member"].sudo().search([("sponsor_related_id", "in", self.ids)])
|
|
if member_ids:
|
|
member_ids.sudo().write({"sponsor_related_id": False})
|
|
grant_partner_ids = self.env['grant.benefit'].sudo().search([
|
|
('partner_id', 'in', self.ids),
|
|
('state', 'not in', ['draft', 'new'])
|
|
]).partner_id
|
|
if grant_partner_ids:
|
|
partner_ids = self.filtered(lambda p: p.id not in grant_partner_ids)
|
|
partner_ids.sudo().write({'active': False})
|
|
|
|
def name_get(self):
|
|
result = []
|
|
for sponsor in self:
|
|
# Ensure name is always a string, never False or None
|
|
name = sponsor.name or ''
|
|
if sponsor.mobile:
|
|
name = (sponsor.name or '') + " - " + str(sponsor.mobile)
|
|
result.append((sponsor.id, name))
|
|
return result
|
|
|
|
@api.depends('company_type',
|
|
'first_name',
|
|
'second_name',
|
|
'middle_name',
|
|
'family_name',
|
|
'sponsor_title',
|
|
'suffix_title_id')
|
|
def get_partner_name(self):
|
|
for rec in self:
|
|
names = []
|
|
if rec.sponsor_title:
|
|
names.append(f"{rec.sponsor_title.shortcut if rec.sponsor_title.shortcut else rec.sponsor_title.name}/")
|
|
if rec.first_name:
|
|
names.append(rec.first_name)
|
|
if rec.second_name:
|
|
names.append(rec.second_name)
|
|
if rec.middle_name:
|
|
names.append(rec.middle_name)
|
|
if rec.family_name:
|
|
names.append(rec.family_name)
|
|
if rec.suffix_title_id:
|
|
names.append(f"({rec.suffix_title_id.shortcut if rec.suffix_title_id.shortcut else rec.suffix_title_id.name})")
|
|
if names:
|
|
rec.name = " ".join(names)
|
|
else:
|
|
rec.name = " "
|
|
|
|
class ResPartnerBank(models.Model):
|
|
_inherit = 'res.partner.bank'
|
|
|
|
def name_get(self):
|
|
result = []
|
|
for bank in self:
|
|
if bank.bank_id:
|
|
name = f"{bank.acc_number} - {bank.bank_id.name}"
|
|
else:
|
|
name = f"{bank.acc_number}"
|
|
result.append((bank.id, name))
|
|
return result
|