<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
###############################################################################
#
# ODOO (ex OpenERP)
# Open Source Management Solution
# Copyright (C) 2001-2015 Micronaet S.r.l. (<https://micronaet.com>)
# Developer: <NAME> @thebrush (<https://it.linkedin.com/in/thebrush>)
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

import os
import sys
import logging
import openerp
import openerp.netsvc as netsvc
import openerp.addons.decimal_precision as dp
import xlsxwriter
from openerp.osv import fields, osv, expression
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from openerp import SUPERUSER_ID
from openerp import tools
from openerp.tools.translate import _
from openerp.tools.float_utils import float_round as round
from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT,
    DEFAULT_SERVER_DATETIME_FORMAT,
    DATETIME_FORMATS_MAP,
    float_compare)
import pdb

_logger = logging.getLogger(__name__)


class MrpProductionWorkcenterLine(osv.osv):
    """ Model name: Lavoration
    """

    _inherit = 'mrp.production.workcenter.line'

    def get_product_stock_days_force(self, cr, uid, data, context=None):
        """ Extract product if exist particularity for stock level days forced
        """
        now = datetime.now()
        product_pool = self.pool.get('product.product')
        product_ids = product_pool.search(cr, uid, [
            ('mrp_stock_level_force', '>', 0),
        ], context=context)
        for product in product_pool.browse(
                cr, uid, product_ids, context=context):
            data[product] = self.get_form_date(
                now, product.mrp_stock_level_force)
        return True

    def update_product_medium_from_dict(
            self, cr, uid, product_medium, stock_level_days, product_obsolete,
            context=None):
        """" Upload product with dictionary loaded:
        """
        # TODO Not used for now:
        product_obsolete = {}
        product_pool = self.pool.get('product.product')
        _logger.warning('Product found: %s' % len(product_medium))

        for product in product_medium:
            total = product_medium[product]
            if product.manual_stock_level:
                continue

            if not total:
                medium_stock_qty = 0.0
            else:
                medium_stock_qty = total / stock_level_days

            product_pool.write(cr, uid, [product.id], {
                'medium_origin': 'mrp',
                'medium_stock_qty': medium_stock_qty,
                'min_stock_level':
                    product.day_min_level * medium_stock_qty,
                # product_pool.round_integer_order(
                #    product.day_min_level * medium_stock_qty,
                #    approx=product.approx_integer,
                #    mode=product.approx_mode),
                'max_stock_level':
                    product.day_max_level * medium_stock_qty,
                # product_pool.round_integer_order(
                #    product.day_max_level * medium_stock_qty,
                #    approx=product.approx_integer,<commit_msg>generic bugfix (fast message)<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
###############################################################################
#
# ODOO (ex OpenERP)
# Open Source Management Solution
# Copyright (C) 2001-2015 Micronaet S.r.l. (<https://micronaet.com>)
# Developer: <NAME> @thebrush (<https://it.linkedin.com/in/thebrush>)
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

import os
import sys
import logging
import openerp
import openerp.netsvc as netsvc
import openerp.addons.decimal_precision as dp
import xlsxwriter
from openerp.osv import fields, osv, expression
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from openerp import SUPERUSER_ID
from openerp import tools
from openerp.tools.translate import _
from openerp.tools.float_utils import float_round as round
from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT,
    DEFAULT_SERVER_DATETIME_FORMAT,
    DATETIME_FORMATS_MAP,
    float_compare)
import pdb

_logger = logging.getLogger(__name__)


class MrpProductionWorkcenterLine(osv.osv):
    """ Model name: Lavoration
    """

    _inherit = 'mrp.production.workcenter.line'

    def get_product_stock_days_force(self, cr, uid, data, context=None):
        """ Extract product if exist particularity for stock level days forced
        """
        now = datetime.now()
        product_pool = self.pool.get('product.product')
        product_ids = product_pool.search(cr, uid, [
            ('mrp_stock_level_force', '>', 0),
        ], context=context)
        for product in product_pool.browse(
                cr, uid, product_ids, context=context):
            data[product] = self.get_form_date(
                now, product.mrp_stock_level_force)
        return True

    def update_product_medium_from_dict(
            self, cr, uid, product_medium, stock_level_days, product_obsolete,
            context=None):
        """" Upload product with dictionary loaded:
        """
        # TODO Not used for now:
        product_obsolete = {}
        product_pool = self.pool.get('product.product')
        _logger.warning('Product found: %s' % len(product_medium))

        log_f = open(os.path.expanduser('~/medium.log'), 'w')
        for product in product_medium:
            total = product_medium[product]
            if product.manual_stock_level:
                continue

            if not total:
                medium_stock_qty = 0.0
            else:
                medium_stock_qty = total / stock_level_days

            log_f.write('%s|%s|%s|%s\n' % (
                product.id,
                product.default_code,
                medium_stock_qty,
                product_obsolete.get(product, False)
            ))
            product_pool.write(cr, uid, [product.id], {
                'medium_origin': 'mrp',
                'medium_stock_qty': medium_stock_qty,
                'min_stock_level':
                    product.day_min_level * medium_stock_qty,
                # product_pool.round_integer_order(
                #    product.day_min_level * medium_stock_qty,
                #    approx=product.approx_integer,
                #    mode=product.approx_mode),
                'max_stock_level':
                    product.day_max_level * medium_stock_qty,
                # product_pool.round_integer_order(
                #    product.day_max_level * medium_stock_qty,
                #    approx=product.approx_integer,
{'fraction_non_alphanumeric': 0.11988011988011989, 'fraction_numerical': 0.003246753246753247, 'mean_word_length': 2.739028944911298, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1540458', 'n_tokens_mistral': 2298, 'n_tokens_neox': 2163, 'n_words': 603}