From 16ceaca2a756f2893f110dad49f6e4375b9d6877 Mon Sep 17 00:00:00 2001 From: scampbell Date: Wed, 17 Jul 2019 16:53:55 -0700 Subject: [PATCH] [IMP] Bug #266 False ETA Error [IMP] Bug #265 Linked Location Search Error [IMP] Bug #272 Rate Not Declared [IMP] Bug #263 equipment_count Wrong [IMP] Bug #277 Worker Pricelists Computed Wrong [IMP] Flake8 + Remove Debug --- fieldservice/models/fsm_location.py | 13 +------------ fieldservice/models/fsm_order.py | 9 +++++---- fieldservice/models/fsm_person.py | 22 +++++++++++++++++++--- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/fieldservice/models/fsm_location.py b/fieldservice/models/fsm_location.py index 98a3a188e9..2de6b8a8a0 100644 --- a/fieldservice/models/fsm_location.py +++ b/fieldservice/models/fsm_location.py @@ -190,8 +190,7 @@ def comp_count(self, contact, equipment, loc): child_locs = self.env['fsm.location'].\ search([('fsm_parent_id', '=', child.id)]) equip = self.env['fsm.equipment'].\ - search_count([('location_id', - '=', child.id)]) + search_count([('location_id', '=', child.id)]) if child_locs: for loc in child_locs: equip += loc.comp_count(0, 1, loc) @@ -336,16 +335,6 @@ def _compute_equipment_ids(self): for loc in self: equipment = self.comp_count(0, 1, loc) loc.equipment_count = equipment - for location in self: - child_locs = self.env['fsm.location']. \ - search([('fsm_parent_id', '=', location.id)]) - equipment = (self.env['fsm.equipment']. - search_count([('location_id', - 'in', child_locs.ids)]) + - self.env['fsm.equipment']. - search_count([('location_id', - '=', location.id)])) - location.equipment_count = equipment or 0 @api.constrains('fsm_parent_id') def _check_location_recursion(self): diff --git a/fieldservice/models/fsm_order.py b/fieldservice/models/fsm_order.py index 1dc77c8212..f7dd81b715 100644 --- a/fieldservice/models/fsm_order.py +++ b/fieldservice/models/fsm_order.py @@ -205,10 +205,11 @@ def write(self, vals): + timedelta(hours=vals.get('scheduled_duration')) vals['scheduled_date_end'] = str(date_to_with_delta) if 'scheduled_date_end' not in vals and 'scheduled_date_start' in vals: - date_to_with_delta = fields.Datetime.from_string( - vals.get('scheduled_date_start')) + \ - timedelta(hours=self.scheduled_duration) - vals['scheduled_date_end'] = str(date_to_with_delta) + if vals['scheduled_date_start']: + date_to_with_delta = fields.Datetime.from_string( + vals.get('scheduled_date_start')) + \ + timedelta(hours=self.scheduled_duration) + vals['scheduled_date_end'] = str(date_to_with_delta) res = super(FSMOrder, self).write(vals) for order in self: if 'customer_id' not in vals and order.customer_id is False: diff --git a/fieldservice/models/fsm_person.py b/fieldservice/models/fsm_person.py index 19b26ff129..dd6c327f97 100644 --- a/fieldservice/models/fsm_person.py +++ b/fieldservice/models/fsm_person.py @@ -34,9 +34,25 @@ def _search(self, args, offset=0, limit=None, order=None, count=False, for arg in args: if isinstance(arg, (list)): if arg[0] == 'location_ids': - self.env.cr.execute("SELECT person_id " - "FROM fsm_location_person " - "WHERE location_id=%s", (arg[2],)) + # If given int search ID, else search name + if isinstance(arg[2], int): + self.env.cr.execute("SELECT person_id " + "FROM fsm_location_person " + "WHERE location_id=%s", (arg[2],)) + else: + arg[2] = '%' + arg[2] + '%' + self.env.cr.execute("SELECT id " + "FROM fsm_location " + "WHERE complete_name like %s", + (arg[2],)) + location_ids = self.env.cr.fetchall() + if location_ids: + location_ids = \ + [location[0] for location in location_ids] + self.env.cr.execute("SELECT DISTINCT person_id " + "FROM fsm_location_person " + "WHERE location_id in %s", + [tuple(location_ids)]) workers_ids = self.env.cr.fetchall() if workers_ids: preferred_workers_list = \