Files
public/directive_test/models/directive_directive.py

27 lines
903 B
Python

from odoo import api, models
class Directive(models.Model):
_inherit = "directive.directive"
@api.model
def _cron_simulate_system_agents(self):
"""
Этот метод имитирует работу внешних систем (WMS, Банк, AI).
Запускается раз в минуту.
"""
system_directives = self.search([
('executor_type', 'in', ['software', 'machine']),
('stage_code', 'in', ['draft', 'planned', 'in_progress']),
('stage_code', '!=', 'done')
], limit=50)
for d in system_directives:
if d.stage_code == 'planned':
d._set_stage('in_progress')
print(f"Agent started directive {d.id}")
elif d.stage_code == 'in_progress':
d.action_done()
print(f"Agent finished directive {d.id}")