<commit_before>
# -*- encoding: utf-8 -*-
##############################################################################
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published
#    by the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see http://www.gnu.org/licenses/.
#
##############################################################################

from openerp import models, fields, api, exceptions, _
import openerp.addons.decimal_precision as dp


class WizProductionProductLine(models.TransientModel):
    _name = 'wiz.production.product.line'

    product_id = fields.Many2one('product.product', 'Product', required=True)
    product_qty = fields.Float(
        'Product Quantity', digits=dp.get_precision('Product Unit of Measure'),
        required=True)
    production_id = fields.Many2one(
        'mrp.production', 'Production Order', select=True,
        default=lambda self: self.env.context.get('active_id', False))

    def _prepare_product_addition(self, product, product_qty, production):
        addition_vals = {'product_id': product.id,
                         'product_uom': product.product_tmpl_id.uom_id.id,
                         'product_qty': product_qty,
                         'production_id': production.id, 'name': product.name,
                         'addition': True}
        return addition_vals

    @api.multi
    def add_product(self):
        mppl_obj = self.env['mrp.production.product.line']
        production_obj = self.env['mrp.production']
        values = self._prepare_product_addition(self.product_id,
                                                self.product_qty,
                                                self.production_id)
        line = mppl_obj.create(values)
        if self.product_qty > 0:
            production_obj._make_production_consume_line(line)
        else:
            raise exceptions.Warning(
                _('Warning'), _('Please provide a positive quantity to add'))
        return True<commit_msg>[IMP] Quantity check<commit_after>
# -*- encoding: utf-8 -*-
##############################################################################
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published
#    by the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see http://www.gnu.org/licenses/.
#
##############################################################################

from openerp import models, fields, api, exceptions, _
import openerp.addons.decimal_precision as dp


class WizProductionProductLine(models.TransientModel):
    _name = 'wiz.production.product.line'

    product_id = fields.Many2one('product.product', 'Product', required=True)
    product_qty = fields.Float(
        'Product Quantity', digits=dp.get_precision('Product Unit of Measure'),
        required=True)
    production_id = fields.Many2one(
        'mrp.production', 'Production Order', select=True,
        default=lambda self: self.env.context.get('active_id', False))

    def _prepare_product_addition(self, product, product_qty, production):
        addition_vals = {'product_id': product.id,
                         'product_uom': product.product_tmpl_id.uom_id.id,
                         'product_qty': product_qty,
                         'production_id': production.id, 'name': product.name,
                         'addition': True}
        return addition_vals

    @api.multi
    def add_product(self):
        if self.product_qty <= 0:
            raise exceptions.Warning(
                _('Warning'), _('Please provide a positive quantity to add'))
        mppl_obj = self.env['mrp.production.product.line']
        production_obj = self.env['mrp.production']
        values = self._prepare_product_addition(self.product_id,
                                                self.product_qty,
                                                self.production_id)
        line = mppl_obj.create(values)
        production_obj._make_production_consume_line(line)
        return True
{'fraction_non_alphanumeric': 0.1441117764471058, 'fraction_numerical': 0.001996007984031936, 'mean_word_length': 2.7173590504451037, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3952847', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1242, 'n_words': 382}