1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
from odoo import fields, models, api
class CrmLead(models.Model):
_inherit = "crm.lead"
html_description = fields.Html(string="Descriptions")
file_npwp = fields.Binary(string="Nomor Pokok Wajib Pajak")
file_nib = fields.Binary(string="Nomor Induk Berusaha")
file_tdp = fields.Binary(string="Tanda Daftar Perusahaan")
file_siup = fields.Binary(string="Surat Izin Usaha Perdagangan")
file_quotation = fields.Binary(string='Dokumen Quotation')
body_html_lead = fields.Text('Body HTML', compute='compute_body_leads')
# for wati only
wati_notification_id = fields.One2many('wati.notification', 'lead_id', string='Wati Notification')
ticket_id = fields.Char('Ticket ID', help='Ticket ID yang ada di WATI')
operator_email = fields.Char('Operator Email', help='Operator yang membalas')
operator_name = fields.Char('Operator Name', help='Operator yang membalas')
order_id = fields.Many2one('sale.order', string='Sales Order', help='Link ke sales order id')
def revert_to_leads(self):
opportunities = self.env['crm.lead'].search([
('type', '=', 'opportunity'),
('active', '=', True),
('user_id', '=', False),
])
for opportunity in opportunities:
opportunity.type = 'lead'
@api.onchange('stage_id')
def update_stars(self):
for lead in self:
lead.priority = 0
def compute_body_leads(self):
for lead in self:
mail_message = self.env['mail.message'].search([
('res_id', '=', lead.id),
('model', '=', 'crm.lead'),
('message_type', '=', 'email')
], limit=1)
lead.body_html_lead = mail_message.body or ''
def _update_tags_leads(self):
leads = self.env['crm.lead'].search([
('active', '=', True),
('type', '=', 'lead'),
('tag_ids', '=', False),
], limit=1000)
for lead in leads:
tags = self.env['crm.tag'].search([('id', '>', 0)])
input_tags = []
for tag in tags:
if tag.name.lower() in lead.body_html_lead.lower():
input_tags.append(tag.id)
lead.tag_ids = input_tags
if not lead.partner_id:
continue
if not lead.user_id or lead.user_id == 2:
if lead.partner_id.parent_id:
salesperson_id = lead.partner_id.parent_id.user_id
else:
salesperson_id = lead.partner_id.user_id
lead.user_id = salesperson_id
|