From 65436a03d40cd31e0111727fe6c84380eba005d5 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 15 Oct 2024 15:34:36 +0700 Subject: update pipeline --- indoteknik_custom/models/crm_lead.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py index eac75cb0..de2bdb12 100755 --- a/indoteknik_custom/models/crm_lead.py +++ b/indoteknik_custom/models/crm_lead.py @@ -98,6 +98,26 @@ class CrmLead(models.Model): lead.user_id = salesperson_id + def _update_pipeline(self, delta=48, limit=100): + # Get the current time + current_time = datetime.now() + + # Calculate the time 24 hours ago + time_48_hours_ago = current_time - timedelta(hours=delta) + + # Define the allowed states + allowed_states = ['sale', 'done'] + + # Search for sale orders with date_order greater than 24 hours ago and opportunity_id is null + orders = self.env['sale.order'].search([ + ('write_date', '>=', time_48_hours_ago), + ('opportunity_id', '!=', False), + ('state', 'in', allowed_states) + ], limit=limit) + for order in orders: + order.opportunity_id.stage_id = 4 + _logger.info('finish order stage pipeline %s' % order.id) + def _cancel_pipeline(self, delta=48, limit=100): # Get the current time current_time = datetime.now() -- cgit v1.2.3