Skip to content

Commit

Permalink
Merge pull request #289 from ursais/12-imp-github-bugs
Browse files Browse the repository at this point in the history
[FIX] FSM Improvements (Bugs: #265, #272, #263, #277, #266)
  • Loading branch information
max3903 authored Aug 6, 2019
2 parents 77d1659 + ee1af27 commit 2c1452f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
13 changes: 1 addition & 12 deletions fieldservice/models/fsm_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions fieldservice/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 19 additions & 3 deletions fieldservice/models/fsm_person.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = \
Expand Down
5 changes: 2 additions & 3 deletions fieldservice_account/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ def _compute_employee(self):
def _compute_total_cost(self):
for order in self:
order.total_cost = 0.0
rate = 0
for line in order.employee_timesheet_ids:
for emp in line.user_id.employee_ids:
rate = emp.timesheet_cost
continue
rate = line.employee_id.timesheet_cost
order.total_cost += line.unit_amount * rate
for cost in order.contractor_cost_ids:
order.total_cost += cost.price_unit * cost.quantity
Expand Down
4 changes: 2 additions & 2 deletions fieldservice_purchase/models/fsm_person.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class FSMPerson(models.Model):
def _compute_pricelist_count(self):
for worker in self:
worker.pricelist_count = self.env['product.supplierinfo'].\
search_count([('id', '=', worker.id)])
search_count([('name', '=', worker.partner_id.id)])

@api.multi
def action_view_pricelists(self):
for worker in self:
pricelist = self.env['product.supplierinfo'].search(
[('id', '=', worker.id)])
[('name', '=', worker.partner_id.id)])
action = self.env.ref(
'product.product_supplierinfo_type_action').read()[0]
if len(pricelist) == 1:
Expand Down

0 comments on commit 2c1452f

Please sign in to comment.