<commit_before># -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################
from openerp import models, fields, api


class MrpProduction(models.Model):
    _inherit = 'mrp.production'

    @api.depends('state', 'move_lines.state')
    def _show_buttons(self):
        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'))
            mo.show_check_availability = moves
            mo.show_force_reservation = moves

    @api.depends('move_lines.state')
    def _show_unreserve(self):
        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')
    show_force_reservation = fields.Boolean(
        string='Show force reservation button', compute='_show_buttons')
    show_unreserve = fields.Boolean(
        string='Show unreserve button', compute='_show_unreserve')

    @api.multi
    def button_unreserve(self):
        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()

    @api.multi
    def check_unreserved_moves(self):
        self.ensure_one()
        moves = self.move_lines.filtered(
            lambda x: x.state in ('assigned', 'done'))
        if moves:
            return False
        return True


class MrpProductionWorkcenterLine(models.Model):
    _inherit = 'mrp.production.workcenter.line'

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

    @api.one
    @api.depends('production_id.move_lines.state')<commit_msg>[IMP] mrp_production_unreserve_movements: no confirmar las ordenes que ya tengan productos planificados<commit_after># -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################
from openerp import models, fields, api


class MrpProduction(models.Model):
    _inherit = 'mrp.production'

    @api.depends('state', 'move_lines.state')
    def _show_buttons(self):
        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'))
            mo.show_check_availability = moves
            mo.show_force_reservation = moves

    @api.depends('move_lines.state')
    def _show_unreserve(self):
        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')
    show_force_reservation = fields.Boolean(
        string='Show force reservation button', compute='_show_buttons')
    show_unreserve = fields.Boolean(
        string='Show unreserve button', compute='_show_unreserve')

    @api.multi
    def button_unreserve(self):
        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()

    @api.multi
    def check_unreserved_moves(self):
        self.ensure_one()
        moves = self.move_lines.filtered(
            lambda x: x.state in ('assigned', 'done'))
        if moves:
            return False
        return True

    @api.multi
    def action_confirm(self):
        mo_to_confirm = self.filtered(lambda x: not x.product_lines or
                                      not x.move_lines)
        mo_no_confirm = self.filtered(lambda x: x.product_lines and
                                      x.move_lines)
        mo_no_confirm.write({'state': 'confirmed'})
        return super(MrpProduction, mo_to_confirm).action_confirm()


class MrpProductionWorkcenterLine(models.Model):
    _inherit = 'mrp.production.workcenter.line'

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

    @api.one
    @api.depends('production_id.move_lines.state')
{'fraction_non_alphanumeric': 0.1539257981018119, 'fraction_numerical': 0.0003451251078515962, 'mean_word_length': 2.5319926873857406, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4553134', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1589, 'n_words': 369}