<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#    Copyright (C) 2010-2010 Camptocamp Austria (<http://www.camptocamp.at>)
#
#    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 pooler
import time
from osv import fields, osv
from tools.translate import _
import netsvc
import logging

class stock_location(osv.osv):
    _inherit = "stock.location"

    _columns = {
        'sequence': fields.integer('Sequence', help="Important when pull pickings are create, the execution order will be decided based on this, low number is higher priority."),
    }

stock_location()

class sale_order(osv.osv):
    _inherit = "sale.order"
    

    _columns = {
        'state_internal': fields.selection([('', 'Unused'), ('calculation', 'Calculation'), ('calculated', 'Calculated')], 'Internal Pull Calcualtion', \
                help="This indicates the status of the internal pull calculation"),
    }


    def order_pull_internal(self, cr, uid, ids, context=None):
        if not context:
            context = {}
        _logger = logging.getLogger(__name__)
        
        product_obj = self.pool.get('product.product')
        location_obj = self.pool.get('stock.location')
        picking_obj = self.pool.get('stock.picking')
        move_obj = self.pool.get('stock.move')
        lot_obj = self.pool.get('stock.production.lot')
        company_obj = self.pool.get('res.company')

        if not context.get('company_id'):
            company_id = company_obj._company_default_get(cr, uid, 'stock.company', context=context),
            context['company_id'] = company_id

        order_ids =[]

        move_lines = []
        back_log_lines = []
        loc_ids = []
        for order in self.browse(cr, uid, ids, context):
            if not order.state_internal and order.state == 'progress':
                order_ids.append(order.id)
        # FIXME uncomment# order.write(cr, uid, order_ids,{'state_internal':'calculation'} )

        order_ids2 = (', '.join(map(str,order_ids)))
        cr.execute("""select shop_id, product_id, sum(product_uom_qty) as qty_requested
                   from sale_order_line l,
                        sale_order o
                  where o.id = l.order_id
                    and order_id in (%s)
                  group by o.shop_id, product_id""" % order_ids2)
        for product_qty in cr.dictfetchall():
            _logger.info('FGF sale pull internal %s' % (product_qty))
            product_id = product_qty['product_id']
            shop_id = product_qty['shop_id']
            qty_requested = product_qty['qty_requested']
            # select source destination
            cr.execute("""select id
                   from stock_location
                  where sequence is not null
                  order by sequence""") 
            for loc in cr.fetchall():
                _logger.info('FGF sale location %s ' % (loc))
                location_id = loc[0]
                context['location_id'] = loc[0]
                _logger.info('FGF sale location id %s ' % (context))
                qty_availiable = product_obj.get_product_available(cr, uid, [product_id] , context)
                qty_avail = qty_availiable.get(product_id)
                _logger.info('FGF sale location product %s %s %s ' % (product_id, qty_avail, qty_requested))
                ml = {'shop_id':shop_id, 'location_id':location_id, 'product_id': product_id,}
                if qty_requested > 0 and qty_avail >0:
                  if qty_avail > qty_requested:
                    qty_requested = 0.0
                    ml.update({'product_qty':qty_requested})
                    move_lines.append(ml)
                    if location_id not in loc_ids:
                        loc_ids.append(location_id)
                  elif qty_available > 0 and qty_avail > qty_requested:
                    qty_requested = qty_requested - qty_avail
                    ml.update({'product_qty':qty_avail})
                    move_lines.append(ml)<commit_msg>[REF] div<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#    Copyright (C) 2010-2010 Camptocamp Austria (<http://www.camptocamp.at>)
#
#    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 pooler
import time
from osv import fields, osv
from tools.translate import _
import netsvc
import logging

class stock_location(osv.osv):
    _inherit = "stock.location"

    _columns = {
        'sequence': fields.integer('Sequence', help="Important when pull pickings are create, the execution order will be decided based on this, low number is higher priority."),
    }

stock_location()

class sale_order(osv.osv):
    _inherit = "sale.order"
    

    _columns = {
        'state_internal': fields.selection([('', 'Unused'), ('calculation', 'Calculation'), ('calculated', 'Calculated')], 'Internal Pull Calcualtion', \
                help="This indicates the status of the internal pull calculation"),
    }


    def order_pull_internal(self, cr, uid, ids, context=None):
        if not context:
            context = {}
        _logger = logging.getLogger(__name__)
        
        product_obj = self.pool.get('product.product')
        location_obj = self.pool.get('stock.location')
        picking_obj = self.pool.get('stock.picking')
        move_obj = self.pool.get('stock.move')
        lot_obj = self.pool.get('stock.production.lot')
        company_obj = self.pool.get('res.company')
        shop_obj = self.pool.get('sale.shop')

        if not context.get('company_id'):
            company_id = company_obj._company_default_get(cr, uid, 'stock.company', context=context),
            context['company_id'] = company_id[0]

        order_ids =[]

        move_lines = []
        back_log_lines = []
        loc_ids = []
        for order in self.browse(cr, uid, ids, context):
            if not order.state_internal and order.state == 'progress':
                order_ids.append(order.id)
        # FIXME uncomment# order.write(cr, uid, order_ids,{'state_internal':'calculation'} )

        order_ids2 = (', '.join(map(str,order_ids)))
        cr.execute("""select shop_id, product_id, sum(product_uom_qty) as qty_requested
                   from sale_order_line l,
                        sale_order o
                  where o.id = l.order_id
                    and order_id in (%s)
                  group by o.shop_id, product_id""" % order_ids2)
        for product_qty in cr.dictfetchall():
            _logger.info('FGF sale pull internal %s' % (product_qty))
            product_id = product_qty['product_id']
            shop_id = product_qty['shop_id']
            qty_requested = product_qty['qty_requested']
            for shop in shop_obj.browse(cr, uid, [shop_id], context=context):
                location_dest_id = shop.warehouse_id.lot_output_id.id
                address_id = shop.warehouse_id.partner_address_id and shop.warehouse_id.partner_address_id.id 
            # select source location
            cr.execute("""select id
                   from stock_location
                  where sequence is not null
                  order by sequence""") 
            for loc in cr.fetchall():
                _logger.info('FGF sale location %s ' % (loc))
                location_id = loc[0]
                context['location_id'] = loc[0]
                _logger.info('FGF sale location id %s ' % (context))
                qty_availiable = product_obj.get_product_available(cr, uid, [product_id] , context)
                qty_avail = qty_availiable.get(product_id)
                _logger.info('FGF sale location product %s %s %s ' % (product_id, qty_avail, qty_requested))
                ml = {'shop_id':shop_id, 'location_id':location_id, 'product_id': product_id,}
                if qty_requested > 0 and qty_avail >0:
                  if qty_avail > qty_requested:
                    qty_requested = 0.0
                    ml.update({'product_qty':qty_requested})
                    move_lines.append(ml)
                    if location_id not in loc_ids:
                        loc_ids.append(location_id)
                  elif qty_available > 0 and qty_avail > qty_requested:
                    qty_requested = qty_requested - qty_avail
                    ml.update({'product_qty':qty_avail})
                    move_lines.append(ml)
{'fraction_non_alphanumeric': 0.12898737950909273, 'fraction_numerical': 0.005465566928351386, 'mean_word_length': 2.355785261753918, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6509191', 'n_tokens_mistral': 2952, 'n_tokens_neox': 2790, 'n_words': 763}