From d97277a0847bc57c0bc704c5ea62f75fadb461dc Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 5 May 2023 15:23:50 +0700 Subject: fix speed compute tag in leads --- indoteknik_custom/models/crm_lead.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py index b40bed6e..e7af4b1c 100755 --- a/indoteknik_custom/models/crm_lead.py +++ b/indoteknik_custom/models/crm_lead.py @@ -1,4 +1,7 @@ from odoo import fields, models, api +import logging + +_logger = logging.getLogger(__name__) class CrmLead(models.Model): @@ -54,16 +57,27 @@ class CrmLead(models.Model): # ('id', '=', 12523) ], limit=1000) for lead in leads: + _logger.info('processing tagged lead %s' % lead.id) input_tags = [] - if "Ada Quotation dari Website" in lead.name: - input_tags.append(1509) - lead.tag_ids = input_tags + if lead.order_id: + last_manufacture_id = 0 + for line in lead.order_id.order_line: + tag = self.env['crm.tag'].search([('name', 'ilike', line.product_id.product_tmpl_id.x_manufacture.x_name)], limit=1) + if tag and tag.id != last_manufacture_id: + last_manufacture_id = tag.id + input_tags.append(tag.id) + input_tags.append(1509) #Website hastag + lead.tag_ids = input_tags else: tags = self.env['crm.tag'].search([('id', '>', 0)]) 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 input_tags: + lead.tag_ids = input_tags + else: + input_tags.append(1510) #no tag + lead.tag_ids = input_tags if not lead.partner_id: continue -- cgit v1.2.3