From ddf2b21bdf38492ce075d4ae96bb9323c6ef59dd Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Thu, 13 Jul 2017 14:19:44 +0200 Subject: [PATCH] [REF] stock: adapt to rename of stock.pack.operation into stock.mode.line --- addons/delivery/models/stock_picking.py | 20 +- .../wizard/choose_delivery_package.py | 4 +- addons/mrp/models/mrp_production.py | 2 +- addons/mrp/models/mrp_unbuild.py | 4 +- addons/mrp/models/mrp_workorder.py | 10 +- addons/mrp/models/stock_move.py | 16 +- addons/mrp/wizard/change_production_qty.py | 2 +- addons/mrp/wizard/mrp_product_produce.py | 12 +- addons/mrp_repair/models/mrp_repair.py | 8 +- addons/point_of_sale/models/pos_order.py | 2 +- .../views/report_deliveryslip.xml | 2 +- addons/purchase/tests/test_create_picking.py | 2 +- addons/purchase/tests/test_purchase_order.py | 6 +- addons/stock/data/stock_demo.yml | 6 +- addons/stock/models/__init__.py | 2 +- addons/stock/models/stock_inventory.py | 2 +- addons/stock/models/stock_move.py | 66 ++--- addons/stock/models/stock_move_line.py | 14 +- addons/stock/models/stock_picking.py | 64 ++--- addons/stock/models/stock_production_lot.py | 2 +- addons/stock/models/stock_quant.py | 6 +- addons/stock/models/stock_scrap.py | 2 +- addons/stock/models/stock_traceability.py | 46 ++-- addons/stock/report/report_deliveryslip.xml | 10 +- .../report/report_stockpicking_operations.xml | 8 +- addons/stock/security/ir.model.access.csv | 8 +- addons/stock/security/stock_security.xml | 4 +- .../xml/stock_traceability_report_line.xml | 4 +- addons/stock/test/packing.yml | 10 +- addons/stock/test/packingneg.yml | 8 +- addons/stock/test/wiseoperator.yml | 12 +- addons/stock/tests/common.py | 2 +- addons/stock/tests/common2.py | 2 +- addons/stock/tests/test_move.py | 228 +++++++++--------- addons/stock/tests/test_move2.py | 80 +++--- addons/stock/tests/test_stock_flow.py | 48 ++-- .../stock/views/report_stock_traceability.xml | 6 +- addons/stock/views/stock_move_views.xml | 8 +- addons/stock/views/stock_picking_views.xml | 6 +- .../stock/wizard/stock_immediate_transfer.py | 4 +- addons/stock/wizard/stock_picking_return.py | 2 +- addons/stock_account/models/stock.py | 6 +- .../tests/test_stockvaluation.py | 34 +-- addons/stock_dropshipping/test/dropship.yml | 2 +- 44 files changed, 396 insertions(+), 396 deletions(-) diff --git a/addons/delivery/models/stock_picking.py b/addons/delivery/models/stock_picking.py index a919ec8e2c5..37a845d937e 100644 --- a/addons/delivery/models/stock_picking.py +++ b/addons/delivery/models/stock_picking.py @@ -22,8 +22,8 @@ class StockQuantPackage(models.Model): shipping_weight = fields.Float(string='Shipping Weight', help="Can be changed during the 'put in pack' to adjust the weight of the shipping.") -class StockPackOperation(models.Model): - _inherit = 'stock.pack.operation' +class StockMoveLine(models.Model): + _inherit = 'stock.move.line' @api.multi def manage_package_type(self): @@ -55,22 +55,22 @@ class StockPicking(models.Model): return weight_uom_id @api.one - @api.depends('pack_operation_ids') + @api.depends('move_line_ids') def _compute_packages(self): self.ensure_one() packs = set() - for packop in self.pack_operation_ids: - if packop.result_package_id and packop.result_package_id.packaging_id: - packs.add(packop.result_package_id.id) + for move_line in self.move_line_ids: + if move_line.result_package_id and move_line.result_package_id.packaging_id: + packs.add(move_line.result_package_id.id) self.package_ids = list(packs) @api.one - @api.depends('pack_operation_ids') + @api.depends('move_line_ids') def _compute_bulk_weight(self): weight = 0.0 - for packop in self.pack_operation_ids: - if packop.product_id and not packop.result_package_id: - weight += packop.product_uom_id._compute_quantity(packop.product_qty, packop.product_id.uom_id) * packop.product_id.weight + for move_line in self.move_line_ids: + if move_line.product_id and not move_line.result_package_id: + weight += move_line.product_uom_id._compute_quantity(move_line.product_qty, move_line.product_id.uom_id) * move_line.product_id.weight self.weight_bulk = weight @api.one diff --git a/addons/delivery/wizard/choose_delivery_package.py b/addons/delivery/wizard/choose_delivery_package.py index 28cae85a8aa..acc4ff0539f 100644 --- a/addons/delivery/wizard/choose_delivery_package.py +++ b/addons/delivery/wizard/choose_delivery_package.py @@ -40,8 +40,8 @@ class ChooseDeliveryPackage(models.TransientModel): return stock_quant_package.shipping_weight else: picking_id = self.env['stock.picking'].browse(self.env.context['active_id']) - pack_operation_ids = [po for po in picking_id.pack_operation_ids if po.qty_done > 0 and not po.result_package_id] - total_weight = sum([po.qty_done * po.product_id.weight for po in pack_operation_ids]) + move_line_ids = [po for po in picking_id.move_line_ids if po.qty_done > 0 and not po.result_package_id] + total_weight = sum([po.qty_done * po.product_id.weight for po in move_line_ids]) return total_weight def put_in_pack(self): diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 74aeb63051d..69ad489da17 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -466,7 +466,7 @@ class MrpProduction(models.Model): if len(workorders) == len(bom.routing_id.operation_ids): moves_raw |= self.move_raw_ids.filtered(lambda move: not move.operation_id) moves_finished = self.move_finished_ids.filtered(lambda move: move.operation_id == operation) #TODO: code does nothing, unless maybe by_products? - moves_raw.mapped('pack_operation_ids').write({'workorder_id': workorder.id}) + moves_raw.mapped('move_line_ids').write({'workorder_id': workorder.id}) (moves_finished + moves_raw).write({'workorder_id': workorder.id}) workorder._generate_lot_ids() diff --git a/addons/mrp/models/mrp_unbuild.py b/addons/mrp/models/mrp_unbuild.py index ee841a7259c..09841db809c 100644 --- a/addons/mrp/models/mrp_unbuild.py +++ b/addons/mrp/models/mrp_unbuild.py @@ -90,7 +90,7 @@ class MrpUnbuild(models.Model): consume_move = self._generate_consume_moves()[0] produce_moves = self._generate_produce_moves() if consume_move.has_tracking != 'none': - self.env['stock.pack.operation'].create({ + self.env['stock.move.line'].create({ 'move_id': consume_move.id, 'lot_id': self.lot_id.id, 'qty_done': consume_move.product_uom_qty, @@ -106,7 +106,7 @@ class MrpUnbuild(models.Model): for produce_move in produce_moves: if produce_move.has_tracking != 'none': original = original_quants.filtered(lambda quant: quant.product_id == produce_move.product_id) - self.env['stock.pack.operation'].create({ + self.env['stock.move.line'].create({ 'move_id': produce_move.id, 'lot_id': original.lot_id.id, 'qty_done': produce_move.product_uom_qty, diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index 75da7786016..f9b420578b7 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -102,11 +102,11 @@ class MrpWorkorder(models.Model): move_raw_ids = fields.One2many( 'stock.move', 'workorder_id', 'Moves') move_line_ids = fields.One2many( - 'stock.pack.operation', 'workorder_id', 'Moves to Track', + 'stock.move.line', 'workorder_id', 'Moves to Track', domain=[('done_wo', '=', True)], help="Inventory moves for which you must scan a lot number at this work order") active_move_line_ids = fields.One2many( - 'stock.pack.operation', 'workorder_id', + 'stock.move.line', 'workorder_id', domain=[('done_wo', '=', False)]) final_lot_id = fields.Many2one( 'stock.production.lot', 'Current Lot', domain="[('product_id', '=', product_id)]", @@ -199,7 +199,7 @@ class MrpWorkorder(models.Model): qty_todo = new_qty - sum(move_lots.mapped('quantity')) if float_compare(qty_todo, 0.0, precision_rounding=move.product_uom.rounding) > 0: while float_compare(qty_todo, 0.0, precision_rounding=move.product_uom.rounding) > 0: - self.active_move_line_ids += self.env['stock.pack.operation'].new({ + self.active_move_line_ids += self.env['stock.move.line'].new({ 'move_id': move.id, 'product_id': move.product_id.id, 'lot_id': False, @@ -236,7 +236,7 @@ class MrpWorkorder(models.Model): def _generate_lot_ids(self): """ Generate stock move lines """ self.ensure_one() - MoveLine = self.env['stock.pack.operation'] + MoveLine = self.env['stock.move.line'] tracked_moves = self.move_raw_ids.filtered( lambda move: move.state not in ('done', 'cancel') and move.product_id.tracking != 'none' and move.product_id != self.production_id.product_id) for move in tracked_moves: @@ -322,7 +322,7 @@ class MrpWorkorder(models.Model): if not self.next_work_order_id: production_move = self.production_id.move_finished_ids.filtered(lambda x: (x.product_id.id == self.production_id.product_id.id) and (x.state not in ('done', 'cancel'))) if production_move.has_tracking != 'none': - move_line = production_move.pack_operation_ids.filtered(lambda x: x.lot_id.id == self.final_lot_id.id) + move_line = production_move.move_line_ids.filtered(lambda x: x.lot_id.id == self.final_lot_id.id) if move_line: move_line.product_qty += self.qty_producing else: diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 0e28d1dd3ec..0cb7f568368 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -7,8 +7,8 @@ from odoo.tools import float_compare, float_round from odoo.addons import decimal_precision as dp -class StockPackOperation(models.Model): - _inherit = 'stock.pack.operation' +class StockMoveLine(models.Model): + _inherit = 'stock.move.line' workorder_id = fields.Many2one('mrp.workorder', 'Work Order') production_id = fields.Many2one('mrp.production', 'Production Order') @@ -33,10 +33,10 @@ class StockPackOperation(models.Model): def write(self, vals): if 'lot_id' in vals: for movelot in self: - movelot.move_id.production_id.move_raw_ids.mapped('pack_operation_ids')\ + movelot.move_id.production_id.move_raw_ids.mapped('move_line_ids')\ .filtered(lambda r: r.done_wo and not r.done_move and r.lot_produced_id == movelot.lot_id)\ .write({'lot_produced_id': vals['lot_id']}) - return super(StockPackOperation, self).write(vals) + return super(StockMoveLine, self).write(vals) class StockMove(models.Model): @@ -55,7 +55,7 @@ class StockMove(models.Model): workorder_id = fields.Many2one( 'mrp.workorder', 'Work Order To Consume') # Quantities to process, in normalized UoMs - active_move_line_ids = fields.One2many('stock.pack.operation', 'move_id', domain=[('done_wo', '=', True)], string='Lots') + active_move_line_ids = fields.One2many('stock.move.line', 'move_id', domain=[('done_wo', '=', True)], string='Lots') bom_line_id = fields.Many2one('mrp.bom.line', 'BoM Line') unit_factor = fields.Float('Unit Factor') is_done = fields.Boolean( @@ -80,8 +80,8 @@ class StockMove(models.Model): def action_assign(self): res = super(StockMove, self).action_assign() for move in self.filtered(lambda x: x.production_id or x.raw_material_production_id): - if move.pack_operation_ids: - move.pack_operation_ids.write({'production_id': move.raw_material_production_id.id, + if move.move_line_ids: + move.move_line_ids.write({'production_id': move.raw_material_production_id.id, 'workorder_id': move.workorder_id.id,}) return res @@ -99,7 +99,7 @@ class StockMove(models.Model): view = self.env.ref('mrp.view_stock_move_lots') serial = (self.has_tracking == 'serial') only_create = False # Check operation type in theory - show_reserved = any([x for x in self.pack_operation_ids if x.product_qty > 0.0]) + show_reserved = any([x for x in self.move_line_ids if x.product_qty > 0.0]) ctx.update({ 'serial': serial, 'only_create': only_create, diff --git a/addons/mrp/wizard/change_production_qty.py b/addons/mrp/wizard/change_production_qty.py index 4ad746ef8be..b408bef5f8b 100644 --- a/addons/mrp/wizard/change_production_qty.py +++ b/addons/mrp/wizard/change_production_qty.py @@ -79,7 +79,7 @@ class ChangeProductionQty(models.TransientModel): if wo == production.workorder_ids[-1]: moves_raw |= production.move_raw_ids.filtered(lambda move: not move.operation_id) moves_finished = production.move_finished_ids.filtered(lambda move: move.operation_id == operation) #TODO: code does nothing, unless maybe by_products? - moves_raw.mapped('pack_operation_ids').write({'workorder_id': wo.id}) + moves_raw.mapped('move_line_ids').write({'workorder_id': wo.id}) (moves_finished + moves_raw).write({'workorder_id': wo.id}) if wo.move_raw_ids.filtered(lambda x: x.product_id.tracking != 'none') and not wo.active_move_line_ids: wo._generate_lot_ids() diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py index 92fbfef526a..d0e4837c1d5 100644 --- a/addons/mrp/wizard/mrp_product_produce.py +++ b/addons/mrp/wizard/mrp_product_produce.py @@ -29,7 +29,7 @@ class MrpProductProduce(models.TransientModel): lines = [] existing_lines = [] for move in production.move_raw_ids.filtered(lambda x: (x.product_id.tracking != 'none') and x.state not in ('done', 'cancel')): - if not move.pack_operation_ids.filtered(lambda x: not x.lot_produced_id): + if not move.move_line_ids.filtered(lambda x: not x.lot_produced_id): qty = quantity / move.bom_line_id.bom_id.product_qty * move.bom_line_id.product_qty if move.product_id.tracking == 'serial': while float_compare(qty, 0.0, precision_rounding=move.product_uom.rounding) > 0: @@ -56,7 +56,7 @@ class MrpProductProduce(models.TransientModel): 'location_dest_id': move.location_dest_id.id, }) else: - existing_lines += move.pack_operation_ids.filtered(lambda x: not x.lot_produced_id).ids + existing_lines += move.move_line_ids.filtered(lambda x: not x.lot_produced_id).ids res['serial'] = serial res['production_id'] = production.id @@ -72,7 +72,7 @@ class MrpProductProduce(models.TransientModel): product_qty = fields.Float(string='Quantity', digits=dp.get_precision('Product Unit of Measure'), required=True) product_uom_id = fields.Many2one('product.uom', 'Unit of Measure') lot_id = fields.Many2one('stock.production.lot', string='Lot') - consume_line_ids = fields.Many2many('stock.pack.operation', 'mrp_produce_stock_pack_operation', string='Product to Track') + consume_line_ids = fields.Many2many('stock.move.line', 'mrp_produce_stock_move_line', string='Product to Track') product_tracking = fields.Selection(related="product_id.tracking") @api.multi @@ -104,12 +104,12 @@ class MrpProductProduce(models.TransientModel): @api.multi def check_finished_move_lots(self): - packs = self.env['stock.pack.operation'] + packs = self.env['stock.move.line'] produce_move = self.production_id.move_finished_ids.filtered(lambda x: x.product_id == self.product_id and x.state not in ('done', 'cancel')) if produce_move and produce_move.product_id.tracking != 'none': if not self.lot_id: raise UserError(_('You need to provide a lot for the finished product')) - existing_move_line = produce_move.pack_operation_ids.filtered(lambda x: x.lot_id == self.lot_id) + existing_move_line = produce_move.move_line_ids.filtered(lambda x: x.lot_id == self.lot_id) if existing_move_line: existing_move_line.product_qty += self.product_qty existing_move_line.qty_done += self.product_qty @@ -127,7 +127,7 @@ class MrpProductProduce(models.TransientModel): } packs.create(vals) for move in self.production_id.move_raw_ids: - for moveline in move.pack_operation_ids.filtered(lambda x: not x.lot_produced_id): + for moveline in move.move_line_ids.filtered(lambda x: not x.lot_produced_id): if moveline.qty_done and self.lot_id: #Possibly the entire move is selected remaining_qty = moveline.product_uom_qty - moveline.qty_done diff --git a/addons/mrp_repair/models/mrp_repair.py b/addons/mrp_repair/models/mrp_repair.py index f92cb1cf975..a098d0b08fa 100644 --- a/addons/mrp_repair/models/mrp_repair.py +++ b/addons/mrp_repair/models/mrp_repair.py @@ -432,8 +432,8 @@ class Repair(models.Model): 'partner_id': repair.address_id.id, 'location_id': operation.location_id.id, 'location_dest_id': operation.location_dest_id.id, - 'pack_operation_ids': [(0, 0, {'product_id': operation.product_id.id, - 'lot_id': operation.lot_id.id, + 'move_line_ids': [(0, 0, {'product_id': operation.product_id.id, + 'lot_id': operation.lot_id.id, 'product_uom_qty': 0, # bypass reservation here 'product_uom_id': operation.product_uom.id, 'qty_done': operation.product_uom_qty, @@ -453,8 +453,8 @@ class Repair(models.Model): 'partner_id': repair.address_id.id, 'location_id': repair.location_id.id, 'location_dest_id': repair.location_dest_id.id, - 'pack_operation_ids': [(0, 0, {'product_id': repair.product_id.id, - 'lot_id': repair.lot_id.id, + 'move_line_ids': [(0, 0, {'product_id': repair.product_id.id, + 'lot_id': repair.lot_id.id, 'product_uom_qty': 0, # bypass reservation here 'product_uom_id': repair.product_uom.id or repair.product_id.uom_id.id, 'qty_done': repair.product_qty, diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 67a639fd659..482ca1d809a 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -724,7 +724,7 @@ class PosOrder(models.Model): has_wrong_lots = True for pack_lot in pack_lots: lot_id, qty = pack_lot['lot_id'], pack_lot['qty'] - self.env['stock.pack.operation'].create({ + self.env['stock.move.line'].create({ 'move_id': move.id, 'product_id': move.product_id.id, 'product_uom_id': move.product_uom.id, diff --git a/addons/product_expiry/views/report_deliveryslip.xml b/addons/product_expiry/views/report_deliveryslip.xml index 97e77a58175..f91af855a81 100644 --- a/addons/product_expiry/views/report_deliveryslip.xml +++ b/addons/product_expiry/views/report_deliveryslip.xml @@ -1,7 +1,7 @@