diff --git a/__init__.py b/__init__.py index 11c9839..ce849ac 100644 --- a/__init__.py +++ b/__init__.py @@ -19,8 +19,10 @@ def register(): prospect.Prospect, prospect_trace.ProspectTrace, prospect.AssignOperatorStart, + prospect_trace.ScheduleCallStart, module='sale_opportunity_management', type_='model') Pool.register( + prospect_trace.ScheduleCall, prospect.AssignOperator, module='sale_opportunity_management', type_='wizard') Pool.register( diff --git a/prospect_trace.py b/prospect_trace.py index 358700d..defb52d 100644 --- a/prospect_trace.py +++ b/prospect_trace.py @@ -1,5 +1,6 @@ # 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 ModelSQL, ModelView, fields, DeactivableMixin from trytond.pool import Pool @@ -58,11 +59,6 @@ class ProspectTrace(DeactivableMixin, ModelSQL, ModelView): self.pending_call = None self.state = 'open' - @fields.depends('pending_call', 'state') - def on_change_pending_call(self): - if self.pending_call: - self.state = 'with_pending_calls' - @fields.depends('prospect', 'prospect_city', 'prospect_contact') def on_change_prospect(self): if not self.prospect: @@ -95,3 +91,37 @@ class ProspectTrace(DeactivableMixin, ModelSQL, ModelView): if contact_mobile: return contact_mobile[0] + + +class ScheduleCallStart(ModelView): + 'Inicio agendar llamada a seguimiento de prospecto' + __name__ = 'sale.prospect_trace.schedule.start' + + date_time = fields.DateTime('Date time') + + +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): + pool = Pool() + PendingCall = pool.get('sale.pending_call') + pending_call = PendingCall() + pending_call.date = self.start.date_time + pending_call.save() + + prospect_trace = self.record + prospect_trace.pending_call = pending_call + prospect_trace.state = 'with_pending_calls' + prospect_trace.save() + + return 'end' diff --git a/prospect_trace.xml b/prospect_trace.xml index eb39d21..061a5cd 100644 --- a/prospect_trace.xml +++ b/prospect_trace.xml @@ -48,11 +48,18 @@ this repository contains the full copyright notices and license terms. --> - + + + + + sale.prospect_trace.schedule.start + form + schedule_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 7498bd7..23b005e 100644 --- a/tests/scenario_sale_opportunity_management.rst +++ b/tests/scenario_sale_opportunity_management.rst @@ -218,9 +218,15 @@ Verificar estado final del seguimiento del prospecto y sus llamadas Programar una próxima llamada pendiente al seguimiento de prospecto:: >>> PendingCall = Model.get('sale.pending_call') - >>> pending_call = PendingCall() - >>> pending_call.date = datetime(2023, 8, 14, 15, 30, 30) - >>> prospect_trace.pending_call = pending_call + + .. >>> pending_call = PendingCall() + + >>> schedule = Wizard('sale.prospect_trace.schedule', [prospect_trace]) + >>> schedule.form.date_time = datetime(2023, 8, 14, 15, 30, 30) + >>> schedule.execute('schedule') + + .. >>> pending_call.date = datetime(2023, 8, 14, 15, 30, 30) + .. >>> prospect_trace.pending_call = pending_call >>> prospect_trace.pending_call.date datetime.datetime(2023, 8, 14, 15, 30, 30) diff --git a/view/schedule_start_form.xml b/view/schedule_start_form.xml new file mode 100644 index 0000000..154334e --- /dev/null +++ b/view/schedule_start_form.xml @@ -0,0 +1,6 @@ + + +
+ +
\ No newline at end of file