From 6337ddd4966b5eb8c4db2e5867cceed52360e4d2 Mon Sep 17 00:00:00 2001 From: amoyaux Date: Tue, 11 Jul 2017 14:50:44 +0200 Subject: [PATCH] [REF] point of sale: adapt to new stock implementation --- addons/point_of_sale/models/pos_order.py | 26 +++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index e307cd02c24..67a639fd659 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -694,7 +694,7 @@ class PosOrder(models.Model): PosPackOperationLot = self.env['pos.pack.operation.lot'] has_wrong_lots = False for order in self: - for pack_operation in (picking or self.picking_id).pack_operation_ids: + for move in (picking or self.picking_id).move_lines: picking_type = (picking or self.picking_id).picking_type_id lots_necessary = True if picking_type: @@ -702,27 +702,39 @@ class PosOrder(models.Model): qty = 0 qty_done = 0 pack_lots = [] - pos_pack_lots = PosPackOperationLot.search([('order_id', '=', order.id), ('product_id', '=', pack_operation.product_id.id)]) + pos_pack_lots = PosPackOperationLot.search([('order_id', '=', order.id), ('product_id', '=', move.product_id.id)]) pack_lot_names = [pos_pack.lot_name for pos_pack in pos_pack_lots] if pack_lot_names and lots_necessary: for lot_name in list(set(pack_lot_names)): - stock_production_lot = StockProductionLot.search([('name', '=', lot_name), ('product_id', '=', pack_operation.product_id.id)]) + stock_production_lot = StockProductionLot.search([('name', '=', lot_name), ('product_id', '=', move.product_id.id)]) if stock_production_lot: if stock_production_lot.product_id.tracking == 'lot': # if a lot nr is set through the frontend it will refer to the full quantity - qty = pack_operation.product_qty + qty = move.product_uom_qty else: # serial numbers qty = 1.0 qty_done += qty pack_lots.append({'lot_id': stock_production_lot.id, 'qty': qty}) else: has_wrong_lots = True - elif pack_operation.product_id.tracking == 'none' or not lots_necessary: - qty_done = pack_operation.product_qty + elif move.product_id.tracking == 'none' or not lots_necessary: + qty_done = move.product_uom_qty else: has_wrong_lots = True - pack_operation.write({'pack_lot_ids': [(0, 0, x) for x in pack_lots], 'qty_done': qty_done}) + for pack_lot in pack_lots: + lot_id, qty = pack_lot['lot_id'], pack_lot['qty'] + self.env['stock.pack.operation'].create({ + 'move_id': move.id, + 'product_id': move.product_id.id, + 'product_uom_id': move.product_uom.id, + 'qty_done': qty, + 'location_id': move.location_id.id, + 'location_dest_id': move.location_dest_id.id, + 'lot_id': lot_id, + }) + if not pack_lots: + move.quantity_done = qty_done return has_wrong_lots def _prepare_bank_statement_line_payment_values(self, data):