Skip to content

Commit

Permalink
Merge pull request #124 from oihane/8.0-unreserve
Browse files Browse the repository at this point in the history
[FIX] mrp_production_unreserve_movements: if not workorder linked doe…
  • Loading branch information
oihane committed Feb 19, 2016
2 parents 40ca247 + bae9cde commit da3ca84
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions mrp_production_unreserve_movements/models/mrp_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,22 @@
class MrpProduction(models.Model):
_inherit = 'mrp.production'

@api.one
@api.depends('state', 'move_lines.state')
def _show_buttons(self):
self.show_check_availability = False
self.show_force_reservation = False
if self.state not in ('draft', 'cancel', 'done'):
moves = self.move_lines.filtered(
for mo in self.filtered(lambda x: x.state not in
('draft', 'cancel', 'done')):
moves = mo.move_lines.filtered(
lambda x: x.state in ('waiting', 'confirmed') and
x.work_order.state not in ('cancel', 'done'))
if moves:
self.show_check_availability = True
self.show_force_reservation = True
mo.show_check_availability = moves
mo.show_force_reservation = moves

@api.one
@api.depends('move_lines.state')
def _show_unreserve(self):
self.show_unreserve = False
moves = self.move_lines.filtered(
lambda x: x.state == 'assigned' and
x.work_order.state not in ('cancel', 'done'))
if moves:
self.show_unreserve = True
for mo in self:
mo.show_unreserve = mo.move_lines.filtered(
lambda x: x.state == 'assigned' and
x.work_order.state not in ('cancel', 'done'))

show_check_availability = fields.Boolean(
string='Show check availability button', compute='_show_buttons')
Expand All @@ -40,8 +34,9 @@ def _show_unreserve(self):

@api.multi
def button_unreserve(self):
moves = self.move_lines.filtered(lambda x: x.state == 'assigned' and
x.work_order.state == 'draft')
moves = self.move_lines.filtered(
lambda x: x.state == 'assigned' and (
not x.work_order or x.work_order.state == 'draft'))
return moves.do_unreserve()


Expand Down

0 comments on commit da3ca84

Please sign in to comment.