feat: Se modifica modularización sale_opportunity_management
This commit is contained in:
0
source/wizards/__init__.py
Normal file
0
source/wizards/__init__.py
Normal file
108
source/wizards/assign_operator.py
Normal file
108
source/wizards/assign_operator.py
Normal file
@@ -0,0 +1,108 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
|
||||
from trytond.wizard import Wizard, StateView, Button, StateTransition
|
||||
from trytond.model import ModelView, fields
|
||||
from trytond.pyson import Eval
|
||||
from trytond.pool import Pool
|
||||
|
||||
from source.models.prospect_trace import ProspectTrace
|
||||
|
||||
|
||||
class AssignOperator(Wizard):
|
||||
'Asignar operador a prospecto'
|
||||
__name__ = 'sale.prospect.assign'
|
||||
|
||||
start = StateView(
|
||||
'sale.prospect.assign.start',
|
||||
'sale_opportunity_management.assign_start_view_form', [
|
||||
Button("Cancel", 'end', 'tryton-cancel'),
|
||||
Button("Assign", 'assign', 'tryton-ok', default=True)])
|
||||
|
||||
assign = StateTransition()
|
||||
|
||||
def transition_assign(self):
|
||||
_prospects = self.start.prospects
|
||||
_operator = self.start.operator
|
||||
|
||||
GenericAssign.assign_prospects_to_operator(_prospects, _operator)
|
||||
|
||||
return 'end'
|
||||
|
||||
|
||||
class AssignOperatorStart(ModelView):
|
||||
'Inicio de asignación de operador'
|
||||
__name__ = 'sale.prospect.assign.start'
|
||||
|
||||
prospects_chunk = fields.Integer(
|
||||
'Prospects chunk', required=True,
|
||||
states={
|
||||
'readonly': ~Eval('business_unit', False)})
|
||||
|
||||
operator = fields.Many2One('res.user', 'Operator', required=True)
|
||||
prospects = fields.One2Many(
|
||||
'sale.prospect', None, 'Prospects', readonly=True)
|
||||
|
||||
business_unit = fields.Selection(
|
||||
[('brigade', 'Brigade'),
|
||||
('optics', 'Optics'),
|
||||
('equipment', 'Equipment')],
|
||||
'Business unit',
|
||||
states={
|
||||
'readonly': Eval('prospects_chunk', False)}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def default_prospects_chunk(cls):
|
||||
return 0
|
||||
|
||||
@fields.depends('prospects_chunk', 'prospects', 'business_unit')
|
||||
def on_change_prospects_chunk(self):
|
||||
pool = Pool()
|
||||
Prospect = pool.get('sale.prospect')
|
||||
|
||||
if self.prospects_chunk >= 1:
|
||||
self.prospects = []
|
||||
self.prospects = Prospect.search(
|
||||
[('state', '=', 'unassigned'),
|
||||
('business_unit', '=', self.business_unit)],
|
||||
limit=self.prospects_chunk)
|
||||
|
||||
|
||||
class GenericAssign():
|
||||
@classmethod
|
||||
def assign_prospects_to_operator(cls, prospects, operator):
|
||||
for prospect in prospects:
|
||||
prospect.assigned_operator = operator
|
||||
prospect.state = 'assigned'
|
||||
prospect.prospect_trace = cls._get_prosp_trace(prospect, operator)
|
||||
prospect.save()
|
||||
|
||||
@classmethod
|
||||
def _get_prosp_trace(cls, prospect, operator):
|
||||
ProspectTrace = Pool().get('sale.prospect_trace')
|
||||
|
||||
prospect_trace = ProspectTrace.search([('prospect', '=', prospect)])
|
||||
|
||||
if not prospect_trace:
|
||||
created_trace = cls._create_base_prospect_trace(prospect, operator)
|
||||
prospect_trace.append(created_trace)
|
||||
|
||||
prospect_trace, = prospect_trace
|
||||
prospect_trace.prospect_assigned_operator = operator
|
||||
prospect_trace.save()
|
||||
return prospect_trace
|
||||
|
||||
@staticmethod
|
||||
def _create_base_prospect_trace(prospect, operator) -> ProspectTrace:
|
||||
ProspectTrace = Pool().get('sale.prospect_trace')
|
||||
|
||||
prospect_trace = ProspectTrace(
|
||||
prospect=prospect,
|
||||
prospect_city=prospect.city,
|
||||
prospect_business_unit=prospect.business_unit,
|
||||
prospect_contacts=prospect.contact_methods
|
||||
)
|
||||
|
||||
return prospect_trace
|
||||
147
source/wizards/make_call.py
Normal file
147
source/wizards/make_call.py
Normal file
@@ -0,0 +1,147 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.wizard import Wizard, StateView, Button, StateTransition
|
||||
from trytond.model import ModelView, fields
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval
|
||||
from selections.call_types import CallTypes
|
||||
from selections.interest import Interest
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class MakeCallStart(ModelView):
|
||||
'Inicio de creación de llamada a seguimiento de prospecto'
|
||||
__name__ = 'sale.prospect_trace.make_call.start'
|
||||
|
||||
description = fields.Text('Description')
|
||||
interest = fields.Selection(
|
||||
Interest.get_interest_levels(), 'Interest', required=True)
|
||||
schedule_call = fields.Selection(
|
||||
[('yes', 'Yes'),
|
||||
('no', 'No')], 'Schedule call?', required=True)
|
||||
|
||||
schedule_task = fields.Selection(
|
||||
[('yes', 'Yes'),
|
||||
('no', 'No')], 'Schedule task?', required=True)
|
||||
|
||||
|
||||
class MakeCallAsk(ModelView):
|
||||
'Posible agendación de llamada luego de hacer llamada actual'
|
||||
__name__ = 'sale.prospect_trace.make_call.ask'
|
||||
|
||||
currency_date = fields.DateTime('Currency Date', readonly=True)
|
||||
datetime = fields.DateTime('Date time', domain=[
|
||||
('datetime', '>=', Eval('currency_date'))])
|
||||
|
||||
@classmethod
|
||||
def default_currency_date(cls):
|
||||
date = datetime.now()
|
||||
|
||||
return date
|
||||
|
||||
|
||||
class MakeCallAskTask(ModelView):
|
||||
'Posible agendación de tarea luego de hacer llamada actual'
|
||||
__name__ = 'sale.prospect_trace.make_call.ask_task'
|
||||
|
||||
task_description = fields.Text('Task description')
|
||||
|
||||
|
||||
class MakeCall(Wizard):
|
||||
'Crear llamada a un seguimiento de prospecto'
|
||||
__name__ = 'sale.prospect_trace.make_call'
|
||||
|
||||
start = StateView(
|
||||
'sale.prospect_trace.make_call.start',
|
||||
'sale_opportunity_management.make_call_start_view_form', [
|
||||
Button("Cancel", 'end', 'tryton-cancel'),
|
||||
Button("Make call", 'make_call', 'tryton-ok', default=True)])
|
||||
make_call = StateTransition()
|
||||
|
||||
ask = StateView(
|
||||
'sale.prospect_trace.make_call.ask',
|
||||
'sale_opportunity_management.make_call_ask_view_form', [
|
||||
Button("Cancel", 'end', 'tryton-cancel'),
|
||||
Button(
|
||||
"Schedule call", 'schedule_call', 'tryton-ok', default=True)])
|
||||
schedule_call = StateTransition()
|
||||
|
||||
ask_task = StateView(
|
||||
'sale.prospect_trace.make_call.ask_task',
|
||||
'sale_opportunity_management.make_call_ask_task_view_form', [
|
||||
Button("Cancel", 'end', 'tryton-cancel'),
|
||||
Button("Schedule task", 'schedule_task', 'tryton-ok', default=True)
|
||||
]
|
||||
)
|
||||
schedule_task = StateTransition()
|
||||
|
||||
def transition_make_call(self):
|
||||
prospect_trace = self.record
|
||||
|
||||
pool = Pool()
|
||||
Call = pool.get('sale.call')
|
||||
call = Call()
|
||||
call.description = self.start.description
|
||||
call.interest = self.start.interest
|
||||
call.prospect_trace = self.record
|
||||
call.call_business_unit = self.record.prospect_business_unit
|
||||
call.operator_who_called = self.record.prospect_assigned_operator
|
||||
|
||||
if call.interest == '0':
|
||||
call.call_result = 'missed_call'
|
||||
else:
|
||||
call.call_result = 'answered_call'
|
||||
already_exist_a_call = len(prospect_trace.calls) >= 1
|
||||
if already_exist_a_call:
|
||||
followup_call_type = CallTypes.get_call_types()[1][0]
|
||||
call.call_type = followup_call_type
|
||||
else:
|
||||
first_call_type = CallTypes.get_call_types()[0][0]
|
||||
call.call_type = first_call_type
|
||||
call.save()
|
||||
|
||||
prospect_trace.current_interest = call.interest
|
||||
if prospect_trace.pending_call:
|
||||
prospect_trace.pending_call = None
|
||||
prospect_trace.state = 'open'
|
||||
prospect_trace.calls += (call,)
|
||||
prospect_trace.save()
|
||||
|
||||
if self.start.schedule_call == 'yes':
|
||||
return 'ask'
|
||||
if self.start.schedule_task == 'yes':
|
||||
return 'ask_task'
|
||||
return 'end'
|
||||
|
||||
def transition_schedule_task(self):
|
||||
self.create_schedule_task(self.ask_task.task_description, self.record)
|
||||
return 'end'
|
||||
|
||||
def transition_schedule_call(self):
|
||||
self.create_schedule_call(self.ask.datetime, self.record)
|
||||
|
||||
if (self.start.schedule_call and self.start.schedule_task) == 'yes':
|
||||
return 'ask_task'
|
||||
return 'end'
|
||||
|
||||
@classmethod
|
||||
def create_schedule_task(cls, description, prospect_trace):
|
||||
pool = Pool()
|
||||
Task = pool.get('sale.pending_task')
|
||||
task = Task()
|
||||
task.description = description
|
||||
task.prospect_trace = prospect_trace
|
||||
task.save()
|
||||
|
||||
@classmethod
|
||||
def create_schedule_call(cls, datetime, prospect_trace):
|
||||
pool = Pool()
|
||||
PendingCall = pool.get('sale.pending_call')
|
||||
pending_call = PendingCall()
|
||||
pending_call.date = datetime
|
||||
pending_call.save()
|
||||
|
||||
prospect_trace.pending_call = pending_call
|
||||
prospect_trace.state = 'with_pending_calls'
|
||||
prospect_trace.save()
|
||||
53
source/wizards/reassign_prospect_by_operator.py
Normal file
53
source/wizards/reassign_prospect_by_operator.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
|
||||
from trytond.wizard import Wizard, StateView, Button, StateTransition
|
||||
from trytond.model import ModelView, fields
|
||||
from trytond.pool import Pool
|
||||
|
||||
from source.wizards.assign_operator import GenericAssign
|
||||
|
||||
|
||||
class ReassignProspectByOperatorStart(ModelView):
|
||||
'Inicio de reasignación de prospecto por operario'
|
||||
__name__ = 'sale.prospect.reassign_by_operator.start'
|
||||
|
||||
current_operator = fields.Many2One(
|
||||
'res.user', "Current operator", required=True)
|
||||
new_operator = fields.Many2One(
|
||||
'res.user', "New operator", required=True)
|
||||
prospects = fields.One2Many(
|
||||
'sale.prospect', None, 'Prospects', readonly=True)
|
||||
|
||||
@fields.depends('current_operator', 'prospects')
|
||||
def on_change_current_operator(self):
|
||||
pool = Pool()
|
||||
Prospect = pool.get('sale.prospect')
|
||||
|
||||
self.prospects = []
|
||||
self.prospects = Prospect.search(
|
||||
[('state', '=', 'assigned'),
|
||||
('assigned_operator', '=', self.current_operator)])
|
||||
|
||||
|
||||
class ReassignProspectByOperator(Wizard):
|
||||
'Reasignar todos los prospectos de un operario, a otro operario'
|
||||
__name__ = 'sale.prospect.reassign_by_operator'
|
||||
|
||||
start = StateView(
|
||||
'sale.prospect.reassign_by_operator.start',
|
||||
'sale_opportunity_management.reassign_by_operator_start_view_form',
|
||||
[Button("Cancel", 'end', 'tryton-cancel'),
|
||||
Button("Reassign", 'reassign_by_operator', 'tryton-ok', default=True)
|
||||
])
|
||||
|
||||
reassign_by_operator = StateTransition()
|
||||
|
||||
def transition_reassign_by_operator(self):
|
||||
_prospects = self.start.prospects
|
||||
_operator = self.start.new_operator
|
||||
|
||||
GenericAssign.assign_prospects_to_operator(_prospects, _operator)
|
||||
|
||||
return 'end'
|
||||
40
source/wizards/reassign_prospect_by_prospect.py
Normal file
40
source/wizards/reassign_prospect_by_prospect.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.wizard import Wizard, StateView, Button, StateTransition
|
||||
from trytond.model import ModelView, fields
|
||||
|
||||
from source.wizards.assign_operator import GenericAssign
|
||||
|
||||
|
||||
class ReassignProspectByProspectStart(ModelView):
|
||||
'Inicio de reasignación de un prospecto en específico'
|
||||
__name__ = 'sale.prospect.reassign_by_prospect.start'
|
||||
|
||||
prospect = fields.Many2One(
|
||||
'sale.prospect', 'Prospect', required=True,
|
||||
domain=[('assigned_operator', '!=', None)])
|
||||
|
||||
new_operator = fields.Many2One('res.user', "New operator", required=True)
|
||||
|
||||
|
||||
class ReasignProspectByProspect(Wizard):
|
||||
'Reasignar un prospecto en específico a un nuevo operario'
|
||||
__name__ = 'sale.prospect.reassign_by_prospect'
|
||||
|
||||
start = StateView(
|
||||
'sale.prospect.reassign_by_prospect.start',
|
||||
'sale_opportunity_management.reassign_by_prospect_start_view_form',
|
||||
[Button("Cancel", 'end', 'tryton-cancel'),
|
||||
Button("Reassign", 'reassign_by_prospect', 'tryton-ok', default=True)
|
||||
])
|
||||
|
||||
reassign_by_prospect = StateTransition()
|
||||
|
||||
def transition_reassign_by_prospect(self):
|
||||
_prospect = self.start.prospect
|
||||
_operator = self.start.new_operator
|
||||
|
||||
GenericAssign.assign_prospects_to_operator([_prospect], _operator)
|
||||
|
||||
return 'end'
|
||||
40
source/wizards/schedule_call.py
Normal file
40
source/wizards/schedule_call.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.wizard import Wizard, StateView, Button, StateTransition
|
||||
from trytond.model import ModelView, fields
|
||||
from trytond.pyson import Eval
|
||||
from datetime import datetime
|
||||
from source.wizards.make_call import MakeCall
|
||||
|
||||
|
||||
class ScheduleCallStart(ModelView):
|
||||
'Inicio agendar llamada a seguimiento de prospecto'
|
||||
__name__ = 'sale.prospect_trace.schedule.start'
|
||||
|
||||
currency_date = fields.DateTime('Currency Date', readonly=True)
|
||||
date_time = fields.DateTime('Date time', domain=[
|
||||
('date_time', '>=', Eval('currency_date'))])
|
||||
|
||||
@classmethod
|
||||
def default_currency_date(cls):
|
||||
date = datetime.now()
|
||||
|
||||
return date
|
||||
|
||||
|
||||
class ScheduleCall(Wizard):
|
||||
'Agendar llamada a seguimiento de prospecto'
|
||||
__name__ = 'sale.prospect_trace.schedule'
|
||||
|
||||
start = StateView(
|
||||
'sale.prospect_trace.schedule.start',
|
||||
'sale_opportunity_management.schedule_start_view_form', [
|
||||
Button("Cancel", 'end', 'tryton-cancel'),
|
||||
Button("Schedule", 'schedule', 'tryton-ok', default=True)])
|
||||
|
||||
schedule = StateTransition()
|
||||
|
||||
def transition_schedule(self):
|
||||
MakeCall.create_schedule_call(self.start.date_time, self.record)
|
||||
return 'end'
|
||||
Reference in New Issue
Block a user