[9.0][IMP] rma: tests moved to Savedpointcase and optimized (66% time reduction)

This commit is contained in:
Lois Rilo
2018-05-14 17:05:57 +02:00
committed by Florian da Costa
parent e2790c24c3
commit 5606be6d2d
4 changed files with 389 additions and 404 deletions

View File

@@ -2,5 +2,3 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from . import test_rma from . import test_rma
from . import test_supplier_rma
from . import test_rma_dropship

View File

@@ -1,113 +1,114 @@
# Copyright (C) 2017 Eficent Business and IT Consulting Services S.L. # © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo.tests import common from openerp.tests import common
from odoo.exceptions import ValidationError from openerp.exceptions import ValidationError
class TestRma(common.TransactionCase): class TestRma(common.SavepointCase):
""" Test the routes and the quantities """ """ Test the routes and the quantities """
def setUp(self): @classmethod
super(TestRma, self).setUp() def setUpClass(cls):
super(TestRma, cls).setUpClass()
self.rma_make_picking = self.env['rma_make_picking.wizard'] cls.rma_make_picking = cls.env['rma_make_picking.wizard']
self.make_supplier_rma = self.env["rma.order.line.make.supplier.rma"] cls.make_supplier_rma = cls.env["rma.order.line.make.supplier.rma"]
self.rma_add_stock_move = self.env['rma_add_stock_move'] cls.rma_add_stock_move = cls.env['rma_add_stock_move']
self.stockpicking = self.env['stock.picking'] cls.stockpicking = cls.env['stock.picking']
self.rma = self.env['rma.order'] cls.rma = cls.env['rma.order']
self.rma_line = self.env['rma.order.line'] cls.rma_line = cls.env['rma.order.line']
self.rma_op = self.env['rma.operation'] cls.rma_op = cls.env['rma.operation']
self.rma_cust_replace_op_id = self.env.ref( cls.rma_cust_replace_op_id = cls.env.ref(
'rma.rma_operation_customer_replace') 'rma.rma_operation_customer_replace')
self.rma_sup_replace_op_id = self.env.ref( cls.rma_sup_replace_op_id = cls.env.ref(
'rma.rma_operation_supplier_replace') 'rma.rma_operation_supplier_replace')
self.product_id = self.env.ref('product.product_product_4') cls.product_id = cls.env.ref('product.product_product_4')
self.product_1 = self.env.ref('product.product_product_25') cls.product_1 = cls.env.ref('product.product_product_25')
self.product_2 = self.env.ref('product.product_product_7') cls.product_2 = cls.env.ref('product.product_product_30')
self.product_3 = self.env.ref('product.product_product_11') cls.product_3 = cls.env.ref('product.product_product_33')
self.uom_unit = self.env.ref('product.product_uom_unit') cls.uom_unit = cls.env.ref('product.product_uom_unit')
# assign an operation # assign an operation
self.product_id.write( cls.product_1.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id, {'rma_customer_operation_id': cls.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id}) 'rma_supplier_operation_id': cls.rma_sup_replace_op_id.id})
self.product_1.write( cls.product_2.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id, {'rma_customer_operation_id': cls.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id}) 'rma_supplier_operation_id': cls.rma_sup_replace_op_id.id})
self.product_2.write( cls.product_3.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id, {'rma_customer_operation_id': cls.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id}) 'rma_supplier_operation_id': cls.rma_sup_replace_op_id.id})
self.product_3.write( cls.partner_id = cls.env.ref('base.res_partner_12')
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id, cls.stock_location = cls.env.ref('stock.stock_location_stock')
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id}) wh = cls.env.ref('stock.warehouse0')
self.partner_id = self.env.ref('base.res_partner_12') cls.stock_rma_location = wh.lot_rma_id
self.stock_location = self.env.ref('stock.stock_location_stock') cls.customer_location = cls.env.ref(
self.stock_rma_location = self.env.ref('rma.location_rma')
self.customer_location = self.env.ref(
'stock.stock_location_customers') 'stock.stock_location_customers')
self.supplier_location = self.env.ref( cls.supplier_location = cls.env.ref(
'stock.stock_location_suppliers') 'stock.stock_location_suppliers')
self.product_uom_id = self.env.ref('product.product_uom_unit') cls.product_uom_id = cls.env.ref('product.product_uom_unit')
products2move = [(self.product_1, 3), (self.product_2, 5), # Customer RMA:
(self.product_3, 2)] products2move = [(cls.product_1, 3), (cls.product_2, 5),
self.rma_customer_id = self._create_rma_from_move( (cls.product_3, 2)]
products2move, 'customer', self.partner_id, cls.rma_customer_id = cls._create_rma_from_move(
products2move, 'customer', cls.env.ref('base.res_partner_2'),
dropship=False)
# Dropship:
cls.rma_droship_id = cls._create_rma_from_move(
products2move, 'customer', cls.env.ref('base.res_partner_2'),
dropship=True,
supplier_address_id=cls.env.ref('base.res_partner_3'))
# Supplier RMA:
cls.rma_supplier_id = cls._create_rma_from_move(
products2move, 'supplier', cls.env.ref('base.res_partner_1'),
dropship=False) dropship=False)
def _create_picking(self, partner): @classmethod
return self.stockpicking.create({ def _create_picking(cls, partner):
return cls.stockpicking.create({
'partner_id': partner.id, 'partner_id': partner.id,
'picking_type_id': self.env.ref('stock.picking_type_in').id, 'picking_type_id': cls.env.ref('stock.picking_type_in').id,
'location_id': self.stock_location.id, 'location_id': cls.stock_location.id,
'location_dest_id': self.supplier_location.id 'location_dest_id': cls.supplier_location.id
}) })
def _create_rma_from_move(self, products2move, type, partner, dropship, @classmethod
def _create_rma_from_move(cls, products2move, type, partner, dropship,
supplier_address_id=None): supplier_address_id=None):
picking_in = self._create_picking(partner) picking_in = cls._create_picking(partner)
moves = [] moves = []
if type == 'customer': if type == 'customer':
for item in products2move: for item in products2move:
move_values = self._prepare_move( move_values = cls._prepare_move(
item[0], item[1], self.stock_location, item[0], item[1], cls.stock_location,
self.customer_location, picking_in) cls.customer_location, picking_in)
moves.append(self.env['stock.move'].create(move_values)) moves.append(cls.env['stock.move'].create(move_values))
else: else:
for item in products2move: for item in products2move:
move_values = self._prepare_move( move_values = cls._prepare_move(
item[0], item[1], self.supplier_location, item[0], item[1], cls.supplier_location,
self.stock_rma_location, picking_in) cls.stock_rma_location, picking_in)
moves.append(self.env['stock.move'].create(move_values)) moves.append(cls.env['stock.move'].create(move_values))
# Create the RMA from the stock_move # Create the RMA from the stock_move
rma_id = self.rma.create( rma_id = cls.rma.create(
{ {
'reference': '0001', 'reference': '0001',
'type': type, 'type': type,
'partner_id': partner.id, 'partner_id': partner.id,
'company_id': self.env.ref('base.main_company').id 'company_id': cls.env.ref('base.main_company').id
}) })
for move in moves: for move in moves:
if type == 'customer': if type == 'customer':
wizard = self.rma_add_stock_move.new( wizard = cls.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'customer': True, {'stock_move_id': move.id, 'customer': True,
'active_ids': rma_id.id, 'active_ids': rma_id.id,
'partner_id': move.partner_id.id,
'active_model': 'rma.order', 'active_model': 'rma.order',
} }
) ).create({})
wizard.with_context({ data = wizard._prepare_rma_line_from_stock_move(move)
'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(move.id),
str(self.partner_id.id)])
data = wizard.with_context(customer=1).\
_prepare_rma_line_from_stock_move(move)
wizard.add_lines() wizard.add_lines()
data['partner_id'] = move.partner_id.id
for operation in move.product_id.rma_customer_operation_id: for operation in move.product_id.rma_customer_operation_id:
operation.in_route_id = False operation.in_route_id = False
move.product_id.categ_id.rma_customer_operation_id = False move.product_id.categ_id.rma_customer_operation_id = False
@@ -115,41 +116,30 @@ class TestRma(common.TransactionCase):
wizard._prepare_rma_line_from_stock_move(move) wizard._prepare_rma_line_from_stock_move(move)
else: else:
wizard = self.rma_add_stock_move.new( wizard = cls.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'supplier': True, {'stock_move_id': move.id, 'supplier': True,
'active_ids': rma_id.id, 'active_ids': rma_id.id,
'partner_id': move.partner_id.id,
'active_model': 'rma.order', 'active_model': 'rma.order',
} }
) ).create({})
wizard.with_context( data = wizard._prepare_rma_line_from_stock_move(move)
{'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(move.id),
str(self.partner_id.id)])
wizard._prepare_rma_line_from_stock_move(move)
wizard.add_lines() wizard.add_lines()
wizard = self.rma_add_stock_move.new( wizard = cls.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'supplier': True, {'stock_move_id': move.id, 'supplier': True,
'active_ids': [], 'active_ids': [],
'partner_id': move.partner_id.id,
'active_model': 'rma.order', 'active_model': 'rma.order',
} }
) ).create({})
wizard.add_lines() wizard.add_lines()
wizard = self.rma_add_stock_move.new( wizard = cls.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'supplier': True, {'stock_move_id': move.id, 'supplier': True,
'active_ids': rma_id.id, 'active_ids': rma_id.id,
'partner_id': move.partner_id.id,
'active_model': 'rma.order', 'active_model': 'rma.order',
} }
) ).create({})
data = wizard._prepare_rma_line_from_stock_move(move) data = wizard._prepare_rma_line_from_stock_move(move)
data['partner_id'] = move.partner_id.id
for operation in move.product_id.rma_customer_operation_id: for operation in move.product_id.rma_customer_operation_id:
operation.in_route_id = False operation.in_route_id = False
move.product_id.rma_customer_operation_id = False move.product_id.rma_customer_operation_id = False
@@ -158,14 +148,10 @@ class TestRma(common.TransactionCase):
if dropship: if dropship:
data.update(customer_to_supplier=dropship, data.update(customer_to_supplier=dropship,
supplier_address_id=supplier_address_id.id) supplier_address_id=supplier_address_id.id)
data['partner_id'] = move.partner_id.id cls.line = cls.rma_line.create(data)
data['rma_id'] = rma_id.id
if type == 'supplier':
self.rma_line = self.rma_line.with_context(supplier=True)
self.line = self.rma_line.create(data)
# approve the RMA Line # approve the RMA Line
self.rma_line.action_rma_to_approve() cls.line.action_rma_to_approve()
self.line.action_rma_approve() cls.line.action_rma_approve()
rma_id._get_default_type() rma_id._get_default_type()
rma_id._compute_in_shipment_count() rma_id._compute_in_shipment_count()
rma_id._compute_out_shipment_count() rma_id._compute_out_shipment_count()
@@ -178,19 +164,18 @@ class TestRma(common.TransactionCase):
rma_id.partner_id.action_open_partner_rma() rma_id.partner_id.action_open_partner_rma()
rma_id.partner_id._compute_rma_line_count() rma_id.partner_id._compute_rma_line_count()
# approve the RMA # approve the RMA
for line in rma_id.rma_line_ids: # rma_id.action_rma_to_approve()
line.action_rma_to_approve() # rma_id.action_rma_approve()
line.action_rma_approve()
return rma_id return rma_id
def _prepare_move(self, product, qty, src, dest, picking_in): @classmethod
def _prepare_move(cls, product, qty, src, dest, picking_in):
res = { res = {
'partner_id': self.partner_id.id, 'partner_id': cls.partner_id.id,
'product_id': product.id, 'product_id': product.id,
'name': product.partner_ref, 'name': product.partner_ref,
'state': 'confirmed', 'state': 'confirmed',
'product_uom': self.product_uom_id.id or product.uom_id.id, 'product_uom': cls.product_uom_id.id or product.uom_id.id,
'product_uom_qty': qty, 'product_uom_qty': qty,
'origin': 'Test RMA', 'origin': 'Test RMA',
'location_id': src.id, 'location_id': src.id,
@@ -199,23 +184,20 @@ class TestRma(common.TransactionCase):
} }
return res return res
def test_rma_order_line(self): def test_01_rma_order_line(self):
partner2 = self.env.ref('base.res_partner_2') picking_in = self._create_picking(self.env.ref('base.res_partner_2'))
picking_in = self._create_picking(partner2)
moves_1 = [] moves_1 = []
move_values = self._prepare_move(self.product_1, 3, move_values = self._prepare_move(self.product_1, 3,
self.stock_location, self.stock_location,
self.customer_location, picking_in) self.customer_location, picking_in)
moves_1.append(self.env['stock.move'].create(move_values)) moves_1.append(self.env['stock.move'].create(move_values))
wizard_1 = self.rma_add_stock_move.new( wizard_1 = self.rma_add_stock_move.with_context(
{'supplier': True, {'supplier': True,
'stock_move_id': [(6, 0, [m.id for m in moves_1])], 'stock_move_id': [(6, 0, [m.id for m in moves_1])],
'active_ids': self.rma_customer_id.id, 'active_ids': self.rma_customer_id.id,
'active_model': 'rma.order', 'active_model': 'rma.order',
'partner_id': self.partner_id.id,
'move_ids': [(6, 0, [m.id for m in moves_1])]
} }
) ).create({'move_ids': [(6, 0, [m.id for m in moves_1])]})
wizard_1.add_lines() wizard_1.add_lines()
for line in self.rma_customer_id.rma_line_ids: for line in self.rma_customer_id.rma_line_ids:
@@ -226,11 +208,26 @@ class TestRma(common.TransactionCase):
})._default_delivery_address() })._default_delivery_address()
line._compute_in_shipment_count() line._compute_in_shipment_count()
line._compute_out_shipment_count() line._compute_out_shipment_count()
line._compute_procurement_count()
data = {'reference_move_id': line.reference_move_id.id} data = {'reference_move_id': line.reference_move_id.id}
new_line = self.rma_line.new(data) new_line = self.rma_line.new(data)
new_line._onchange_reference_move_id() new_line._onchange_reference_move_id()
# check assert if call reference_move_id onchange
self.assertEquals(new_line.product_id,
line.reference_move_id.product_id)
self.assertEquals(new_line.product_qty,
line.reference_move_id.product_uom_qty)
self.assertEquals(new_line.location_id.location_id,
line.reference_move_id.location_id)
self.assertEquals(new_line.origin,
line.reference_move_id.picking_id.name)
self.assertEquals(new_line.delivery_address_id,
line.reference_move_id.picking_partner_id)
self.assertEquals(new_line.qty_to_receive,
line.reference_move_id.product_uom_qty)
line.action_rma_to_approve() line.action_rma_to_approve()
line.action_rma_draft() line.action_rma_draft()
line.action_rma_done() line.action_rma_done()
@@ -243,6 +240,10 @@ class TestRma(common.TransactionCase):
new_line = self.rma_line.new(data) new_line = self.rma_line.new(data)
new_line._onchange_operation_id() new_line._onchange_operation_id()
# check assert if call operation_id onchange
self.assertEquals(new_line.operation_id.receipt_policy,
line.receipt_policy)
data = {'customer_to_supplier': line.customer_to_supplier} data = {'customer_to_supplier': line.customer_to_supplier}
new_line = self.rma_line.new(data) new_line = self.rma_line.new(data)
new_line._onchange_receipt_policy() new_line._onchange_receipt_policy()
@@ -253,31 +254,28 @@ class TestRma(common.TransactionCase):
line.action_view_in_shipments() line.action_view_in_shipments()
line.action_view_out_shipments() line.action_view_out_shipments()
line.action_view_procurements()
self.rma_customer_id.action_view_supplier_lines() self.rma_customer_id.action_view_supplier_lines()
with self.assertRaises(ValidationError): with self.assertRaises(ValidationError):
line.rma_id.partner_id = partner2.id line.rma_id.partner_id = self.partner_id.id
self.rma_customer_id.rma_line_ids[0].\ self.rma_customer_id.rma_line_ids[0].\
partner_id = partner2.id partner_id = self.partner_id.id
self.rma_customer_id.action_view_supplier_lines() self.rma_customer_id.action_view_supplier_lines()
def test_customer_rma(self): def test_02_customer_rma(self):
wizard = self.rma_make_picking.with_context({ wizard = self.rma_make_picking.with_context({
'active_ids': self.rma_customer_id.rma_line_ids.ids, 'active_ids': self.rma_customer_id.rma_line_ids.ids,
'active_model': 'rma.order.line', 'active_model': 'rma.order.line',
'picking_type': 'incoming', 'picking_type': 'incoming',
'active_id': 1 'active_id': 1
}).create({}) }).create({})
wizard.with_context({ procurements = wizard._create_picking()
'active_ids': self.rma_customer_id.rma_line_ids.ids, group_ids = set([proc.group_id.id for proc in procurements if
'active_model': 'rma.order.line', proc.group_id])
'picking_type': 'incoming', domain = [('group_id', 'in', list(group_ids))]
'active_id': 1 picking = self.stockpicking.search(domain)
}).default_get({}) self.assertEquals(len(picking), 1,
wizard._create_picking() "Incorrect number of pickings created")
res = self.rma_customer_id.rma_line_ids.action_view_in_shipments()
self.assertTrue('res_id' in res,
"Incorrect number of pickings created")
picking = self.env['stock.picking'].browse(res['res_id'])
moves = picking.move_lines moves = picking.move_lines
self.assertEquals(len(moves), 3, self.assertEquals(len(moves), 3,
"Incorrect number of moves created") "Incorrect number of moves created")
@@ -285,37 +283,30 @@ class TestRma(common.TransactionCase):
# common qtys for all products # common qtys for all products
self.assertEquals(line.qty_received, 0, self.assertEquals(line.qty_received, 0,
"Wrong qty received") "Wrong qty received")
self.assertEquals(line.qty_to_deliver, 0,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 0, self.assertEquals(line.qty_outgoing, 0,
"Wrong qty outgoing") "Wrong qty outgoing")
self.assertEquals(line.qty_delivered, 0, self.assertEquals(line.qty_delivered, 0,
"Wrong qty delivered") "Wrong qty delivered")
# product specific # product specific
if line.product_id == self.product_1: if line.product_id == self.product_1:
self.assertEquals(line.qty_to_deliver, 0,
"Wrong qty to deliver")
self.assertEquals(line.qty_to_receive, 3, self.assertEquals(line.qty_to_receive, 3,
"Wrong qty to receive") "Wrong qty to receive")
self.assertEquals(line.qty_incoming, 3, self.assertEquals(line.qty_incoming, 3,
"Wrong qty incoming") "Wrong qty incoming")
if line.product_id == self.product_2: if line.product_id == self.product_2:
self.assertEquals(line.qty_to_deliver, 0,
"Wrong qty to deliver")
self.assertEquals(line.qty_to_receive, 5, self.assertEquals(line.qty_to_receive, 5,
"Wrong qty to receive") "Wrong qty to receive")
self.assertEquals(line.qty_incoming, 5, self.assertEquals(line.qty_incoming, 5,
"Wrong qty incoming") "Wrong qty incoming")
if line.product_id == self.product_3: if line.product_id == self.product_3:
self.assertEquals(line.qty_to_deliver, 0,
"Wrong qty to deliver")
self.assertEquals(line.qty_to_receive, 2, self.assertEquals(line.qty_to_receive, 2,
"Wrong qty to receive") "Wrong qty to receive")
self.assertEquals(line.qty_incoming, 2, self.assertEquals(line.qty_incoming, 2,
"Wrong qty incoming") "Wrong qty incoming")
picking.action_confirm()
picking.action_assign() picking.action_assign()
for line in picking.move_line_ids: picking.do_transfer()
line.qty_done = line.product_uom_qty
picking.action_done()
for line in self.rma_customer_id.rma_line_ids: for line in self.rma_customer_id.rma_line_ids:
self.assertEquals(line.qty_to_receive, 0, self.assertEquals(line.qty_to_receive, 0,
"Wrong qty to_receive") "Wrong qty to_receive")
@@ -328,12 +319,18 @@ class TestRma(common.TransactionCase):
if line.product_id == self.product_1: if line.product_id == self.product_1:
self.assertEquals(line.qty_received, 3, self.assertEquals(line.qty_received, 3,
"Wrong qty received") "Wrong qty received")
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to_deliver")
if line.product_id == self.product_2: if line.product_id == self.product_2:
self.assertEquals(line.qty_received, 5, self.assertEquals(line.qty_received, 5,
"Wrong qty received") "Wrong qty received")
self.assertEquals(line.qty_to_deliver, 5,
"Wrong qty to_deliver")
if line.product_id == self.product_3: if line.product_id == self.product_3:
self.assertEquals(line.qty_received, 2, self.assertEquals(line.qty_received, 2,
"Wrong qty received") "Wrong qty received")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to_deliver")
wizard = self.rma_make_picking.with_context({ wizard = self.rma_make_picking.with_context({
'active_id': 1, 'active_id': 1,
@@ -341,15 +338,22 @@ class TestRma(common.TransactionCase):
'active_model': 'rma.order.line', 'active_model': 'rma.order.line',
'picking_type': 'outgoing', 'picking_type': 'outgoing',
}).create({}) }).create({})
wizard._create_picking() procurements = wizard._create_picking()
res = self.rma_customer_id.rma_line_ids.action_view_out_shipments() group_ids = set([proc.group_id.id for proc in procurements if
self.assertTrue('res_id' in res, proc.group_id])
"Incorrect number of pickings created") domain = [('group_id', 'in', list(group_ids))]
picking = self.env['stock.picking'].browse(res['res_id']) pickings = self.stockpicking.search(domain)
moves = picking.move_lines self.assertEquals(len(pickings), 2,
"Incorrect number of pickings created")
picking_out = pickings[1]
moves = picking_out.move_lines
self.assertEquals(len(moves), 3, self.assertEquals(len(moves), 3,
"Incorrect number of moves created") "Incorrect number of moves created")
for line in self.rma_customer_id.rma_line_ids: for line in self.rma_customer_id.rma_line_ids:
self.assertEquals(line.qty_to_receive, 0,
"Wrong qty to receive")
self.assertEquals(line.qty_incoming, 0,
"Wrong qty incoming")
self.assertEquals(line.qty_delivered, 0, self.assertEquals(line.qty_delivered, 0,
"Wrong qty delivered") "Wrong qty delivered")
if line.product_id == self.product_1: if line.product_id == self.product_1:
@@ -357,35 +361,272 @@ class TestRma(common.TransactionCase):
"Wrong qty to deliver") "Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 3, self.assertEquals(line.qty_outgoing, 3,
"Wrong qty outgoing") "Wrong qty outgoing")
self.assertEquals(line.qty_received, 3,
"Wrong qty received")
if line.product_id == self.product_2: if line.product_id == self.product_2:
self.assertEquals(line.qty_received, 5,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 5, self.assertEquals(line.qty_to_deliver, 5,
"Wrong qty to deliver") "Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 5, self.assertEquals(line.qty_outgoing, 5,
"Wrong qty outgoing") "Wrong qty outgoing")
if line.product_id == self.product_3: if line.product_id == self.product_3:
self.assertEquals(line.qty_received, 2,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 2, self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to deliver") "Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 2, self.assertEquals(line.qty_outgoing, 2,
"Wrong qty outgoing") "Wrong qty outgoing")
picking.action_confirm() picking_out.action_assign()
picking.action_assign() picking_out.do_transfer()
for line in picking.move_line_ids: for line in self.rma_customer_id.rma_line_ids:
line.qty_done = line.product_uom_qty self.assertEquals(line.qty_to_receive, 0,
picking.action_done() "Wrong qty to receive")
for line in self.rma_customer_id.rma_line_ids[0]: self.assertEquals(line.qty_incoming, 0,
"Wrong qty incoming")
self.assertEquals(line.qty_to_deliver, 0, self.assertEquals(line.qty_to_deliver, 0,
"Wrong qty to deliver") "Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 0, self.assertEquals(line.qty_outgoing, 0,
"Wrong qty outgoing") "Wrong qty outgoing")
if line.product_id == self.product_1: if line.product_id == self.product_1:
self.assertEquals(line.qty_received, 3,
"Wrong qty received")
self.assertEquals(line.qty_delivered, 3, self.assertEquals(line.qty_delivered, 3,
"Wrong qty delivered") "Wrong qty delivered")
if line.product_id == self.product_2: if line.product_id == self.product_2:
self.assertEquals(line.qty_received, 5,
"Wrong qty received")
self.assertEquals(line.qty_delivered, 5, self.assertEquals(line.qty_delivered, 5,
"Wrong qty delivered") "Wrong qty delivered")
if line.product_id == self.product_3: if line.product_id == self.product_3:
self.assertEquals(line.qty_received, 2,
"Wrong qty received")
self.assertEquals(line.qty_delivered, 2, self.assertEquals(line.qty_delivered, 2,
"Wrong qty delivered") "Wrong qty delivered")
self.line.action_rma_done() self.line.action_rma_done()
self.assertEquals(self.line.state, 'done', self.assertEquals(self.line.state, 'done',
"Wrong State") "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()
# DROPSHIP
def test_03_dropship(self):
wizard = self.make_supplier_rma.with_context({
'active_ids': self.rma_droship_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'active_id': 1
}).create({})
res = wizard.make_supplier_rma()
supplier_rma = self.rma.browse(res['res_id'])
for line in supplier_rma.rma_line_ids:
line.action_rma_to_approve()
line.action_rma_approve()
wizard = self.rma_make_picking.with_context({
'active_id': 1,
'active_ids': supplier_rma.rma_line_ids.ids,
'active_model': 'rma.order.line',
'picking_type': 'incoming',
}).create({})
procurements = wizard._create_picking()
group_ids = set([proc.group_id.id for proc in procurements if
proc.group_id])
domain = [('group_id', 'in', list(group_ids))]
picking = self.stockpicking.search(domain)
self.assertEquals(len(picking), 1,
"Incorrect number of pickings created")
moves = picking.move_lines
self.assertEquals(len(moves), 3,
"Incorrect number of moves created")
for line in supplier_rma.rma_line_ids:
# common qtys for all products
self.assertEquals(line.qty_received, 0,
"Wrong qty received")
self.assertEquals(line.qty_outgoing, 0,
"Wrong qty incoming")
self.assertEquals(line.qty_delivered, 0,
"Wrong qty delivered")
# product specific
if line.product_id == self.product_1:
self.assertEquals(line.qty_to_receive, 3,
"Wrong qty to receive")
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to deliver")
self.assertEquals(line.qty_incoming, 3,
"Wrong qty outgoing")
if line.product_id == self.product_2:
self.assertEquals(line.qty_to_receive, 5,
"Wrong qty to receive")
self.assertEquals(line.qty_to_deliver, 5,
"Wrong qty to deliver")
self.assertEquals(line.qty_incoming, 5,
"Wrong qty outgoing")
if line.product_id == self.product_3:
self.assertEquals(line.qty_to_receive, 2,
"Wrong qty to receive")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to deliver")
self.assertEquals(line.qty_incoming, 2,
"Wrong qty outgoing")
for line in self.rma_droship_id.rma_line_ids:
if line.product_id == self.product_1:
self.assertEquals(line.qty_to_supplier_rma, 0,
"Wrong qty to supplier rma")
self.assertEquals(line.qty_in_supplier_rma, 3,
"Wrong qty in supplier rma")
if line.product_id == self.product_2:
self.assertEquals(line.qty_to_supplier_rma, 0,
"Wrong qty to supplier rma")
self.assertEquals(line.qty_in_supplier_rma, 5,
"Wrong qty in supplier rma")
if line.product_id == self.product_3:
self.assertEquals(line.qty_to_supplier_rma, 0,
"Wrong qty to supplier rma")
self.assertEquals(line.qty_in_supplier_rma, 2,
"Wrong qty in supplier rma")
for line in self.rma_droship_id.rma_line_ids:
line.action_rma_done()
self.assertEquals(line.state, 'done',
"Wrong State")
# Supplier RMA
def test_04_supplier_rma(self):
wizard = self.rma_make_picking.with_context({
'active_ids': self.rma_supplier_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'picking_type': 'outgoing',
'active_id': 1
}).create({})
procurements = wizard._create_picking()
group_ids = set([proc.group_id.id for proc in procurements if
proc.group_id])
domain = [('group_id', 'in', list(group_ids))]
picking = self.stockpicking.search(domain)
self.assertEquals(len(picking), 1,
"Incorrect number of pickings created")
moves = picking.move_lines
self.assertEquals(len(moves), 3,
"Incorrect number of moves created")
for line in self.rma_supplier_id.rma_line_ids:
# common qtys for all products
self.assertEquals(line.qty_received, 0,
"Wrong qty received")
self.assertEquals(line.qty_incoming, 0,
"Wrong qty incoming")
self.assertEquals(line.qty_delivered, 0,
"Wrong qty delivered")
# product specific
if line.product_id == self.product_1:
self.assertEquals(line.qty_to_receive, 3,
"Wrong qty to receive")
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 3,
"Wrong qty outgoing")
if line.product_id == self.product_2:
self.assertEquals(line.qty_to_receive, 5,
"Wrong qty to receive")
self.assertEquals(line.qty_to_deliver, 5,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 5,
"Wrong qty outgoing")
if line.product_id == self.product_3:
self.assertEquals(line.qty_to_receive, 2,
"Wrong qty to receive")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 2,
"Wrong qty outgoing")
picking.action_assign()
picking.do_transfer()
for line in self.rma_supplier_id.rma_line_ids:
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_delivered, 3,
"Wrong qty delivered")
self.assertEquals(line.qty_to_receive, 3,
"Wrong qty to receive")
if line.product_id == self.product_2:
self.assertEquals(line.qty_outgoing, 5,
"Wrong qty delivered")
self.assertEquals(line.qty_to_receive, 5,
"Wrong qty to receive")
if line.product_id == self.product_3:
self.assertEquals(line.qty_outgoing, 2,
"Wrong qty delivered")
self.assertEquals(line.qty_to_receive, 2,
"Wrong qty to receive")
wizard = self.rma_make_picking.with_context({
'active_id': 1,
'active_ids': self.rma_supplier_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'picking_type': 'incoming',
}).create({})
procurements = wizard._create_picking()
group_ids = set([proc.group_id.id for proc in procurements if
proc.group_id])
domain = [('group_id', 'in', list(group_ids))]
pickings = self.stockpicking.search(domain)
self.assertEquals(len(pickings), 3,
"Incorrect number of pickings created")
picking_out = pickings[0]
moves = picking_out.move_lines
self.assertEquals(len(moves), 2,
"Incorrect number of moves created")
for line in self.rma_supplier_id.rma_line_ids:
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, 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_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_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[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, 3,
"Wrong qty outgoing")
if line.product_id == self.product_1:
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, 0,
"Wrong qty received")
self.assertEquals(line.qty_delivered, 5,
"Wrong qty delivered")
if line.product_id == self.product_3:
self.assertEquals(line.qty_received, 2,
"Wrong qty received")
self.assertEquals(line.qty_delivered, 2,
"Wrong qty delivered")
for line in self.rma_supplier_id.rma_line_ids:
line.action_rma_done()
self.assertEquals(line.state, 'done',
"Wrong State")

View File

@@ -1,110 +0,0 @@
# Copyright (C) 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from . import test_rma
class TestRmaDropship(test_rma.TestRma):
def setUp(self):
super(TestRmaDropship, self).setUp()
rma_operation_ds_replace = self.env.ref(
'rma.rma_operation_ds_replace')
self.rma_operation_ds_replace_supplier = self.env.ref(
'rma.rma_operation_ds_replace_supplier')
self.product_id.write(
{'rma_customer_operation_id': rma_operation_ds_replace.id,
'rma_supplier_operation_id':
self.rma_operation_ds_replace_supplier.id})
self.product_1.write(
{'rma_customer_operation_id': rma_operation_ds_replace.id,
'rma_supplier_operation_id':
self.rma_operation_ds_replace_supplier.id})
self.product_2.write(
{'rma_customer_operation_id': rma_operation_ds_replace.id,
'rma_supplier_operation_id':
self.rma_operation_ds_replace_supplier.id})
self.product_3.write(
{'rma_customer_operation_id': rma_operation_ds_replace.id,
'rma_supplier_operation_id':
self.rma_operation_ds_replace_supplier.id})
products2move = [(self.product_1, 3), (self.product_2, 5),
(self.product_3, 2)]
self.rma_droship_id = self._create_rma_from_move(
products2move, 'customer', self.env.ref('base.res_partner_2'),
dropship=True,
supplier_address_id=self.env.ref('base.res_partner_3'))
def test_dropship(self):
wizard = self.make_supplier_rma.with_context({
'active_ids': self.rma_droship_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'active_id': 1
}).create({})
res = wizard.make_supplier_rma()
supplier_rma = self.rma.browse(res['res_id'])
for line in supplier_rma.rma_line_ids:
line.delivery_address_id = self.env.ref('base.res_partner_2')
line.operation_id = self.rma_operation_ds_replace_supplier
line._onchange_operation_id()
line.action_rma_to_approve()
line.action_rma_approve()
wizard = self.rma_make_picking.with_context({
'active_id': 1,
'active_ids': supplier_rma.rma_line_ids.ids,
'active_model': 'rma.order.line',
'picking_type': 'incoming',
}).create({})
wizard._create_picking()
res = supplier_rma.rma_line_ids.action_view_in_shipments()
self.assertTrue('res_id' in res,
"Incorrect number of pickings created")
picking = self.env['stock.picking'].browse(res['res_id'])
moves = picking.move_lines
self.assertEquals(len(moves), 3,
"Incorrect number of moves created")
for line in supplier_rma.rma_line_ids:
# product specific
if line.product_id == self.product_1:
self.assertEquals(line.qty_to_receive, 3,
"Wrong qty to receive")
self.assertEquals(line.qty_received, 0,
"Wrong qty receive")
self.assertEquals(line.qty_outgoing, 0,
"Wrong qty outgoing")
if line.product_id == self.product_2:
self.assertEquals(line.qty_to_receive, 5,
"Wrong qty to receive")
self.assertEquals(line.qty_delivered, 0,
"Wrong qty deliver")
self.assertEquals(line.qty_outgoing, 0,
"Wrong qty outgoing")
if line.product_id == self.product_3:
self.assertEquals(line.qty_to_receive, 2,
"Wrong qty to receive")
self.assertEquals(line.qty_delivered, 0,
"Wrong qty deliver")
self.assertEquals(line.qty_outgoing, 0,
"Wrong qty outgoing")
for line in self.rma_droship_id.rma_line_ids[0]:
if line.product_id == self.product_1:
self.assertEquals(line.qty_to_supplier_rma, 0,
"Wrong qty to supplier rma")
self.assertEquals(line.qty_in_supplier_rma, 3,
"Wrong qty in supplier rma")
if line.product_id == self.product_2:
self.assertEquals(line.qty_to_supplier_rma, 0,
"Wrong qty to supplier rma")
self.assertEquals(line.qty_in_supplier_rma, 5,
"Wrong qty in supplier rma")
if line.product_id == self.product_3:
self.assertEquals(line.qty_to_supplier_rma, 0,
"Wrong qty to supplier rma")
self.assertEquals(line.qty_in_supplier_rma, 2,
"Wrong qty in supplier rma")
for line in self.rma_droship_id.rma_line_ids:
line.action_rma_done()
self.assertEquals(line.state, 'done',
"Wrong State")

View File

@@ -1,144 +0,0 @@
# Copyright (C) 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from . import test_rma
class TestSupplierRma(test_rma.TestRma):
def setUp(self):
super(TestSupplierRma, self).setUp()
self.rma_operation_supplier_replace = self.env.ref(
'rma.rma_operation_supplier_replace')
products2move = [(self.product_1, 3), (self.product_2, 5),
(self.product_3, 2)]
self.rma_supplier_id = self._create_rma_from_move(
products2move, 'supplier', self.env.ref('base.res_partner_1'),
dropship=False)
def test_supplier_rma(self):
for line in self.rma_supplier_id.rma_line_ids:
line.operation_id = self.rma_operation_supplier_replace
line._onchange_operation_id()
line.action_rma_to_approve()
line.action_rma_approve()
wizard = self.rma_make_picking.with_context({
'active_ids': self.rma_supplier_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'picking_type': 'outgoing',
'active_id': 1
}).create({})
wizard._create_picking()
res = self.rma_supplier_id.rma_line_ids.action_view_out_shipments()
self.assertTrue('res_id' in res,
"Incorrect number of pickings created")
picking = self.env['stock.picking'].browse(res['res_id'])
moves = picking.move_lines
self.assertEquals(len(moves), 3,
"Incorrect number of moves created")
for line in self.rma_supplier_id.rma_line_ids:
# common qtys for all products
self.assertEquals(line.qty_received, 0,
"Wrong qty received")
self.assertEquals(line.qty_incoming, 0,
"Wrong qty incoming")
self.assertEquals(line.qty_delivered, 0,
"Wrong qty delivered")
# product specific
if line.product_id == self.product_1:
self.assertEquals(line.qty_to_receive, 3,
"Wrong qty to receive")
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 3,
"Wrong qty outgoing")
if line.product_id == self.product_2:
self.assertEquals(line.qty_to_receive, 5,
"Wrong qty to receive")
self.assertEquals(line.qty_to_deliver, 5,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 5,
"Wrong qty outgoing")
if line.product_id == self.product_3:
self.assertEquals(line.qty_to_receive, 2,
"Wrong qty to receive")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 2,
"Wrong qty outgoing")
picking.force_assign()
for line in picking.move_lines:
line.quantity_done = line.product_uom_qty
picking.button_validate()
for line in self.rma_supplier_id.rma_line_ids:
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_delivered, 3,
"Wrong qty delivered")
self.assertEquals(line.qty_to_receive, 3,
"Wrong qty to receive")
if line.product_id == self.product_2:
self.assertEquals(line.qty_delivered, 5,
"Wrong qty delivered")
self.assertEquals(line.qty_to_receive, 5,
"Wrong qty to receive")
if line.product_id == self.product_3:
self.assertEquals(line.qty_delivered, 2,
"Wrong qty delivered")
self.assertEquals(line.qty_to_receive, 2,
"Wrong qty to receive")
wizard = self.rma_make_picking.with_context({
'active_id': 1,
'active_ids': self.rma_supplier_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'picking_type': 'incoming',
}).create({})
wizard._create_picking()
res = self.rma_supplier_id.rma_line_ids.action_view_in_shipments()
self.assertTrue('res_id' in res,
"Incorrect number of pickings created")
picking = self.env['stock.picking'].browse(res['res_id'])
moves = picking.move_lines
self.assertEquals(len(moves), 3,
"Incorrect number of moves created")
for line in self.rma_supplier_id.rma_line_ids:
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,
"Wrong qty incoming")
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")
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")
picking.action_assign()
for line in picking.move_line_ids:
line.qty_done = line.product_uom_qty
picking.action_done()
for line in self.rma_supplier_id.rma_line_ids[0]:
self.assertEquals(line.qty_incoming, 0,
"Wrong qty incoming")
if line.product_id == self.product_1:
self.assertEquals(line.qty_received, 3,
"Wrong qty received")
if line.product_id == self.product_2:
self.assertEquals(line.qty_received, 5,
"Wrong qty received")
if line.product_id == self.product_3:
self.assertEquals(line.qty_received, 2,
"Wrong qty received")
for line in self.rma_supplier_id.rma_line_ids:
line.action_rma_done()
self.assertEquals(line.state, 'done',
"Wrong State")