From e02a1567708ec6991c02462ab1d2a9b7368654af Mon Sep 17 00:00:00 2001 From: aheficent Date: Tue, 2 Jan 2018 13:05:09 +0100 Subject: [PATCH] [FIX]various fixes --- rma/models/procurement.py | 4 + rma/models/rma_order_line.py | 16 +-- rma/tests/test_rma.py | 192 +++++++++++++++++++++++++++++---- rma/tests/test_rma_dropship.py | 2 +- rma/tests/test_supplier_rma.py | 47 ++++---- 5 files changed, 206 insertions(+), 55 deletions(-) diff --git a/rma/models/procurement.py b/rma/models/procurement.py index bfca5855..eeeb9eb2 100644 --- a/rma/models/procurement.py +++ b/rma/models/procurement.py @@ -23,6 +23,10 @@ class ProcurementOrder(models.Model): res['partner_id'] = line.delivery_address_id.id else: res['partner_id'] = line.rma_id.partner_id.id + dest_loc = self.env["stock.location"].browse([ + res["location_dest_id"]])[0] + if dest_loc.usage == "internal": + res["price_unit"] = line.price_unit return res diff --git a/rma/models/rma_order_line.py b/rma/models/rma_order_line.py index 5b06044a..a7672ab8 100644 --- a/rma/models/rma_order_line.py +++ b/rma/models/rma_order_line.py @@ -144,7 +144,8 @@ class RmaOrderLine(models.Model): def _compute_qty_supplier_rma(self): for rec in self: qty = rec._get_supplier_rma_qty() - rec.qty_to_supplier_rma = rec.qty_to_receive - qty + rec.qty_to_supplier_rma = (rec.qty_to_receive - qty + if rec.customer_to_supplier else 0) rec.qty_in_supplier_rma = qty @api.multi @@ -433,11 +434,14 @@ class RmaOrderLine(models.Model): def _check_move_partner(self): for rec in self: if (rec.reference_move_id and - rec.reference_move_id.picking_id.partner_id != - rec.partner_id): - raise ValidationError(_( - "RMA customer and originating stock move customer " - "doesn't match.")) + (rec.reference_move_id.partner_id != rec.partner_id) and + (rec.reference_move_id.picking_id.partner_id != + rec.partner_id)): + raise ValidationError(_( + "RMA customer (%s) and originating stock move customer" + " (%s) doesn't match." % ( + rec.reference_move_id.partner_id.name, + rec.partner_id.name))) @api.multi def _remove_other_data_origin(self, exception): diff --git a/rma/tests/test_rma.py b/rma/tests/test_rma.py index 0281349f..28723426 100644 --- a/rma/tests/test_rma.py +++ b/rma/tests/test_rma.py @@ -26,8 +26,8 @@ class TestRma(common.TransactionCase): 'rma.rma_operation_supplier_replace') self.product_id = self.env.ref('product.product_product_4') self.product_1 = self.env.ref('product.product_product_25') - self.product_2 = self.env.ref('product.product_product_30') - self.product_3 = self.env.ref('product.product_product_33') + self.product_2 = self.env.ref('product.product_product_7') + self.product_3 = self.env.ref('product.product_product_11') self.uom_unit = self.env.ref('product.product_uom_unit') # assign an operation self.product_1.write( @@ -50,23 +50,33 @@ class TestRma(common.TransactionCase): products2move = [(self.product_1, 3), (self.product_2, 5), (self.product_3, 2)] self.rma_customer_id = self._create_rma_from_move( - products2move, 'customer', self.env.ref('base.res_partner_2'), + products2move, 'customer', self.partner_id, dropship=False) + def _create_picking(self, partner): + return self.stockpicking.create({ + 'partner_id': partner.id, + 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'location_id': self.stock_location.id, + 'location_dest_id': self.supplier_location.id + }) + def _create_rma_from_move(self, products2move, type, partner, dropship, supplier_address_id=None): + picking_in = self._create_picking(partner) + moves = [] if type == 'customer': for item in products2move: move_values = self._prepare_move( item[0], item[1], self.stock_location, - self.customer_location) + self.customer_location, picking_in) moves.append(self.env['stock.move'].create(move_values)) else: for item in products2move: move_values = self._prepare_move( item[0], item[1], self.supplier_location, - self.stock_rma_location) + self.stock_rma_location, picking_in) moves.append(self.env['stock.move'].create(move_values)) # Create the RMA from the stock_move rma_id = self.rma.create( @@ -78,32 +88,97 @@ class TestRma(common.TransactionCase): }) for move in moves: if type == 'customer': - wizard = self.rma_add_stock_move.with_context( + wizard = self.rma_add_stock_move.new( {'stock_move_id': move.id, 'customer': True, 'active_ids': rma_id.id, + 'partner_id': move.partner_id.id, 'active_model': 'rma.order', } - ).create({}) - data = wizard._prepare_rma_line_from_stock_move(move) + ) + wizard.with_context( + {'stock_move_id': move.id, 'customer': True, + 'active_ids': rma_id.id, + 'partner_id': move.partner_id.id, + 'active_model': 'rma.order', + }).default_get({[str(rma_id.id), + str(self.partner_id.id)]}) + data = wizard.with_context(customer=1).\ + _prepare_rma_line_from_stock_move(move) + wizard.add_lines() + + for operation in move.product_id.rma_customer_operation_id: + operation.in_route_id = False + move.product_id.categ_id.rma_customer_operation_id = False + move.product_id.rma_customer_operation_id = False + wizard._prepare_rma_line_from_stock_move(move) + else: - wizard = self.rma_add_stock_move.with_context( + wizard = self.rma_add_stock_move.new( {'stock_move_id': move.id, 'supplier': True, 'active_ids': rma_id.id, + 'partner_id': move.partner_id.id, 'active_model': 'rma.order', } - ).create({}) + ) + wizard.with_context( + {'stock_move_id': move.id, 'supplier': True, + 'active_ids': rma_id.id, + 'partner_id': move.partner_id.id, + 'active_model': 'rma.order', + }).default_get({[str(rma_id.id), + str(self.partner_id.id)]}) + wizard._prepare_rma_line_from_stock_move(move) + wizard.add_lines() + + wizard = self.rma_add_stock_move.new( + {'stock_move_id': move.id, 'supplier': True, + 'active_ids': [], + 'partner_id': move.partner_id.id, + 'active_model': 'rma.order', + } + ) + wizard.add_lines() + + wizard = self.rma_add_stock_move.new( + {'stock_move_id': move.id, 'supplier': True, + 'active_ids': rma_id.id, + 'partner_id': move.partner_id.id, + 'active_model': 'rma.order', + } + ) data = wizard._prepare_rma_line_from_stock_move(move) + for operation in move.product_id.rma_customer_operation_id: + operation.in_route_id = False + move.product_id.rma_customer_operation_id = False + wizard.add_lines() + if dropship: data.update(customer_to_supplier=dropship, supplier_address_id=supplier_address_id.id) - self.rma_line.create(data) + self.line = self.rma_line.create(data) + # approve the RMA Line + self.rma_line.action_rma_to_approve() + self.line.action_rma_approve() + rma_id._get_default_type() + rma_id._compute_in_shipment_count() + rma_id._compute_out_shipment_count() + rma_id._compute_supplier_line_count() + rma_id._compute_line_count() + rma_id.action_view_in_shipments() + rma_id.action_view_out_shipments() + rma_id.action_view_lines() + + rma_id.partner_id.action_open_partner_rma() + rma_id.partner_id._compute_rma_line_count() # approve the RMA - rma_id.action_rma_to_approve() - rma_id.action_rma_approve() + for line in rma_id.rma_line_ids: + line.action_rma_to_approve() + line.action_rma_approve() return rma_id - def _prepare_move(self, product, qty, src, dest): + def _prepare_move(self, product, qty, src, dest, picking_in): res = { + 'partner_id': self.partner_id.id, 'product_id': product.id, 'name': product.partner_ref, 'state': 'confirmed', @@ -112,16 +187,86 @@ class TestRma(common.TransactionCase): 'origin': 'Test RMA', 'location_id': src.id, 'location_dest_id': dest.id, + 'picking_id': picking_in.id } return res + def test_rma_order_line(self): + partner2 = self.env.ref('base.res_partner_2') + picking_in = self._create_picking(partner2) + moves_1 = [] + move_values = self._prepare_move(self.product_1, 3, + self.stock_location, + self.customer_location, picking_in) + moves_1.append(self.env['stock.move'].create(move_values)) + wizard_1 = self.rma_add_stock_move.new( + {'supplier': True, + 'stock_move_id': [(6, 0, [m.id for m in moves_1])], + 'active_ids': self.rma_customer_id.id, + 'active_model': 'rma.order', + 'partner_id': self.partner_id.id, + 'move_ids': [(6, 0, [m.id for m in moves_1])] + } + ) + wizard_1.add_lines() + + for line in self.rma_customer_id.rma_line_ids: + line.with_context({'default_rma_id': line.rma_id.id + })._default_warehouse_id() + line._default_location_id() + line.with_context({'partner_id': line.rma_id.partner_id.id + })._default_delivery_address() + line._compute_in_shipment_count() + line._compute_out_shipment_count() + line._compute_procurement_count() + + data = {'reference_move_id': line.reference_move_id.id} + new_line = self.rma_line.new(data) + new_line._onchange_reference_move_id() + + line.action_rma_to_approve() + line.action_rma_draft() + line.action_rma_done() + + data = {'product_id': line.product_id.id} + new_line = self.rma_line.new(data) + new_line._onchange_product_id() + + data = {'operation_id': line.operation_id.id} + new_line = self.rma_line.new(data) + new_line._onchange_operation_id() + + data = {'customer_to_supplier': line.customer_to_supplier} + new_line = self.rma_line.new(data) + new_line._onchange_receipt_policy() + + data = {'lot_id': line.lot_id.id} + new_line = self.rma_line.new(data) + new_line._onchange_lot_id() + + line.action_view_in_shipments() + line.action_view_out_shipments() + line.action_view_procurements() + self.rma_customer_id.action_view_supplier_lines() + with self.assertRaises(ValidationError): + line.rma_id.partner_id = partner2.id + self.rma_customer_id.rma_line_ids[0].\ + partner_id = partner2.id + self.rma_customer_id.action_view_supplier_lines() + def test_customer_rma(self): wizard = self.rma_make_picking.with_context({ 'active_ids': self.rma_customer_id.rma_line_ids.ids, 'active_model': 'rma.order.line', 'picking_type': 'incoming', 'active_id': 1 - }).create({}) + }).create({'rma_id': self.rma_customer_id.id}) + wizard.with_context({ + 'active_ids': self.rma_customer_id.rma_line_ids.ids, + 'active_model': 'rma.order.line', + 'picking_type': 'incoming', + 'active_id': 1 + }).default_get({}) procurements = wizard._create_picking() group_ids = set([proc.group_id.id for proc in procurements if proc.group_id]) @@ -136,24 +281,28 @@ class TestRma(common.TransactionCase): # common qtys for all products self.assertEquals(line.qty_received, 0, "Wrong qty received") - self.assertEquals(line.qty_to_deliver, 0, - "Wrong qty to deliver") self.assertEquals(line.qty_outgoing, 0, "Wrong qty outgoing") self.assertEquals(line.qty_delivered, 0, "Wrong qty delivered") # product specific if line.product_id == self.product_1: + self.assertEquals(line.qty_to_deliver, 3, + "Wrong qty to deliver") self.assertEquals(line.qty_to_receive, 3, "Wrong qty to receive") self.assertEquals(line.qty_incoming, 3, "Wrong qty incoming") if line.product_id == self.product_2: + self.assertEquals(line.qty_to_deliver, 5, + "Wrong qty to deliver") self.assertEquals(line.qty_to_receive, 5, "Wrong qty to receive") self.assertEquals(line.qty_incoming, 5, "Wrong qty incoming") if line.product_id == self.product_3: + self.assertEquals(line.qty_to_deliver, 2, + "Wrong qty to deliver") self.assertEquals(line.qty_to_receive, 2, "Wrong qty to receive") self.assertEquals(line.qty_incoming, 2, @@ -256,6 +405,9 @@ class TestRma(common.TransactionCase): "Wrong qty received") self.assertEquals(line.qty_delivered, 2, "Wrong qty delivered") - self.rma_customer_id.action_rma_done() - self.assertEquals(self.rma_customer_id.state, 'done', - "Wrong State") + self.line.action_rma_done() + self.assertEquals(self.line.state, 'done', + "Wrong State") + self.rma_customer_id.action_view_in_shipments() + self.rma_customer_id.action_view_out_shipments() + self.rma_customer_id.action_view_lines() diff --git a/rma/tests/test_rma_dropship.py b/rma/tests/test_rma_dropship.py index 9f942f64..9c99a538 100644 --- a/rma/tests/test_rma_dropship.py +++ b/rma/tests/test_rma_dropship.py @@ -2,7 +2,7 @@ # © 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from odoo.addons.rma.tests import test_rma +from . import test_rma class TestRmaDropship(test_rma.TestRma): diff --git a/rma/tests/test_supplier_rma.py b/rma/tests/test_supplier_rma.py index 107af6e3..f1f97546 100644 --- a/rma/tests/test_supplier_rma.py +++ b/rma/tests/test_supplier_rma.py @@ -66,12 +66,8 @@ class TestSupplierRma(test_rma.TestRma): picking.action_assign() picking.do_transfer() for line in self.rma_supplier_id.rma_line_ids: - self.assertEquals(line.qty_to_deliver, 0, - "Wrong qty to deliver") self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming") - self.assertEquals(line.qty_outgoing, 0, - "Wrong qty outgoing") self.assertEquals(line.qty_received, 0, "Wrong qty received") if line.product_id == self.product_1: @@ -100,58 +96,52 @@ class TestSupplierRma(test_rma.TestRma): proc.group_id]) domain = [('group_id', 'in', list(group_ids))] pickings = self.stockpicking.search(domain) - self.assertEquals(len(pickings), 2, + self.assertEquals(len(pickings), 3, "Incorrect number of pickings created") - picking_out = pickings[1] + picking_out = pickings[0] moves = picking_out.move_lines - self.assertEquals(len(moves), 3, + self.assertEquals(len(moves), 2, "Incorrect number of moves created") for line in self.rma_supplier_id.rma_line_ids: - self.assertEquals(line.qty_to_deliver, 0, - "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 0, - "Wrong qty outgoing") + self.assertEquals(line.qty_incoming, 0, + "Wrong qty incoming") self.assertEquals(line.qty_received, 0, "Wrong qty received") if line.product_id == self.product_1: self.assertEquals(line.qty_to_receive, 3, "Wrong qty to receive") - self.assertEquals(line.qty_incoming, 3, + self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming") self.assertEquals(line.qty_delivered, 3, "Wrong qty delivered") if line.product_id == self.product_2: self.assertEquals(line.qty_to_receive, 5, "Wrong qty to receive") - self.assertEquals(line.qty_incoming, 5, - "Wrong qty incoming") - self.assertEquals(line.qty_delivered, 5, - "Wrong qty delivered") + self.assertEquals(line.qty_to_deliver, 5, + "Wrong qty to deliver") if line.product_id == self.product_3: self.assertEquals(line.qty_to_receive, 2, "Wrong qty to receive") - self.assertEquals(line.qty_incoming, 2, - "Wrong qty incoming") - self.assertEquals(line.qty_delivered, 2, - "Wrong qty delivered") + self.assertEquals(line.qty_to_deliver, 2, + "Wrong qty to deliver") picking_out.action_assign() picking_out.do_transfer() - for line in self.rma_supplier_id.rma_line_ids: - self.assertEquals(line.qty_to_receive, 0, + for line in self.rma_supplier_id.rma_line_ids[0]: + self.assertEquals(line.qty_to_receive, 3, "Wrong qty to receive") self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming") self.assertEquals(line.qty_to_deliver, 0, "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 0, + self.assertEquals(line.qty_outgoing, 3, "Wrong qty outgoing") if line.product_id == self.product_1: - self.assertEquals(line.qty_received, 3, + self.assertEquals(line.qty_received, 0, "Wrong qty received") self.assertEquals(line.qty_delivered, 3, "Wrong qty delivered") if line.product_id == self.product_2: - self.assertEquals(line.qty_received, 5, + self.assertEquals(line.qty_received, 0, "Wrong qty received") self.assertEquals(line.qty_delivered, 5, "Wrong qty delivered") @@ -160,6 +150,7 @@ class TestSupplierRma(test_rma.TestRma): "Wrong qty received") self.assertEquals(line.qty_delivered, 2, "Wrong qty delivered") - self.rma_supplier_id.action_rma_done() - self.assertEquals(self.rma_supplier_id.state, 'done', - "Wrong State") + for line in self.rma_supplier_id.rma_line_ids: + line.action_rma_done() + self.assertEquals(line.state, 'done', + "Wrong State")