Skip to content

Commit

Permalink
Merge pull request #175 from Tecnativa/8.0-project_task_materials_sto…
Browse files Browse the repository at this point in the history
…ck-Singleton

[8.0][FIX] project_task_materials_stock: Singleton unlink tasks
  • Loading branch information
pedrobaeza committed May 19, 2016
2 parents 72c07c9 + 671e43e commit 2d9b63e
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions project_task_materials_stock/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,32 @@ class ProjectTaskType(models.Model):
class Task(models.Model):
_inherit = "project.task"

@api.multi
@api.depends('material_ids.stock_move_id')
def _compute_stock_move(self):
self.stock_move_ids = self.mapped('material_ids.stock_move_id')
for task in self:
task.stock_move_ids = task.mapped('material_ids.stock_move_id')

@api.multi
@api.depends('material_ids.analytic_line_id')
def _compute_analytic_line(self):
self.analytic_line_ids = self.mapped('material_ids.analytic_line_id')
for task in self:
task.analytic_line_ids = task.mapped(
'material_ids.analytic_line_id')

@api.multi
@api.depends('stock_move_ids.state')
def _check_stock_state(self):
if not self.stock_move_ids:
self.stock_state = 'pending'
elif self.stock_move_ids.filtered(lambda r: r.state == 'confirmed'):
self.stock_state = 'confirmed'
elif self.stock_move_ids.filtered(lambda r: r.state == 'assigned'):
self.stock_state = 'assigned'
elif self.stock_move_ids.filtered(lambda r: r.state == 'done'):
self.stock_state = 'done'
def _compute_stock_state(self):
for task in self:
if not task.stock_move_ids:
task.stock_state = 'pending'
elif task.stock_move_ids.filtered(
lambda r: r.state == 'confirmed'):
task.stock_state = 'confirmed'
elif task.stock_move_ids.filtered(lambda r: r.state == 'assigned'):
task.stock_state = 'assigned'
elif task.stock_move_ids.filtered(lambda r: r.state == 'done'):
task.stock_state = 'done'

stock_move_ids = fields.Many2many(
comodel_name='stock.move', compute='_compute_stock_move',
Expand All @@ -47,7 +56,8 @@ def _check_stock_state(self):
[('pending', 'Pending'),
('confirmed', 'Confirmed'),
('assigned', 'Assigned'),
('done', 'Done')], compute='_check_stock_state', string='Stock State')
('done', 'Done')],
compute='_compute_stock_state', string='Stock State')

@api.multi
def unlink_stock_move(self):
Expand Down Expand Up @@ -79,7 +89,7 @@ def write(self, vals):
@api.multi
def unlink(self):
self.mapped('stock_move_ids').unlink()
self.analytic_line_ids.unlink()
self.mapped('analytic_line_ids').unlink()
return super(Task, self).unlink()

@api.multi
Expand Down

0 comments on commit 2d9b63e

Please sign in to comment.