← Back to team overview

openerp-india team mailing list archive

[Bug 926541] Re: action_split has obvious bug and behavior not as expected

 

Hello Jeroen Vet,

I have checked your Issue with latest revision and also with stable. But
at my end it's running fine as expected. That's why I have attached the
video. Would you please check it And notify us where you have faced the
problem.

Correct me If I am wrong!

Thank you and waiting for your reply!

** Attachment added: "split lot - working fine"
   https://bugs.launchpad.net/openobject-addons/+bug/926541/+attachment/2729514/+files/production_lot.ogv

** Changed in: openobject-addons
       Status: New => Incomplete

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/926541

Title:
  action_split has obvious bug and behavior not as expected

Status in OpenERP Addons (modules):
  Incomplete

Bug description:
  The expected behavior of action_split on stock.stock_move imho  would
  be that the original move quantity is reduced by quantity if quantity
  < move.quantity and there are split off moves for as many as quantity
  allows, each of the split off moves having a a quantity equal (or less
  for the last split off move if any remainder) to the
  split_by_quantity.

  However the actual behavior is that:
  if quantity >= move.qty
  - the original move is set to split_by_qty and its move.id is returned as res[0]
  - there are additional new split of moves for as many as quantity - split_by_qty (for the original move) allows and for the remainder. Their  these ids are also returned.

  if quantity < move.qty
  - the system splits of moves and returns their ids but NEVER TOUCHES THE ORIGINAL MOVE. The original move is also not returned and remains having the old quantity.

  There is also an obvious bug in that the uos_qty is not set correctly
  for the remainder.

  I would suggest suggest the following changes in the code (indicated
  by the remarsk):

      def action_split(self, cr, uid, ids, quantity, split_by_qty=1, prefix=False, with_lot=True, context=None):
          """ Split Stock Move lines into production lot which specified split by quantity.
          @param cr: the database cursor
          @param uid: the user id
          @param ids: ids of stock move object to be splited
          @param split_by_qty : specify split by qty
          @param prefix : specify prefix of production lot
          @param with_lot : if true, prodcution lot will assign for split line otherwise not.
          @param context: context arguments
          @return: Splited move lines
          """

          if context is None:
              context = {}
          if quantity <= 0:
              raise osv.except_osv(_('Warning!'), _('Please provide Proper Quantity !'))

          res = []

          for move in self.browse(cr, uid, ids, context=context):
              if split_by_qty <= 0 or quantity == 0:
                  return res

              uos_qty = split_by_qty / move.product_qty *
  move.product_uos_qty

              quantity_rest = quantity % split_by_qty
              #uos_qty_rest = split_by_qty / move.product_qty * move.product_uos_qty
              uos_qty_rest = quantity_rest / move.product_qty * move.product_uos_qty

              update_val = {
                  'product_qty': split_by_qty,
                  'product_uos_qty': uos_qty,
              }
              for idx in range(int(quantity//split_by_qty)):
                  if not idx and move.product_qty<=quantity:
                      current_move = move.id
                  else:
                      current_move = self.copy(cr, uid, move.id, {'state': move.state})
                  res.append(current_move)
                  if with_lot:
                      update_val['prodlot_id'] = self._create_lot(cr, uid, [current_move], move.product_id.id)

                  self.write(cr, uid, [current_move], update_val)

  
              if quantity_rest > 0:
                  idx = int(quantity//split_by_qty)
                  update_val['product_qty'] = quantity_rest
                  update_val['product_uos_qty'] = uos_qty_rest
                  if not idx and move.product_qty<=quantity:
                      current_move = move.id
                  else:
                      current_move = self.copy(cr, uid, move.id, {'state': move.state})

                  res.append(current_move)

  
                  if with_lot:
                      update_val['prodlot_id'] = self._create_lot(cr, uid, [current_move], move.product_id.id)

                  self.write(cr, uid, [current_move], update_val)

              # added to modify behavior to always update original move by reducing it with quantity if quantity < move qty             
              if quantity < move.product_qty:
                  update_val['product_qty'] = move.product_qty - quantity
                  update_val['product_uos_qty'] = (move.product_qty - quantity)/move.product_qty * move.product_uos_qty
                  self.write(cr,uid,[move.id],update_val)
                  
          return res

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/926541/+subscriptions


References