diff --git a/jikimo_demand_plan_queue/__init__.py b/jikimo_demand_plan_queue/__init__.py new file mode 100644 index 00000000..a0fdc10f --- /dev/null +++ b/jikimo_demand_plan_queue/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import models diff --git a/jikimo_demand_plan_queue/__manifest__.py b/jikimo_demand_plan_queue/__manifest__.py new file mode 100644 index 00000000..aa970328 --- /dev/null +++ b/jikimo_demand_plan_queue/__manifest__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +{ + 'name': '机企猫 需求计划排程队列', + 'version': '1.0', + 'summary': """ 使用队列进行排程 """, + 'author': 'fox', + 'website': '', + 'category': '', + 'depends': ['queue_job', 'sf_demand_plan'], + 'data': [ + + ], + + 'application': True, + 'installable': True, + 'auto_install': False, + 'license': 'LGPL-3', +} diff --git a/jikimo_demand_plan_queue/models/__init__.py b/jikimo_demand_plan_queue/models/__init__.py new file mode 100644 index 00000000..54314ee3 --- /dev/null +++ b/jikimo_demand_plan_queue/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import production_demand_plan diff --git a/jikimo_demand_plan_queue/models/production_demand_plan.py b/jikimo_demand_plan_queue/models/production_demand_plan.py new file mode 100644 index 00000000..fd51e055 --- /dev/null +++ b/jikimo_demand_plan_queue/models/production_demand_plan.py @@ -0,0 +1,20 @@ +from odoo import models, fields + + +class ProductionDemandPlan(models.Model): + _inherit = 'sf.production.demand.plan' + + + def _do_production_schedule(self, pro_plan_list): + """使用队列进行排程""" + batch_size = 10 + current_time = fields.Datetime.now().strftime('%Y%m%d%H%M%S') + index = 1 + for i in range(0, len(pro_plan_list), batch_size): + batch = self.env['queue.job.batch'].get_new_batch('plan-%s-%s' % (current_time, index)) + pro_plans = pro_plan_list[i:i+batch_size] + pro_plans.with_context( + job_batch=batch + ).with_delay().do_production_schedule() + index += 1 + batch.enqueue() \ No newline at end of file diff --git a/sf_demand_plan/__manifest__.py b/sf_demand_plan/__manifest__.py index 2a543f1a..aab4ed99 100644 --- a/sf_demand_plan/__manifest__.py +++ b/sf_demand_plan/__manifest__.py @@ -10,7 +10,7 @@ """, 'category': 'sf', 'website': 'https://www.sf.jikimo.com', - 'depends': ['sf_plan', 'jikimo_printing'], + 'depends': ['sf_plan'], 'data': [ 'security/ir.model.access.csv', 'views/demand_plan.xml', diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index 79fcb99b..12214bff 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -323,8 +323,12 @@ class SfProductionDemandPlan(models.Model): date_planned_start = datetime.combine(date_part, time_part) pro_plan_list.production_line_id = sf_production_line.id pro_plan_list.date_planned_start = date_planned_start - for pro_plan in pro_plan_list: - pro_plan.do_production_schedule() + self._do_production_schedule(pro_plan_list) + + def _do_production_schedule(self, pro_plan_list): + for pro_plan in pro_plan_list: + pro_plan.do_production_schedule() + def button_action_print(self): return {