From 6ecb0da346571804a5f0c4a588e4a0f39a6e9c5c Mon Sep 17 00:00:00 2001
From: camilogs <camilo.gonzalez.col@gmail.com>
Date: Sun, 6 Aug 2023 14:27:52 -0500
Subject: [PATCH] =?UTF-8?q?feat:=20Se=20agrega=20dominio=20de=20ciudad=20y?=
 =?UTF-8?q?=20departamento=20en=20creaci=C3=B3n=20de=20prospecto?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 call.py                                        |  2 +-
 prospect.py                                    | 10 +++++++++-
 tests/scenario_sale_opportunity_management.rst | 10 ++++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/call.py b/call.py
index c7d4f8e..59234f3 100644
--- a/call.py
+++ b/call.py
@@ -26,7 +26,7 @@ class Call(ModelSQL, ModelView):
     def default_date(cls):
         return date.today()
 
-    @fields.depends('interest')
+    @fields.depends('interest', 'call_result')
     def on_change_interest(self):
         if self.interest:
             if self.interest == '0':
diff --git a/prospect.py b/prospect.py
index a3e5615..04d3146 100644
--- a/prospect.py
+++ b/prospect.py
@@ -1,6 +1,7 @@
 # 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, If
 
 
 class Prospect(ModelSQL, ModelView):
@@ -13,7 +14,14 @@ class Prospect(ModelSQL, ModelView):
         'prospect.contact_method', 'prospect', 'Contact methods')
 
     department = fields.Many2One('sale.department', 'Department')
-    city = fields.Many2One('sale.city', 'City')
+    city = fields.Many2One('sale.city', 'City',
+                           domain=[If(Eval('department'),
+                                    ('parent', '=', Eval('department')))])
+
+    @fields.depends('city', 'department')
+    def on_change_city(self):
+        if self.city:
+            self.department = self.city.parent
 
 
 class ContactMethod(ModelSQL, ModelView):
diff --git a/tests/scenario_sale_opportunity_management.rst b/tests/scenario_sale_opportunity_management.rst
index cfa449b..cd0a8d2 100644
--- a/tests/scenario_sale_opportunity_management.rst
+++ b/tests/scenario_sale_opportunity_management.rst
@@ -47,6 +47,11 @@ Crear prospecto::
     >>> prospect.name = 'guchito S.A.S'
     >>> contact_method = prospect.contact_methods.new(contact_type = 'mobile', value = '31223425234') 
     >>> contact_method = prospect.contact_methods.new(contact_type = 'mail', value = 'peralto@guchitos.org') 
+
+    .. >>> Department = Model.get('sale.department')
+    .. >>> cundinamarca, = Department.find([('code', '=', 'CO-25')])
+    .. >>> prospect.department = cundinamarca
+
     >>> City = Model.get('sale.city')
     >>> medellin, = City.find([('code', '=', 'CO-05001')])
     >>> prospect.city = medellin
@@ -57,6 +62,11 @@ Verificar estado final de creación de prospecto::
     [proteus.Model.get('prospect.contact_method')(1), proteus.Model.get('prospect.contact_method')(2)]
     >>> prospect.city.parent.code
     'CO-05'
+    >>> prospect.department.code
+    'CO-05'
+
+
+
 
 ------------------------------------
 Asignación de prospectos a operarios