38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import logging
|
|
|
|
from odoo import api, models
|
|
from odoo.addons.directive_layer.models.directive_constants import (
|
|
STAGE_DRAFT,
|
|
STAGE_PLANNED,
|
|
STAGE_IN_PROGRESS,
|
|
STAGE_DONE,
|
|
)
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
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', [STAGE_DRAFT, STAGE_PLANNED, STAGE_IN_PROGRESS]),
|
|
('stage_code', '!=', STAGE_DONE)
|
|
], limit=50)
|
|
|
|
for d in system_directives:
|
|
|
|
if d.stage_code == STAGE_PLANNED:
|
|
d._set_stage(STAGE_IN_PROGRESS)
|
|
_logger.info("Agent started directive %s", d.id)
|
|
|
|
elif d.stage_code == STAGE_IN_PROGRESS:
|
|
d.action_done()
|
|
_logger.info("Agent finished directive %s", d.id)
|