feat(Asignación de prospectos): Auto-asignar prospectos al operador que lo creó

This commit is contained in:
2024-01-28 16:36:34 -05:00
parent 99de45dd32
commit b1c3b21a9c
4 changed files with 49 additions and 39 deletions

View File

@@ -3,6 +3,9 @@
from trytond.model import ModelSQL, ModelView, fields, DeactivableMixin
from trytond.pyson import Eval, If
from trytond.transaction import Transaction
from trytond.pool import Pool
from core.Prospect.wizards.assign_operator import GenericAssign
class Prospect(ModelSQL, ModelView, DeactivableMixin):
@@ -60,12 +63,20 @@ class Prospect(ModelSQL, ModelView, DeactivableMixin):
if self.city:
self.department = self.city.parent
# TODO assign to current user if is operator
# @classmethod
# def create(cls, values):
# records = super().create(values)
# Transaction.atexit(
# lambda: cls.try_assign_to_current_operator(records))
@classmethod
def create(cls, values):
user_id = Transaction().user
records = super().create(values)
# @classmethod
# def try_assign_to_current_operator(cls, prospect, user)
cls.try_assign_to_current_operator(records, user_id)
# Transaction().atexit(
# lambda: cls.try_assign_to_current_operator(prospects, user_id))
return records
@classmethod
def try_assign_to_current_operator(cls, prospects, user_id):
User = Pool().get('res.user')
user, = User.search([('id', '=', user_id)])
if user.is_operator:
GenericAssign.assign_prospects_to_operator(prospects, user)

View File

@@ -10,6 +10,7 @@ class User(metaclass=PoolMeta):
__name__ = 'res.user'
user_admin = fields.Boolean('Is Admin')
is_operator = fields.Boolean('Is Operator')
@classmethod
def __setup__(cls):