112 lines
4.8 KiB
Python
Executable File
112 lines
4.8 KiB
Python
Executable File
from odoo import models, fields, api
|
|
|
|
class sos_sales_leads(models.Model):
|
|
_name = 'sos_sales_leads'
|
|
_description = 'Sosaley Customers Management'
|
|
_rec_name="company_name"
|
|
|
|
company_name = fields.Char(string="Company Name")
|
|
transferred_on = fields.Date(string="Transferred On")
|
|
location = fields.Char(string="Location")
|
|
website_url = fields.Char(string="Website URL")
|
|
vertical_domain = fields.Many2one('sos_vertical_domain',string="Domain / Industry", ondelete="cascade")
|
|
linkedin_profile = fields.Char(string="Linkedin profile")
|
|
status = fields.Char(string="Status")
|
|
correspondence_address = fields.Text(string="Correspondence Address")
|
|
interested_in = fields.Selection(
|
|
[
|
|
('products', 'Products'),
|
|
('projects', 'Projects')
|
|
],
|
|
string="Interested In",required=True,default="products")
|
|
project_name = fields.Char(string="Project Name")
|
|
products = fields.Selection(
|
|
[
|
|
('BHMS 1.2V', 'BHMS 1.2V'),
|
|
('BHMS 2V', 'BHMS 2V'),
|
|
('BHMS 12V', 'BHMS 12V'),
|
|
('BHMS 48V', 'BHMS 48V'),
|
|
('BMS-HV', 'BMS-HV'),
|
|
('BMS-LV 100A', 'BMS-LV 100A'),
|
|
('BMS-LV 40A', 'BMS-LV 40A'),
|
|
('SBMS 55A', 'SBMS 55A'),
|
|
('MC 250W', 'MC 250W'),
|
|
('HeartTarang', 'HeartTarang')
|
|
],
|
|
string="Products")
|
|
source = fields.Selection(
|
|
[
|
|
('self', 'Self'),
|
|
('inside_sales', 'Inside Sales')
|
|
],
|
|
string="Source")
|
|
expo_name = fields.Char(string="Expo Name")
|
|
lead_generated_by = fields.Many2one(
|
|
'res.users',
|
|
string='Lead Generated By',
|
|
default=lambda self: self.env.user.id
|
|
)
|
|
line_ids_contacts = fields.One2many('sos_leads_customer_contact_lines', 'ref_id', string="Contact Details",copy=True)
|
|
convert_to_customer_btn_display = fields.Boolean(default=True)
|
|
def action_convert_to_customer(self):
|
|
self.convert_to_customer_btn_display = False
|
|
self.status = "Moved to Customer"
|
|
customer_model = self.env['sos_customers']
|
|
line_contacts_data = [(0, 0, {
|
|
'ref_id': self.id, # Replace with actual field names
|
|
'name': line.name,
|
|
'dept': line.dept,
|
|
'email': line.email,
|
|
'mobile_number': line.mobile_number,
|
|
'set_as_primary': line.set_as_primary,
|
|
}) for line in self.line_ids_contacts]
|
|
customer_record = customer_model.create({
|
|
'customer_name': self.company_name,
|
|
'customer_city':self.location,
|
|
'vertical_domain':self.vertical_domain.id,
|
|
'correspondence_address': self.correspondence_address,
|
|
'products':self.products,
|
|
'interested_in':self.interested_in,
|
|
'project_name':self.project_name,
|
|
'line_ids_contacts': line_contacts_data,
|
|
'leads_ref_no':self.id
|
|
|
|
})
|
|
return {
|
|
'type': 'ir.actions.client',
|
|
'tag': 'display_notification',
|
|
'params': {
|
|
'message': "Moved Successfully",
|
|
'type': 'success',
|
|
'sticky': False
|
|
}
|
|
}
|
|
class SOS_Leads_Lines(models.Model):
|
|
_name = 'sos_leads_customer_contact_lines'
|
|
_description = 'Leads Contact Lines'
|
|
|
|
ref_id = fields.Many2one('sos_sales_leads', string="Leads")
|
|
name = fields.Char(string="Name")
|
|
dept = fields.Char(string="Designation")
|
|
email = fields.Char(string="Email Id")
|
|
mobile_number = fields.Char(string="Contact Number")
|
|
set_as_primary = fields.Boolean(string="Set Primary")
|
|
@api.model
|
|
def create(self, vals):
|
|
record = super(SOS_Leads_Lines, self).create(vals)
|
|
if not self.env['sos_leads_customer_contact_lines'].search([
|
|
('ref_id', '=', record.ref_id.id),
|
|
('set_as_primary', '=', True)
|
|
]):
|
|
# Set the created record as primary
|
|
record.set_as_primary = True
|
|
return record
|
|
def write(self, vals):
|
|
res = super(SOS_Leads_Lines, self).write(vals)
|
|
if 'set_as_primary' in vals and vals['set_as_primary']:
|
|
for record in self:
|
|
self.env['sos_leads_customer_contact_lines'].search([
|
|
('ref_id', '=', record.ref_id.id),
|
|
('id', '!=', record.id)
|
|
]).write({'set_as_primary': False})
|
|
return res |