Hello everyone,
I've recently installed the Insurance Management module (great work on it!) and I'm trying to enhance its functionality. My goal is to add a page in the CRM lead notebook to display insurances created for each lead.
However, I'm encountering an error every time I try to upgrade the CRM or the Insurance Management module. Below is the code I've added:
class Lead(models.Model): _name = "crm.lead" _description = "Lead/Opportunity" _order = "priority desc, id desc" _inherit = ['mail.thread.cc', 'mail.thread.blacklist', 'mail.thread.phone', 'mail.activity.mixin', 'utm.mixin', 'format.address.mixin', ]
insurance_ids = fields.One2many('insurance.details', 'crm_lead_ref', string='Insurances', required=True, store=True)
def create_insurance_action(self): return { 'name': 'Create Insurance', 'type': 'ir.actions.act_window', 'res_model': 'insurance.details', 'view_mode': 'form', 'target': 'new', 'context': { 'default_partner_id': self.partner_id.id, 'default_lead_id': self.id }, 'views': [(False, 'form')], 'view_id': False, }
class InsuranceDetails(models.Model): _name = 'insurance.details' _inherit = ["mail.thread"]
crm_lead_ref = fields.Many2one('crm.lead', string='CRM Lead Reference', help="Reference to the CRM lead from which this insurance was created.", required=True, store=True)
def create(self, vals): if vals.get('name', 'New') == 'New': vals['name'] = self.env['ir.sequence'].next_by_code('insurance.details') or 'New'
crm_lead_ref = self.env.context.get('default_crm_lead_ref') if crm_lead_ref: vals['crm_lead_ref'] = crm_lead_ref
new_record = super(InsuranceDetails, self).create(vals) return new_record
__manifest.py__ in insurance module:
'name': 'Insurance Management', 'version': '16.0.1.1.1', 'summary': """Insurance Management & Operations""", 'description': """Insurance Management""", 'author': 'Cybrosys Techno Solutions', 'company': 'Cybrosys Techno Solutions', 'category': 'Industries', 'depends': ['crm','account', 'base'], 'license': 'AGPL-3', 'data': [ 'security/ir.model.access.csv', 'data/insurance_management_data.xml', 'views/claim_details_views.xml', 'views/employee_details_views.xml', 'views/insurance_details_views.xml', 'views/policy_details_views.xml', 'views/insurance_management_menus.xml' ],
crm_lead_views.xml:
I have extended the crm.lead model with a One2many field to insurance.details, and also have a corresponding Many2one field in insurance.details. Despite these configurations, I keep getting an error during the module upgrade.
Any insights or suggestions on what might be causing this issue or how to resolve it would be greatly appreciated