feat: Se modifica modularización sale_opportunity_management

This commit is contained in:
2024-01-31 12:25:54 -05:00
parent 4d88f9423d
commit aa35405a86
17 changed files with 17 additions and 17 deletions

View File

50
source/models/call.py Normal file
View File

@@ -0,0 +1,50 @@
# 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.model import ModelSQL, ModelView, fields
from datetime import date
from selections.interest import Interest
from selections.call_types import CallTypes
from selections.call_results import CallResults
class Call(ModelSQL, ModelView):
'Llamada'
__name__ = 'sale.call'
_order_name = 'date'
_states = {'readonly': True}
date = fields.Date('Date', states=_states)
description = fields.Text('Description', strip=True)
prospect_trace = fields.Many2One(
'sale.prospect_trace', 'Prospect trace', required=True, states=_states)
interest = fields.Selection(
Interest.get_interest_levels(), 'Interest', required=True)
call_type = fields.Selection(
CallTypes.get_call_types(), 'Call type', states=_states)
call_result = fields.Selection(
CallResults.get_call_results(),
'Call result', states=_states)
call_business_unit = fields.Selection(
[('brigade', 'Brigade'),
('optics', 'Optics'),
('equipment', 'Equipment')],
'Business unit', states=_states
)
operator_who_called = fields.Many2One(
'res.user', "Operator who called", states=_states)
@classmethod
def __setup__(cls):
super(Call, cls).__setup__()
cls._order = [
('date', 'DESC NULLS FIRST')
]
@classmethod
def default_date(cls):
return date.today()

View File

@@ -0,0 +1,37 @@
# 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.model import ModelSQL, ModelView, fields
class ContactMethod(ModelSQL, ModelView):
'Mecanismo de contacto'
__name__ = 'prospect.contact_method'
contact_type = fields.Selection([
('phone', 'Phone'),
('mobile', 'Mobile'),
('mail', 'Mail')
], 'Contact type', required=True)
value = fields.Char('Value', required=True)
name = fields.Char('Name')
job = fields.Char('Job')
prospect = fields.Many2One('sale.prospect', 'Prospect', required=True)
prospect_trace = fields.Many2One(
'sale.prospect_trace', 'Prospect Trace', required=False)
@classmethod
def default_contact_type(cls):
return 'mobile'
def get_rec_name(self, name):
fields = [self.name, self.job, self.value]
contact_rec_name = ''
for field in fields:
if field:
contact_rec_name += ' [' + str(field) + '] '
return contact_rec_name

View File

@@ -0,0 +1,15 @@
# 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.model import ModelSQL, ModelView, fields
class PendingCall(ModelSQL, ModelView):
'Llamada pendiente a un prospecto'
__name__ = "sale.pending_call"
date = fields.DateTime('Date', required=True)
def get_rec_name(self, name):
if self.date:
return str(self.date)

View File

@@ -0,0 +1,45 @@
# 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.model import ModelSQL, ModelView, fields
from trytond.pyson import Eval
class PendingTask(ModelSQL, ModelView):
'Tarea a realizar a un seguimiento de prospecto'
__name__ = "sale.pending_task"
description = fields.Text(
'Description', required=True,
states={
'readonly': Eval('state') == 'done'
})
state = fields.Selection(
[('pending', 'Pending'),
('done', 'Done')],
'State')
prospect_trace = fields.Many2One(
'sale.prospect_trace', 'Prospect trace',
required=True, readonly=True)
@classmethod
def __setup__(cls):
super(PendingTask, cls).__setup__()
cls._buttons.update({
'close_task': {
'invisible': Eval('state') == 'done'
}
})
@classmethod
@ModelView.button
def close_task(cls, tasks):
for task in tasks:
task.state = 'done'
task.save()
@classmethod
def default_state(cls):
return 'pending'

80
source/models/prospect.py Normal file
View File

@@ -0,0 +1,80 @@
# 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.model import ModelSQL, ModelView, fields, DeactivableMixin
from trytond.pyson import Eval, If
from trytond.transaction import Transaction
from trytond.pool import Pool
from source.wizards.assign_operator import GenericAssign
class Prospect(ModelSQL, ModelView, DeactivableMixin):
'Prospecto'
__name__ = 'sale.prospect'
_rec_name = 'name'
name = fields.Char('Name', required=True)
business_unit = fields.Selection(
[('brigade', 'Brigade'),
('optics', 'Optics'),
('equipment', 'Equipment')],
'Business unit', required=True
)
contact_methods = fields.One2Many(
'prospect.contact_method',
'prospect', 'Contact methods', required=True)
department = fields.Many2One('sale.department', 'Department')
city = fields.Many2One('sale.city', 'City',
domain=[If(Eval('department'),
('parent', '=', Eval('department')))])
assigned_operator = fields.Many2One(
'res.user', "Assigned operator", readonly=True)
state = fields.Selection([
('unassigned', 'Unsassigned'),
('assigned', 'Assigned')], "State", readonly=True)
prospect_trace = fields.Many2One('sale.prospect_trace', 'Prospect trace')
rating = fields.Selection(
[(None, None),
('1', '1'),
('2', '2'),
('3', '3'),
('4', '4'),
('5', '5')], 'Rating (1-5)')
comments = fields.Text('Comments')
@classmethod
def default_state(cls):
return 'unassigned'
@fields.depends('prospect_trace', 'contact_methods')
def on_change_contact_methods(self):
for contact in self.contact_methods:
contact.prospect_trace = self.prospect_trace
@fields.depends('city', 'department')
def on_change_city(self):
if self.city:
self.department = self.city.parent
@classmethod
def create(cls, values):
user_id = Transaction().user
records = super().create(values)
cls.try_assign_to_current_operator(records, 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

@@ -0,0 +1,106 @@
# 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.model import ModelSQL, ModelView, fields
from trytond.pyson import Eval
from selections.interest import Interest
class ProspectTrace(ModelSQL, ModelView):
'Seguimiento de un prospecto'
__name__ = 'sale.prospect_trace'
_states = {'readonly': True}
prospect = fields.Many2One(
'sale.prospect', 'Prospect', required=True, states=_states)
prospect_business_unit = fields.Selection(
[('brigade', 'Brigade'),
('optics', 'Optics'),
('equipment', 'Equipment')],
'Business unit', states=_states
)
prospect_contacts = fields.One2Many(
'prospect.contact_method', 'prospect_trace',
'Prospect contacts', required=True)
prospect_city = fields.Many2One('sale.city', 'City',
states=_states)
prospect_assigned_operator = fields.Many2One(
'res.user', "Assigned operator", states=_states)
calls = fields.One2Many(
'sale.call', 'prospect_trace', 'Calls', states=_states)
pending_call = fields.Many2One(
'sale.pending_call', 'Pending call', states=_states)
current_interest = fields.Selection(
Interest.get_interest_levels(), 'Current interest',
states=_states)
state = fields.Selection([
('unassigned', 'Unassigned'),
('open', 'Open'),
('with_pending_calls', 'With pending calls'),
('closed', 'Closed')
], 'State',
states=_states)
@fields.depends('prospect_contacts', 'prospect')
def on_change_prospect_contacts(self):
for contact in self.prospect_contacts:
contact.prospect = self.prospect
@classmethod
def __setup__(cls):
super(ProspectTrace, cls).__setup__()
cls._buttons.update({
'wizard_schedule': {
'invisible': Eval('state') == 'with_pending_calls',
},
'wizard_make_call': {},
'close_trace': {
'invisible': Eval('state') == 'closed',
'depends': ['state']
},
'reopen_trace': {
'invisible': (Eval('state') == 'open')
| (Eval('state') == 'with_pending_calls'),
'depends': ['state']
}
})
@classmethod
def default_state(cls):
return 'open'
@classmethod
@ModelView.button_action(
'sale_opportunity_management.schedule_call_wizard')
def wizard_schedule(cls, prospect_traces):
pass
@classmethod
@ModelView.button_action(
'sale_opportunity_management.make_call_wizard')
def wizard_make_call(cls, prospect_traces):
pass
@classmethod
@ModelView.button
def close_trace(cls, prospect_traces):
for prospect_trace in prospect_traces:
prospect_trace.state = 'closed'
prospect_trace.save()
@classmethod
@ModelView.button
def reopen_trace(cls, prospect_traces):
for prospect_trace in prospect_traces:
prospect_trace.state = 'open'
prospect_trace.save()
def get_rec_name(self, name):
if self.prospect:
return '[' + str(self.id) + '] ' + self.prospect.name

18
source/models/user.py Normal file
View File

@@ -0,0 +1,18 @@
# 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.model import fields
from trytond.pool import PoolMeta
class User(metaclass=PoolMeta):
"User"
__name__ = 'res.user'
user_admin = fields.Boolean('Is Admin')
is_operator = fields.Boolean('Is Operator')
@classmethod
def __setup__(cls):
super(User, cls).__setup__()
cls._context_fields.insert(0, 'user_admin')