diff --git a/__init__.py b/__init__.py index ce849ac..211e110 100644 --- a/__init__.py +++ b/__init__.py @@ -20,10 +20,12 @@ def register(): prospect_trace.ProspectTrace, prospect.AssignOperatorStart, prospect_trace.ScheduleCallStart, + prospect_trace.MakeCallStart, module='sale_opportunity_management', type_='model') Pool.register( prospect_trace.ScheduleCall, prospect.AssignOperator, + prospect_trace.MakeCall, module='sale_opportunity_management', type_='wizard') Pool.register( module='sale_opportunity_management', type_='report') diff --git a/call.py b/call.py index 73955a0..5b3098b 100644 --- a/call.py +++ b/call.py @@ -30,11 +30,3 @@ class Call(ModelSQL, ModelView): @classmethod def default_date(cls): return date.today() - - @fields.depends('interest', 'call_result') - def on_change_interest(self): - if self.interest: - if self.interest == '0': - self.call_result = 'missed_call' - else: - self.call_result = 'answered_call' diff --git a/prospect_trace.py b/prospect_trace.py index d1a4c27..1db0c52 100644 --- a/prospect_trace.py +++ b/prospect_trace.py @@ -56,26 +56,6 @@ class ProspectTrace(DeactivableMixin, ModelSQL, ModelView): def wizard_schedule(cls, prospect_traces): pass - @fields.depends('calls', 'pending_call', 'current_interest', 'state') - def on_change_calls(self): - if not self.calls: - return - - last_call = self.calls[-1] - self.current_interest = last_call.interest - - already_exist_a_call = len(self.calls) > 1 - if already_exist_a_call: - followup_call_type = CallTypes.get_call_types()[1][0] - last_call.call_type = followup_call_type - else: - first_call_type = CallTypes.get_call_types()[0][0] - last_call.call_type = first_call_type - - if self.pending_call: - self.pending_call = None - self.state = 'open' - @fields.depends('prospect', 'prospect_city', 'prospect_contact') def on_change_prospect(self): if not self.prospect: @@ -142,3 +122,57 @@ class ScheduleCall(Wizard): prospect_trace.save() return 'end' + + +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) + + +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() + + 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 + + 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() + + return 'end' diff --git a/prospect_trace.xml b/prospect_trace.xml index b711283..95a194f 100644 --- a/prospect_trace.xml +++ b/prospect_trace.xml @@ -68,5 +68,16 @@ this repository contains the full copyright notices and license terms. --> Schedule call + + + Make call + sale.prospect_trace.make_call + + + sale.prospect_trace.make_call.start + form + make_call_start_form + + \ No newline at end of file diff --git a/tests/scenario_sale_opportunity_management.rst b/tests/scenario_sale_opportunity_management.rst index 4cb1b62..1f78819 100644 --- a/tests/scenario_sale_opportunity_management.rst +++ b/tests/scenario_sale_opportunity_management.rst @@ -185,10 +185,22 @@ Crear seguimiento de prospecto:: 'Gerente R.H' Crear llamadas a un seguimiento de prospecto desde el seguimiento de prospecto:: - >>> call1 = prospect_trace.calls.new(description='First call', interest='0') - >>> call2 = prospect_trace.calls.new(description='Second call', interest='1') - >>> call3 = prospect_trace.calls.new(description='Third call', interest='3') - >>> prospect_trace.save() + >>> make_call = Wizard('sale.prospect_trace.make_call', [prospect_trace]) + >>> make_call.form.description = 'First call to the prospect' + >>> make_call.form.interest = '0' + >>> make_call.execute('make_call') + + >>> make_call = Wizard('sale.prospect_trace.make_call', [prospect_trace]) + >>> make_call.form.description = 'Second call to the prospect' + >>> make_call.form.interest = '1' + >>> make_call.execute('make_call') + + >>> make_call = Wizard('sale.prospect_trace.make_call', [prospect_trace]) + >>> make_call.form.description = 'Third call to the prospect' + >>> make_call.form.interest = '3' + >>> make_call.execute('make_call') + + .. >>> prospect_trace.save() Verificar estado final del seguimiento del prospecto y sus llamadas >>> prospect_trace.calls[0].call_result @@ -223,7 +235,10 @@ Programar una próxima llamada pendiente al seguimiento de prospecto:: 'with_pending_calls' Crear una llamada agendada previamente: - >>> call4 = prospect_trace.calls.new(description='fourth call', interest='3') + >>> make_call = Wizard('sale.prospect_trace.make_call', [prospect_trace]) + >>> make_call.form.description = 'Fourth call to the prospect' + >>> make_call.form.interest = '3' + >>> make_call.execute('make_call') >>> prospect_trace.pending_call diff --git a/view/make_call_start_form.xml b/view/make_call_start_form.xml new file mode 100644 index 0000000..f70e785 --- /dev/null +++ b/view/make_call_start_form.xml @@ -0,0 +1,6 @@ + + +
+ +
\ No newline at end of file