[IMP] Improved Unit Test Case and Fixed Travis

This commit is contained in:
Nikul Chaudhary
2017-11-10 12:48:55 +05:30
committed by Aarón Henríquez
parent d83e759f2a
commit 622250eef6
41 changed files with 3397 additions and 63 deletions

View File

@@ -9,7 +9,7 @@
'category': 'RMA',
'summary': 'Introduces the return merchandise authorization (RMA) process '
'in odoo',
'author': "Eficent",
'author': "Eficent, Odoo Community Association (OCA)",
'website': 'http://www.github.com/OCA/rma',
'depends': ['stock', 'mail', 'procurement'],
'demo': ['demo/stock_demo.xml',

View File

@@ -171,7 +171,6 @@ class RmaOrder(models.Model):
res = self.env.ref('rma.view_rma_line_form', False)
else:
res = self.env.ref('rma.view_rma_line_supplier_form', False)
result['views'] = [(res and res.id or False, 'form')]
result['res_id'] = lines.id
return result
@@ -181,13 +180,14 @@ class RmaOrder(models.Model):
action = self.env.ref('rma.action_rma_supplier_lines')
result = action.read()[0]
lines = self.rma_line_ids
related_lines = [line.id for line in lines.supplier_rma_line_ids]
# choose the view_mode accordingly
if len(related_lines) != 1:
result['domain'] = "[('id', 'in', " + \
str(related_lines) + ")]"
elif len(related_lines) == 1:
res = self.env.ref('rma.view_rma_line_supplier_form', False)
result['views'] = [(res and res.id or False, 'form')]
result['res_id'] = related_lines[0]
for line_id in lines:
related_lines = [line.id for line in line_id.supplier_rma_line_ids]
# choose the view_mode accordingly
if len(related_lines) != 1:
result['domain'] = "[('id', 'in', " + \
str(related_lines) + ")]"
elif len(related_lines) == 1:
res = self.env.ref('rma.view_rma_line_supplier_form', False)
result['views'] = [(res and res.id or False, 'form')]
result['res_id'] = related_lines[0]
return result

View File

@@ -372,21 +372,21 @@ class RmaOrderLine(models.Model):
operation = self.env['rma.operation'].search(
[('type', '=', self.type)], limit=1)
if not operation:
raise ValidationError("Please define an operation first.")
raise ValidationError(_("Please define an operation first."))
if not operation.in_route_id or not operation.out_route_id:
route = self.env['stock.location.route'].search(
[('rma_selectable', '=', True)], limit=1)
if not route:
raise ValidationError("Please define an RMA route.")
raise ValidationError(_("Please define an RMA route."))
if not operation.in_warehouse_id or not operation.out_warehouse_id:
warehouse = self.env['stock.warehouse'].search(
[('company_id', '=', self.company_id.id),
('lot_rma_id', '!=', False)], limit=1)
if not warehouse:
raise ValidationError(
"Please define a warehouse with a default RMA location.")
raise ValidationError(_(
"Please define a warehouse with a default RMA location."))
data = {
'product_id': sm.product_id.id,

View File

@@ -3,6 +3,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo.tests import common
from odoo.exceptions import ValidationError
class TestRma(common.TransactionCase):

View File

@@ -24,8 +24,9 @@ class TestRmaDropship(test_rma.TestRma):
}).create({})
res = wizard.make_supplier_rma()
supplier_rma = self.rma.browse(res['res_id'])
supplier_rma.action_rma_to_approve()
supplier_rma.action_rma_approve()
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,
@@ -89,3 +90,7 @@ class TestRmaDropship(test_rma.TestRma):
"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

@@ -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 TestSupplierRma(test_rma.TestRma):

View File

@@ -2,7 +2,7 @@
<odoo>
<data>
<record id="procurement_form_view" model="ir.ui.view">
<record id="procurement_form_view_0" model="ir.ui.view">
<field name="name">procurement.order.form</field>
<field name="model">procurement.order</field>
<field name="inherit_id"

View File

@@ -86,7 +86,7 @@ class RmaAddStockMove(models.TransientModel):
'location_id': (operation.location_id.id or
operation.in_warehouse_id.lot_rma_id.id or
warehouse.lot_rma_id.id)
}
}
return data
@api.model

View File

@@ -83,7 +83,7 @@ class RmaMakePicking(models.TransientModel):
elif item.line_id.partner_id:
delivery_address = item.line_id.partner_id
else:
raise ValidationError('Unknown delivery address')
raise ValidationError(_('Unknown delivery address'))
return delivery_address
@api.model
@@ -111,9 +111,9 @@ class RmaMakePicking(models.TransientModel):
warehouse = line.out_warehouse_id
route = line.out_route_id
if not route:
raise ValidationError("No route specified")
raise ValidationError(_("No route specified"))
if not warehouse:
raise ValidationError("No warehouse specified")
raise ValidationError(_("No warehouse specified"))
procurement_data = {
'name': line.rma_id and line.rma_id.name or line.name,
'group_id': group.id,

View File

@@ -110,7 +110,7 @@ class RmaLineMakeSupplierRma(models.TransientModel):
'location_id': (operation.location_id.id or
operation.in_warehouse_id.lot_rma_id.id or
warehouse.lot_rma_id.id)
}
}
return data
@api.multi

View File

@@ -8,7 +8,7 @@
'license': 'LGPL-3',
'category': 'RMA',
'summary': 'Integrates RMA with Invoice Processing',
'author': "Eficent",
'author': "Eficent, Odoo Community Association (OCA)",
'website': 'http://www.github.com/OCA/rma',
'depends': ['account', 'rma'],
'demo': ['demo/rma_operation.xml'],

View File

@@ -8,7 +8,7 @@ from odoo import api, fields, models
class AccountInvoice(models.Model):
_inherit = "account.invoice"
@api.one
@api.depends('invoice_line_ids.rma_line_ids')
def _compute_rma_count(self):
for inv in self:
rmas = self.mapped('invoice_line_ids.rma_line_ids')

View File

@@ -31,11 +31,13 @@ class RmaOrder(models.Model):
def _prepare_rma_line_from_inv_line(self, line):
if self.type == 'customer':
operation = self.product_id.rma_customer_operation_id or \
self.product_id.categ_id.rma_customer_operation_id
operation =\
self.rma_line_ids.product_id.rma_customer_operation_id or \
self.rma_line_ids.product_id.categ_id.rma_customer_operation_id
else:
operation = self.product_id.rma_supplier_operation_id or \
self.product_id.categ_id.rma_supplier_operation_id
operation =\
self.rma_line_ids.product_id.rma_supplier_operation_id or \
self.rma_line_ids.product_id.categ_id.rma_supplier_operation_id
data = {
'invoice_line_id': line.id,
'product_id': line.product_id.id,
@@ -46,7 +48,7 @@ class RmaOrder(models.Model):
'product_qty': line.quantity,
'price_unit': line.invoice_id.currency_id.compute(
line.price_unit, line.currency_id, round=False),
'rma_id': self._origin.id
'rma_id': self.id
}
return data

View File

@@ -25,16 +25,16 @@ class RmaOrderLine(models.Model):
lambda i: i.invoice_id.state in ('open', 'paid')).mapped(
'quantity'))
@api.one
@api.depends('refund_line_ids', 'refund_line_ids.invoice_id.state',
'refund_policy', 'move_ids', 'move_ids.state', 'type')
def _compute_qty_to_refund(self):
qty = 0.0
if self.refund_policy == 'ordered':
qty = self.product_qty - self.qty_refunded
elif self.refund_policy == 'received':
qty = self.qty_received - self.qty_refunded
self.qty_to_refund = qty
for res in self:
if res.refund_policy == 'ordered':
qty = res.product_qty - res.qty_refunded
elif res.refund_policy == 'received':
qty = res.qty_received - res.qty_refunded
res.qty_to_refund = qty
@api.multi
def _compute_refund_count(self):
@@ -94,21 +94,21 @@ class RmaOrderLine(models.Model):
operation = self.env['rma.operation'].search(
[('type', '=', self.type)], limit=1)
if not operation:
raise ValidationError("Please define an operation first")
raise ValidationError(_("Please define an operation first"))
if not operation.in_route_id or not operation.out_route_id:
route = self.env['stock.location.route'].search(
[('rma_selectable', '=', True)], limit=1)
if not route:
raise ValidationError("Please define an rma route")
raise ValidationError(_("Please define an rma route"))
if not operation.in_warehouse_id or not operation.out_warehouse_id:
warehouse = self.env['stock.warehouse'].search(
[('company_id', '=', self.company_id.id),
('lot_rma_id', '!=', False)], limit=1)
if not warehouse:
raise ValidationError("Please define a warehouse with a"
" default rma location")
raise ValidationError(_("Please define a warehouse with a"
" default rma location"))
data = {
'product_id': line.product_id.id,
'origin': line.invoice_id.number,
@@ -189,7 +189,6 @@ class RmaOrderLine(models.Model):
result['views'] = [(res and res.id or False, 'form')]
result['view_id'] = res and res.id or False
result['res_id'] = self.invoice_line_id.invoice_id.id
return result
@api.multi

View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 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
from . import test_supplier_rma
from . import test_rma_dropship

View File

@@ -0,0 +1,395 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from openerp.tests import common
from openerp import fields
class TestRma(common.TransactionCase):
""" Test the routes and the quantities """
def setUp(self):
super(TestRma, self).setUp()
self.rma_make_picking = self.env['rma_make_picking.wizard']
self.make_supplier_rma = self.env["rma.order.line.make.supplier.rma"]
self.rma_add_stock_move = self.env['rma_add_stock_move']
self.stockpicking = self.env['stock.picking']
self.rma = self.env['rma.order']
self.rma_line = self.env['rma.order.line']
self.rma_op = self.env['rma.operation']
self.rma_cust_replace_op_id = self.env.ref(
'rma.rma_operation_customer_replace')
self.rma_sup_replace_op_id = self.env.ref(
'rma.rma_operation_supplier_replace')
self.product_id = self.env.ref('product.product_product_4')
self.product_id.product_tmpl_id.categ_id.\
property_stock_account_input_categ_id =\
self.env.ref('account.data_account_type_receivable').id
self.product_id.product_tmpl_id.categ_id.\
property_stock_account_output_categ_id =\
self.env.ref('account.data_account_type_expenses').id
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.uom_unit = self.env.ref('product.product_uom_unit')
# assign an operation
self.product_1.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.product_2.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.product_3.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.partner_id = self.env.ref('base.res_partner_12')
self.stock_location = self.env.ref('stock.stock_location_stock')
self.stock_rma_location = self.env.ref('rma.location_rma')
self.customer_location = self.env.ref(
'stock.stock_location_customers')
self.supplier_location = self.env.ref(
'stock.stock_location_suppliers')
self.product_uom_id = self.env.ref('product.product_uom_unit')
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'),
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, 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, picking_in)
moves.append(self.env['stock.move'].create(move_values))
# Create the RMA from the stock_move
rma_id = self.rma.create(
{
'reference': '0001',
'type': type,
'partner_id': partner.id,
'company_id': self.env.ref('base.main_company').id
})
rma_id._compute_invoice_refund_count()
rma_id._compute_invoice_count()
data = {'add_invoice_id': self._create_invoice().id}
new_line = self.rma.new(data)
new_line.on_change_invoice()
rma_id.action_view_invoice_refund()
rma_id.action_view_invoice()
for move in moves:
if type == 'customer':
wizard = self.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'customer': True,
'active_ids': rma_id.id,
'active_model': 'rma.order',
}
).create({})
data = wizard._prepare_rma_line_from_stock_move(move)
else:
wizard = self.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'supplier': True,
'active_ids': rma_id.id,
'active_model': 'rma.order',
}
).create({})
data = wizard._prepare_rma_line_from_stock_move(move)
if dropship:
data.update(customer_to_supplier=dropship,
supplier_address_id=supplier_address_id.id)
self.line = self.rma_line.create(data)
# approve the RMA Line
self.line._compute_refund_count()
self.rma_line.action_rma_to_approve()
self.line.action_rma_approve()
self.line.action_view_invoice()
self.line.action_view_refunds()
# approve the RMA
# rma_id.action_rma_to_approve()
# rma_id.action_rma_approve()
return rma_id
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',
'product_uom': self.product_uom_id.id or product.uom_id.id,
'product_uom_qty': qty,
'origin': 'Test RMA',
'location_id': src.id,
'location_dest_id': dest.id,
'picking_id': picking_in.id
}
return res
def test_rma_refund(self):
self.rma_refund_item = self.env['rma.refund.item']
self.rma_refund = self.env['rma.refund']
self.product_id.income =\
self.env.ref('account.data_account_type_receivable').id
self.product_id.expense =\
self.env.ref('account.data_account_type_expenses').id
for line in self.rma_customer_id.rma_line_ids:
line.refund_policy = 'ordered'
refund = self.rma_refund.with_context({
'active_ids': self.rma_customer_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'active_id': 1
}).create({'description': 'Test Reason',
'date_invoice': fields.datetime.now()
})
self.rma_refund_item.create({
'line_id': self.rma_customer_id.rma_line_ids[0].id,
'rma_id': self.rma_customer_id.id,
'product_id': self.product_id.id,
'name': 'Test RMA Refund',
'product_qty': self.rma_customer_id.rma_line_ids[0].product_qty,
'wiz_id': refund.id
})
refund.invoice_refund()
data = {'invoice_line_id': self._create_invoice().invoice_line_ids.id}
new_line = self.rma_line.new(data)
new_line._onchange_invoice_line_id()
self.rma_customer_id.action_view_invoice_refund()
self.rma_customer_id.action_view_invoice()
def test_on_change_invoice_rma(self):
wizard = self.env['rma_add_invoice'].with_context({
'active_ids': self.rma_customer_id.ids,
'active_model': 'rma.order',
'active_id': self.rma_customer_id.id
}).create({'partner_id': self.partner_id.id,
'rma_id': self.rma_customer_id.id,
'invoice_line_ids':
[(6, 0, [self._create_invoice().invoice_line_ids.id])],
})
wizard.default_get([str(self._create_invoice().id),
str(self._create_invoice().invoice_line_ids.id),
str(self.partner_id.id)])
wizard.add_lines()
self.rma_customer_id.action_view_invoice_refund()
self.rma_customer_id.action_view_invoice()
self.rma_customer_id.rma_line_ids[0].\
invoice_id = self._create_invoice().id
self.rma_customer_id.action_view_invoice()
self.rma_customer_id.add_invoice_id = self._create_invoice().id
for line in self.rma_customer_id.rma_line_ids:
line.invoice_id.action_view_rma_supplier()
line.invoice_id.action_view_rma_customer()
def _create_invoice(self):
self.Account = self.env['account.account']
self.AccountInvoice = self.env['account.invoice']
self.AccountInvoiceLine = self.env['account.invoice.line']
self.account_receivable =\
self.env.ref('account.data_account_type_receivable')
self.account_expenses =\
self.env.ref('account.data_account_type_expenses')
invoice_account = self.Account.\
search([('user_type_id', '=', self.account_receivable.id)], limit=1
).id
invoice_line_account = self.Account.\
search([('user_type_id', '=', self.account_expenses.id)], limit=1
).id
invoice = self.AccountInvoice.create({
'partner_id': self.partner_id.id,
'account_id': invoice_account,
'type': 'in_invoice',
})
invoice_line = self.AccountInvoiceLine.create({
'product_id': self.product_1.id,
'quantity': 1.0,
'price_unit': 100.0,
'invoice_id': invoice.id,
'uom_id': 1,
'name': 'product that cost 100',
'account_id': invoice_line_account,
})
invoice._compute_rma_count()
invoice_line._compute_rma_count()
invoice.action_view_rma_customer()
invoice.action_view_rma_supplier()
return invoice
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({})
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_customer_id.rma_line_ids:
# 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_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()
picking.do_transfer()
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_outgoing, 0,
"Wrong qty outgoing")
self.assertEquals(line.qty_delivered, 0,
"Wrong qty delivered")
if line.product_id == self.product_1:
self.assertEquals(line.qty_received, 3,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to_deliver")
if line.product_id == self.product_2:
self.assertEquals(line.qty_received, 5,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 5,
"Wrong qty to_deliver")
if line.product_id == self.product_3:
self.assertEquals(line.qty_received, 2,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to_deliver")
wizard = self.rma_make_picking.with_context({
'active_id': 1,
'active_ids': self.rma_customer_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'picking_type': 'outgoing',
}).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), 2,
"Incorrect number of pickings created")
picking_out = pickings[1]
moves = picking_out.move_lines
self.assertEquals(len(moves), 3,
"Incorrect number of moves created")
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,
"Wrong qty delivered")
if line.product_id == self.product_1:
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 3,
"Wrong qty outgoing")
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")
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_received, 2,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 2,
"Wrong qty outgoing")
picking_out.action_assign()
picking_out.do_transfer()
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_to_deliver, 0,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 0,
"Wrong qty outgoing")
if line.product_id == self.product_1:
self.assertEquals(line.qty_received, 3,
"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,
"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")
self.line.action_rma_done()
self.assertEquals(self.line.state, 'done',
"Wrong State")

View File

@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from openerp.addons.rma.tests import test_rma
class TestRmaDropship(test_rma.TestRma):
def setUp(self):
super(TestRmaDropship, self).setUp()
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.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")

View File

@@ -0,0 +1,156 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from openerp.addons.rma.tests import test_rma
class TestSupplierRma(test_rma.TestRma):
def setUp(self):
super(TestSupplierRma, self).setUp()
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):
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

@@ -4,6 +4,7 @@
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools.safe_eval import safe_eval as eval
import odoo.addons.decimal_precision as dp

View File

@@ -7,7 +7,7 @@
'category': 'RMA',
'summary': 'RMA from PO',
'license': 'LGPL-3',
'author': 'Eficent',
'author': 'Eficent, Odoo Community Association (OCA)',
'website': 'http://www.github.com/OCA/rma',
'depends': ['rma_account', 'purchase'],
'data': ['views/rma_order_view.xml',

View File

@@ -21,7 +21,7 @@ class RmaOrderLine(models.Model):
@api.multi
@api.depends('procurement_ids.purchase_line_id')
def _get_purchase_order_lines(self):
def _compute_purchase_order_lines(self):
for rec in self:
purchase_list = []
for procurement_id in rec.procurement_ids:
@@ -53,7 +53,7 @@ class RmaOrderLine(models.Model):
comodel_name='purchase.order.line',
relation='purchase_line_rma_line_rel',
column1='rma_order_line_id', column2='purchase_order_line_id',
string='Purchase Order Lines', compute='_get_purchase_order_lines',
string='Purchase Order Lines', compute='_compute_purchase_order_lines',
)
qty_purchased = fields.Float(
string='Qty Purchased', copy=False,
@@ -140,7 +140,6 @@ class RmaOrderLine(models.Model):
self.purchase_order_line_id = False
return res
@api.multi
def action_view_purchase_order(self):
action = self.env.ref('purchase.purchase_rfq')

View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 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
from . import test_supplier_rma
from . import test_rma_dropship

View File

@@ -0,0 +1,440 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from openerp.tests import common
from openerp import fields
class TestRma(common.TransactionCase):
""" Test the routes and the quantities """
def setUp(self):
super(TestRma, self).setUp()
self.rma_make_picking = self.env['rma_make_picking.wizard']
self.make_supplier_rma = self.env["rma.order.line.make.supplier.rma"]
self.rma_add_stock_move = self.env['rma_add_stock_move']
self.stockpicking = self.env['stock.picking']
self.rma = self.env['rma.order']
self.rma_line = self.env['rma.order.line']
self.rma_op = self.env['rma.operation']
self.rma_cust_replace_op_id = self.env.ref(
'rma.rma_operation_customer_replace')
self.rma_sup_replace_op_id = self.env.ref(
'rma.rma_operation_supplier_replace')
self.product_id = self.env.ref('product.product_product_4')
self.product_id.product_tmpl_id.categ_id.\
property_stock_account_input_categ_id =\
self.env.ref('account.data_account_type_receivable').id
self.product_id.product_tmpl_id.categ_id.\
property_stock_account_output_categ_id =\
self.env.ref('account.data_account_type_expenses').id
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.uom_unit = self.env.ref('product.product_uom_unit')
# assign an operation
self.product_1.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.product_2.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.product_3.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.partner_id = self.env.ref('base.res_partner_12')
self.stock_location = self.env.ref('stock.stock_location_stock')
self.stock_rma_location = self.env.ref('rma.location_rma')
self.customer_location = self.env.ref(
'stock.stock_location_customers')
self.supplier_location = self.env.ref(
'stock.stock_location_suppliers')
self.product_uom_id = self.env.ref('product.product_uom_unit')
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'),
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, 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, picking_in)
moves.append(self.env['stock.move'].create(move_values))
# Create the RMA from the stock_move
rma_id = self.rma.create(
{
'reference': '0001',
'type': type,
'partner_id': partner.id,
'company_id': self.env.ref('base.main_company').id
})
rma_id._compute_invoice_refund_count()
rma_id._compute_invoice_count()
data = {'add_invoice_id': self._create_invoice().id}
new_line = self.rma.new(data)
new_line.on_change_invoice()
rma_id.action_view_invoice_refund()
rma_id.action_view_invoice()
for move in moves:
if type == 'customer':
wizard = self.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'customer': True,
'active_ids': rma_id.id,
'active_model': 'rma.order',
}
).create({})
data = wizard._prepare_rma_line_from_stock_move(move)
else:
wizard = self.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'supplier': True,
'active_ids': rma_id.id,
'active_model': 'rma.order',
}
).create({})
data = wizard._prepare_rma_line_from_stock_move(move)
if dropship:
data.update(customer_to_supplier=dropship,
supplier_address_id=supplier_address_id.id)
self.line = self.rma_line.create(data)
# approve the RMA Line
self.rma_line.action_rma_to_approve()
self.line.action_rma_approve()
self.line.action_view_invoice()
self.line.action_view_refunds()
# approve the RMA
# rma_id.action_rma_to_approve()
# rma_id.action_rma_approve()
return rma_id
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',
'product_uom': self.product_uom_id.id or product.uom_id.id,
'product_uom_qty': qty,
'origin': 'Test RMA',
'location_id': src.id,
'location_dest_id': dest.id,
'picking_id': picking_in.id
}
return res
def test_rma_refund(self):
self.rma_refund_item = self.env['rma.refund.item']
self.rma_refund = self.env['rma.refund']
self.product_id.income =\
self.env.ref('account.data_account_type_receivable').id
self.product_id.expense =\
self.env.ref('account.data_account_type_expenses').id
for line in self.rma_customer_id.rma_line_ids:
line.refund_policy = 'ordered'
refund = self.rma_refund.with_context({
'active_ids': self.rma_customer_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'active_id': 1
}).create({'description': 'Test Reason',
'date_invoice': fields.datetime.now()
})
self.rma_refund_item.create({
'line_id': self.rma_customer_id.rma_line_ids[0].id,
'rma_id': self.rma_customer_id.id,
'product_id': self.product_id.id,
'name': 'Test RMA Refund',
'product_qty': self.rma_customer_id.rma_line_ids[0].product_qty,
'wiz_id': refund.id
})
refund.invoice_refund()
def test_rma_add_invoice_wizard(self):
wizard = self.env['rma_add_invoice'].with_context({
'active_ids': self.rma_customer_id.ids,
'active_model': 'rma.order',
'active_id': self.rma_customer_id.id
}).create({'partner_id': self.partner_id.id,
'rma_id': self.rma_customer_id.id,
'invoice_line_ids':
[(6, 0, [self._create_invoice().invoice_line_ids.id])],
})
wizard.add_lines()
def _create_invoice(self):
self.Account = self.env['account.account']
self.AccountInvoice = self.env['account.invoice']
self.AccountInvoiceLine = self.env['account.invoice.line']
self.account_receivable =\
self.env.ref('account.data_account_type_receivable')
self.account_expenses =\
self.env.ref('account.data_account_type_expenses')
invoice_account = self.Account.\
search([('user_type_id', '=', self.account_receivable.id)], limit=1
).id
invoice_line_account = self.Account.\
search([('user_type_id', '=', self.account_expenses.id)], limit=1
).id
invoice = self.AccountInvoice.create({
'partner_id': self.partner_id.id,
'account_id': invoice_account,
'type': 'in_invoice',
})
invoice_line = self.AccountInvoiceLine.create({
'product_id': self.product_1.id,
'quantity': 1.0,
'price_unit': 100.0,
'invoice_id': invoice.id,
'uom_id': 1,
'name': 'product that cost 100',
'account_id': invoice_line_account,
})
invoice._compute_rma_count()
invoice_line._compute_rma_count()
invoice.action_view_rma_customer()
invoice.action_view_rma_supplier()
return invoice
def test_rma_make_picking(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({})
wizard.action_create_picking()
data = {'purchase_order_line_id':
self._create_purchase_order().order_line.id}
new_line = self.rma_line.new(data)
new_line._onchange_purchase_order_line_id()
self.rma_customer_id._compute_po_count()
self.rma_customer_id._compute_origin_po_count()
self.rma_customer_id.action_view_purchase_order()
self.rma_customer_id.action_view_origin_purchase_order()
self.rma_customer_id.rma_line_ids[0]._compute_purchase_count()
self.rma_customer_id.rma_line_ids[0]._compute_purchase_order_lines()
self.rma_customer_id.rma_line_ids[0].action_view_purchase_order()
self.rma_customer_id.rma_line_ids[0]._get_rma_purchased_qty()
def test_rma_add_purchase_wizard(self):
wizard = self.env['rma_add_purchase'].with_context({
'active_ids': self.rma_customer_id.ids,
'active_model': 'rma.order',
'active_id': self.rma_customer_id.id
}).create({'partner_id': self.partner_id.id,
'rma_id': self.rma_customer_id.id,
'purchase_id': self._create_purchase_order().id,
'purchase_line_ids':
[(6, 0, [self._create_purchase_order().order_line.id])],
})
wizard.default_get([str(self._create_purchase_order().id),
str(self._create_purchase_order().order_line.id),
str(self.partner_id.id)])
wizard.add_lines()
def _create_purchase_order(self):
purchase_order_id = self.env["purchase.order"].create({
"partner_id": self.partner_id.id,
"order_line": [
(0, 0, {
"product_id": self.product_id.id,
"name": self.product_id.name,
"product_qty": 5,
"price_unit": 100,
"product_uom": self.product_id.uom_id.id,
"date_planned": fields.datetime.now(),
}),
],
})
self.env["purchase.order.line"].\
name_search(name=self.product_id.name, operator='ilike',
args=[('id', 'in', purchase_order_id.order_line.ids)])
self.env["purchase.order.line"].\
_name_search(name=self.product_id.name, operator='ilike',
args=[('id', 'in', purchase_order_id.order_line.ids)])
return purchase_order_id
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({})
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_customer_id.rma_line_ids:
# 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_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()
picking.do_transfer()
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_outgoing, 0,
"Wrong qty outgoing")
self.assertEquals(line.qty_delivered, 0,
"Wrong qty delivered")
if line.product_id == self.product_1:
self.assertEquals(line.qty_received, 3,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to_deliver")
if line.product_id == self.product_2:
self.assertEquals(line.qty_received, 5,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 5,
"Wrong qty to_deliver")
if line.product_id == self.product_3:
self.assertEquals(line.qty_received, 2,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to_deliver")
wizard = self.rma_make_picking.with_context({
'active_id': 1,
'active_ids': self.rma_customer_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'picking_type': 'outgoing',
}).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), 2,
"Incorrect number of pickings created")
picking_out = pickings[1]
moves = picking_out.move_lines
self.assertEquals(len(moves), 3,
"Incorrect number of moves created")
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,
"Wrong qty delivered")
if line.product_id == self.product_1:
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 3,
"Wrong qty outgoing")
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")
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_received, 2,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 2,
"Wrong qty outgoing")
picking_out.action_assign()
picking_out.do_transfer()
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_to_deliver, 0,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 0,
"Wrong qty outgoing")
if line.product_id == self.product_1:
self.assertEquals(line.qty_received, 3,
"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,
"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")
self.line.action_rma_done()
self.assertEquals(self.line.state, 'done',
"Wrong State")

View File

@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from openerp.addons.rma.tests import test_rma
class TestRmaDropship(test_rma.TestRma):
def setUp(self):
super(TestRmaDropship, self).setUp()
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.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")

View File

@@ -0,0 +1,156 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from openerp.addons.rma.tests import test_rma
class TestSupplierRma(test_rma.TestRma):
def setUp(self):
super(TestSupplierRma, self).setUp()
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):
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

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 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
from . import test_supplier_rma
from . import test_rma_dropship

View File

@@ -0,0 +1,379 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from openerp.tests import common
class TestRma(common.TransactionCase):
""" Test the routes and the quantities """
def setUp(self):
super(TestRma, self).setUp()
self.rma_make_picking = self.env['rma_make_picking.wizard']
self.make_supplier_rma = self.env["rma.order.line.make.supplier.rma"]
self.rma_add_stock_move = self.env['rma_add_stock_move']
self.stockpicking = self.env['stock.picking']
self.rma = self.env['rma.order']
self.rma_line = self.env['rma.order.line']
self.rma_op = self.env['rma.operation']
self.rma_cust_replace_op_id = self.env.ref(
'rma.rma_operation_customer_replace')
self.rma_sup_replace_op_id = self.env.ref(
'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.uom_unit = self.env.ref('product.product_uom_unit')
# assign an operation
self.product_1.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.product_2.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.product_3.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.partner_id = self.env.ref('base.res_partner_12')
self.stock_location = self.env.ref('stock.stock_location_stock')
self.stock_rma_location = self.env.ref('rma.location_rma')
self.customer_location = self.env.ref(
'stock.stock_location_customers')
self.supplier_location = self.env.ref(
'stock.stock_location_suppliers')
self.product_uom_id = self.env.ref('product.product_uom_unit')
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'),
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, 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, picking_in)
moves.append(self.env['stock.move'].create(move_values))
# Create the RMA from the stock_move
rma_id = self.rma.create(
{
'reference': '0001',
'type': type,
'partner_id': partner.id,
'company_id': self.env.ref('base.main_company').id
})
for move in moves:
if type == 'customer':
wizard = self.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'customer': True,
'active_ids': rma_id.id,
'active_model': 'rma.order',
}
).create({})
data = wizard._prepare_rma_line_from_stock_move(move)
wizard.add_lines()
else:
wizard = self.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'supplier': True,
'active_ids': rma_id.id,
'active_model': 'rma.order',
}
).create({})
data = wizard._prepare_rma_line_from_stock_move(move)
wizard.add_lines()
if dropship:
data.update(customer_to_supplier=dropship,
supplier_address_id=supplier_address_id.id)
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()
return rma_id
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',
'product_uom': self.product_uom_id.id or product.uom_id.id,
'product_uom_qty': qty,
'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):
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()
def test_qc_issue_make_supplier_rma_wizard(self):
self.rma_qc_issue_item = self.env['qc.issue.make.supplier.rma.item']
self.rma_qc_issue = self.env['qc.issue.make.supplier.rma']
qc_issue = self.rma_qc_issue.with_context({
'active_ids': self.rma_customer_id.rma_line_ids.ids,
'active_model': 'qc.issue',
'active_id': 1
}).create({
'partner_id': self.partner_id.id,
'supplier_rma_id': self.rma_customer_id.id,
'use_group': True,
'item_ids': [(0, 0, {
'issue_id': self._create_qc_issue().id,
'product_id': self.product_id.id,
'name': 'Test RMA Refund',
'product_qty':
self.rma_customer_id.rma_line_ids[0].product_qty,
'uom_id': self.product_id.uom_id.id
})]})
self.rma_qc_issue.with_context({
'active_ids': self._create_qc_issue().ids,
'active_model': 'qc.issue'
}).default_get([str(qc_issue.id)])
qc_issue.make_supplier_rma()
qc_issue_1 = qc_issue.\
copy({'item_ids': [(6, 0, [qc_issue.item_ids.id])],
'use_group': False})
qc_issue_1.make_supplier_rma()
def _create_qc_issue(self):
location_id = self.env.ref('stock.stock_location_stock')
qc_issue_id = self.env['qc.issue'].create({
'rma_line_ids':
[(6, 0, [self.rma_customer_id.rma_line_ids[0].id])],
'product_id': self.product_id.id,
'product_qty':
self.rma_customer_id.rma_line_ids[0].product_qty,
'inspector_id': self.env.user.id,
'company_id': self.env.user.company_id.id,
'product_uom': self.product_id.uom_id.id,
'location_id': location_id.id
})
qc_issue_id._compute_rma_line_count()
qc_issue_id.action_view_rma_lines_supplier()
qc_issue_id.action_view_rma_lines_customer()
return qc_issue_id
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({})
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_customer_id.rma_line_ids:
# 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_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()
picking.do_transfer()
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_outgoing, 0,
"Wrong qty outgoing")
self.assertEquals(line.qty_delivered, 0,
"Wrong qty delivered")
if line.product_id == self.product_1:
self.assertEquals(line.qty_received, 3,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to_deliver")
if line.product_id == self.product_2:
self.assertEquals(line.qty_received, 5,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 5,
"Wrong qty to_deliver")
if line.product_id == self.product_3:
self.assertEquals(line.qty_received, 2,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to_deliver")
wizard = self.rma_make_picking.with_context({
'active_id': 1,
'active_ids': self.rma_customer_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'picking_type': 'outgoing',
}).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), 2,
"Incorrect number of pickings created")
picking_out = pickings[1]
moves = picking_out.move_lines
self.assertEquals(len(moves), 3,
"Incorrect number of moves created")
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,
"Wrong qty delivered")
if line.product_id == self.product_1:
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 3,
"Wrong qty outgoing")
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")
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_received, 2,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 2,
"Wrong qty outgoing")
picking_out.action_assign()
picking_out.do_transfer()
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_to_deliver, 0,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 0,
"Wrong qty outgoing")
if line.product_id == self.product_1:
self.assertEquals(line.qty_received, 3,
"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,
"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")
self.line.action_rma_done()
self.assertEquals(self.line.state, 'done',
"Wrong State")

View File

@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
# © 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()
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.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")

View File

@@ -0,0 +1,156 @@
# -*- coding: utf-8 -*-
# © 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()
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):
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

@@ -8,7 +8,7 @@
"license": "LGPL-3",
"category": "RMA",
"summary": "Links RMA with Repairs.",
"author": "Eficent",
"author": "Eficent, Odoo Community Association (OCA)",
"website": "http://www.github.com/OCA/rma",
"depends": ["rma_account", "mrp_repair_refurbish"],
"data": ["views/rma_order_view.xml",

View File

@@ -9,26 +9,26 @@ from openerp.addons import decimal_precision as dp
class RmaOrderLine(models.Model):
_inherit = "rma.order.line"
@api.one
@api.depends('repair_ids', 'repair_type', 'repair_ids.state',
'qty_to_receive')
def _compute_qty_to_repair(self):
if self.repair_type == 'no':
self.qty_to_repair = 0.0
elif self.repair_type == 'ordered':
qty = self._get_rma_repaired_qty()
self.qty_to_repair = self.product_qty - qty
elif self.repair_type == 'received':
qty = self._get_rma_repaired_qty()
self.qty_to_repair = self.qty_received - qty
else:
self.qty_to_repair = 0.0
for line in self:
if line.repair_type == 'no':
line.qty_to_repair = 0.0
elif line.repair_type == 'ordered':
qty = line._get_rma_repaired_qty()
line.qty_to_repair = line.product_qty - qty
elif line.repair_type == 'received':
qty = line._get_rma_repaired_qty()
line.qty_to_repair = line.qty_received - qty
else:
line.qty_to_repair = 0.0
@api.one
@api.depends('repair_ids', 'repair_type', 'repair_ids.state',
'qty_to_receive')
def _compute_qty_repaired(self):
self.qty_repaired = self._get_rma_repaired_qty()
for line in self:
line.qty_repaired = line._get_rma_repaired_qty()
@api.multi
def _compute_repair_count(self):

View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 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
from . import test_supplier_rma
from . import test_rma_dropship

View File

@@ -0,0 +1,374 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from openerp.tests import common
class TestRma(common.TransactionCase):
""" Test the routes and the quantities """
def setUp(self):
super(TestRma, self).setUp()
self.rma_make_picking = self.env['rma_make_picking.wizard']
self.make_supplier_rma = self.env["rma.order.line.make.supplier.rma"]
self.rma_add_stock_move = self.env['rma_add_stock_move']
self.stockpicking = self.env['stock.picking']
self.rma = self.env['rma.order']
self.rma_line = self.env['rma.order.line']
self.rma_op = self.env['rma.operation']
self.rma_cust_replace_op_id = self.env.ref(
'rma.rma_operation_customer_replace')
self.rma_sup_replace_op_id = self.env.ref(
'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.uom_unit = self.env.ref('product.product_uom_unit')
# assign an operation
self.product_1.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.product_2.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.product_3.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.partner_id = self.env.ref('base.res_partner_12')
self.stock_location = self.env.ref('stock.stock_location_stock')
self.stock_rma_location = self.env.ref('rma.location_rma')
self.customer_location = self.env.ref(
'stock.stock_location_customers')
self.supplier_location = self.env.ref(
'stock.stock_location_suppliers')
self.product_uom_id = self.env.ref('product.product_uom_unit')
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'),
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, 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, picking_in)
moves.append(self.env['stock.move'].create(move_values))
# Create the RMA from the stock_move
rma_id = self.rma.create(
{
'reference': '0001',
'type': type,
'partner_id': partner.id,
'company_id': self.env.ref('base.main_company').id
})
for move in moves:
if type == 'customer':
wizard = self.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'customer': True,
'active_ids': rma_id.id,
'active_model': 'rma.order',
}
).create({})
data = wizard._prepare_rma_line_from_stock_move(move)
wizard.add_lines()
else:
wizard = self.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'supplier': True,
'active_ids': rma_id.id,
'active_model': 'rma.order',
}
).create({})
data = wizard._prepare_rma_line_from_stock_move(move)
wizard.add_lines()
if dropship:
data.update(customer_to_supplier=dropship,
supplier_address_id=supplier_address_id.id)
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()
return rma_id
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',
'product_uom': self.product_uom_id.id or product.uom_id.id,
'product_uom_qty': qty,
'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):
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()
def test_rma_order_line_make_repair_wizard(self):
self.rma_line_repair_item = self.env['rma.order.line.make.repair.item']
self.rma_line_repair = self.env['rma.order.line.make.repair']
self.product_id.income =\
self.env.ref('account.data_account_type_receivable').id
self.product_id.expense =\
self.env.ref('account.data_account_type_expenses').id
location_id = self.env.ref('stock.stock_location_stock')
location_dest_id = self.env.ref('stock.stock_location_customers')
self.product_id.write({'refurbish_product_id': self.product_1.id})
repair_id = self.rma_line_repair.with_context({
'active_ids': self.rma_customer_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'active_id': 1
}).create({'item_ids': [(0, 0, {
'line_id': self.rma_customer_id.rma_line_ids[0].id,
'rma_id': self.rma_customer_id.id,
'product_id': self.product_id.id,
'name': 'Test RMA Refund',
'product_qty': self.rma_customer_id.rma_line_ids[0].product_qty,
'invoice_method': 'after_repair',
'location_id': location_id.id,
'location_dest_id': location_dest_id.id,
'refurbish_product_id': self.product_1.id,
'to_refurbish': True
})]})
repair_id.default_get([str(repair_id.item_ids)])
repair_id.make_repair_order()
data = {'to_refurbish': True}
new_line = self.rma_line_repair_item.new(data)
new_line._onchange_to_refurbish()
self.rma_customer_id._compute_repair_count()
self.rma_customer_id.action_view_repair_order()
for line in self.rma_customer_id.rma_line_ids:
line.refund_policy = 'ordered'
line._compute_qty_to_repair()
line._compute_qty_repaired()
line._compute_repair_count()
line.action_view_repair_order()
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({})
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_customer_id.rma_line_ids:
# 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_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()
picking.do_transfer()
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_outgoing, 0,
"Wrong qty outgoing")
self.assertEquals(line.qty_delivered, 0,
"Wrong qty delivered")
if line.product_id == self.product_1:
self.assertEquals(line.qty_received, 3,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to_deliver")
if line.product_id == self.product_2:
self.assertEquals(line.qty_received, 5,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 5,
"Wrong qty to_deliver")
if line.product_id == self.product_3:
self.assertEquals(line.qty_received, 2,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to_deliver")
wizard = self.rma_make_picking.with_context({
'active_id': 1,
'active_ids': self.rma_customer_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'picking_type': 'outgoing',
}).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), 2,
"Incorrect number of pickings created")
picking_out = pickings[1]
moves = picking_out.move_lines
self.assertEquals(len(moves), 3,
"Incorrect number of moves created")
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,
"Wrong qty delivered")
if line.product_id == self.product_1:
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 3,
"Wrong qty outgoing")
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")
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_received, 2,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 2,
"Wrong qty outgoing")
picking_out.action_assign()
picking_out.do_transfer()
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_to_deliver, 0,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 0,
"Wrong qty outgoing")
if line.product_id == self.product_1:
self.assertEquals(line.qty_received, 3,
"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,
"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")
self.line.action_rma_done()
self.assertEquals(self.line.state, 'done',
"Wrong State")

View File

@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
# © 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()
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.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")

View File

@@ -0,0 +1,156 @@
# -*- coding: utf-8 -*-
# © 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()
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):
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

@@ -8,7 +8,7 @@
'license': 'LGPL-3',
'category': 'RMA',
'summary': 'Links RMA with Sales Orders',
'author': "Eficent",
'author': "Eficent, Odoo Community Association (OCA)",
'website': 'http://www.github.com/OCA/rma',
'depends': ['rma_account', 'sale_stock'],
'data': ['views/rma_order_view.xml',

View File

@@ -9,7 +9,6 @@ from odoo.addons import decimal_precision as dp
class RmaOrderLine(models.Model):
_inherit = "rma.order.line"
@api.one
@api.depends('sale_line_ids', 'sale_type', 'sales_count',
'sale_line_ids.state')
def _compute_qty_to_sell(self):
@@ -24,7 +23,6 @@ class RmaOrderLine(models.Model):
else:
self.qty_to_sell = 0.0
@api.one
@api.depends('sale_line_ids', 'sale_type', 'sales_count',
'sale_line_ids.state')
def _compute_qty_sold(self):

View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 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
from . import test_supplier_rma
from . import test_rma_dropship

451
rma_sale/tests/test_rma.py Normal file
View File

@@ -0,0 +1,451 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from openerp.tests import common
from openerp import fields
class TestRma(common.TransactionCase):
""" Test the routes and the quantities """
def setUp(self):
super(TestRma, self).setUp()
self.rma_make_picking = self.env['rma_make_picking.wizard']
self.make_supplier_rma = self.env["rma.order.line.make.supplier.rma"]
self.rma_add_stock_move = self.env['rma_add_stock_move']
self.stockpicking = self.env['stock.picking']
self.rma = self.env['rma.order']
self.rma_line = self.env['rma.order.line']
self.rma_op = self.env['rma.operation']
self.rma_cust_replace_op_id = self.env.ref(
'rma.rma_operation_customer_replace')
self.rma_sup_replace_op_id = self.env.ref(
'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.uom_unit = self.env.ref('product.product_uom_unit')
# assign an operation
self.product_1.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.product_2.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.product_3.write(
{'rma_customer_operation_id': self.rma_cust_replace_op_id.id,
'rma_supplier_operation_id': self.rma_sup_replace_op_id.id})
self.partner_id = self.env.ref('base.res_partner_12')
self.stock_location = self.env.ref('stock.stock_location_stock')
self.stock_rma_location = self.env.ref('rma.location_rma')
self.customer_location = self.env.ref(
'stock.stock_location_customers')
self.supplier_location = self.env.ref(
'stock.stock_location_suppliers')
self.product_uom_id = self.env.ref('product.product_uom_unit')
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'),
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, 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, picking_in)
moves.append(self.env['stock.move'].create(move_values))
# Create the RMA from the stock_move
rma_id = self.rma.create(
{
'reference': '0001',
'type': type,
'partner_id': partner.id,
'company_id': self.env.ref('base.main_company').id
})
for move in moves:
if type == 'customer':
wizard = self.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'customer': True,
'active_ids': rma_id.id,
'active_model': 'rma.order',
}
).create({})
data = wizard._prepare_rma_line_from_stock_move(move)
wizard.add_lines()
else:
wizard = self.rma_add_stock_move.with_context(
{'stock_move_id': move.id, 'supplier': True,
'active_ids': rma_id.id,
'active_model': 'rma.order',
}
).create({})
data = wizard._prepare_rma_line_from_stock_move(move)
wizard.add_lines()
if dropship:
data.update(customer_to_supplier=dropship,
supplier_address_id=supplier_address_id.id)
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._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()
return rma_id
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',
'product_uom': self.product_uom_id.id or product.uom_id.id,
'product_uom_qty': qty,
'origin': 'Test RMA',
'location_id': src.id,
'location_dest_id': dest.id,
'picking_id': picking_in.id
}
return res
def test_add_sale(self):
wizard = self.env['rma_add_sale'].with_context({
'active_ids': self.rma_customer_id.ids,
'active_model': 'rma.order',
'active_id': self.rma_customer_id.id
}).create({'partner_id': self.partner_id.id,
'rma_id': self.rma_customer_id.id,
'sale_id': self._create_sale_order().id,
'sale_line_ids':
[(6, 0, [self._create_sale_order().order_line.id])],
})
wizard.default_get([str(self._create_sale_order().id),
str(self._create_sale_order().order_line.id),
str(self.partner_id.id)])
wizard.add_lines()
for line in self.rma_customer_id.rma_line_ids:
line._compute_qty_to_sell()
line.sale_type = 'ordered'
line._compute_qty_to_sell()
line.sale_type = 'received'
line._compute_qty_to_sell()
line._compute_qty_sold()
line._compute_sales_count()
data = {'sale_line_id': self._create_sale_order().order_line.id}
new_line = self.rma_line.new(data)
new_line._onchange_sale_line_id()
line.action_view_sale_order()
self.rma_customer_id._compute_sales_count()
self.rma_customer_id.action_view_sale_order()
def test_rma_order_line_make_sale_order(self):
self.rma_sale_order_item =\
self.env['rma.order.line.make.sale.order.item']
self.rma_sale_order = self.env['rma.order.line.make.sale.order']
self.product_id.income =\
self.env.ref('account.data_account_type_receivable').id
self.product_id.expense =\
self.env.ref('account.data_account_type_expenses').id
sale_order = self.rma_sale_order.with_context({
'active_ids': self.rma_customer_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'active_id': 1
}).create({'sale_order_id': self._create_sale_order().id,
'partner_id': self.partner_id.id,
})
self.rma_sale_order_item.create({
'line_id': self.rma_customer_id.rma_line_ids[0].id,
'rma_id': self.rma_customer_id.id,
'product_id': self.product_id.id,
'name': 'Test RMA Refund',
'product_qty': self.rma_customer_id.rma_line_ids[0].product_qty,
'wiz_id': sale_order.id
})
for line in sale_order.item_ids:
line.product_qty = self.rma_customer_id.rma_line_ids[0].product_qty
sale_order.make_sale_order()
sale_order.write({'sale_order_id': False})
sale_order.make_sale_order()
def test_rma_refund(self):
self.rma_refund_item = self.env['rma.refund.item']
self.rma_refund = self.env['rma.refund']
self.product_id.income =\
self.env.ref('account.data_account_type_receivable').id
self.product_id.expense =\
self.env.ref('account.data_account_type_expenses').id
self.product_id.product_tmpl_id.categ_id.\
property_stock_account_input_categ_id =\
self.env.ref('account.data_account_type_receivable').id
self.product_id.product_tmpl_id.categ_id.\
property_stock_account_output_categ_id =\
self.env.ref('account.data_account_type_expenses').id
for line in self.rma_customer_id.rma_line_ids:
line.refund_policy = 'ordered'
refund = self.rma_refund.with_context({
'active_ids': self.rma_customer_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'active_id': 1
}).create({'description': 'Test Reason',
'date_invoice': fields.datetime.now()
})
self.rma_refund_item.create({
'line_id': self.rma_customer_id.rma_line_ids[0].id,
'rma_id': self.rma_customer_id.id,
'product_id': self.product_id.id,
'name': 'Test RMA Refund',
'product_qty': self.rma_customer_id.rma_line_ids[0].product_qty,
'wiz_id': refund.id
})
def _create_sale_order(self):
self.sale_order_id = self.env['sale.order'].create({
'partner_id': self.partner_id.id,
'partner_invoice_id': self.partner_id.id,
'partner_shipping_id': self.partner_id.id,
'order_line': [(0, 0, {
'name': self.product_id.name,
'product_id': self.product_id.id,
'product_uom_qty':
self.rma_customer_id.rma_line_ids[0].product_qty,
'price_unit': 100.00,
})]
})
self.env["sale.order.line"].\
name_search(name=self.product_id.name, operator='ilike',
args=[('id', 'in', self.sale_order_id.order_line.ids)])
self.env["sale.order.line"].\
_name_search(name=self.product_id.name, operator='ilike',
args=[('id', 'in', self.sale_order_id.order_line.ids)
])
self.sale_order_id.order_line._prepare_order_line_procurement()
return self.sale_order_id
def test_rma_order_line(self):
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()
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({})
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_customer_id.rma_line_ids:
# 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_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()
picking.do_transfer()
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_outgoing, 0,
"Wrong qty outgoing")
self.assertEquals(line.qty_delivered, 0,
"Wrong qty delivered")
if line.product_id == self.product_1:
self.assertEquals(line.qty_received, 3,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to_deliver")
if line.product_id == self.product_2:
self.assertEquals(line.qty_received, 5,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 5,
"Wrong qty to_deliver")
if line.product_id == self.product_3:
self.assertEquals(line.qty_received, 2,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to_deliver")
wizard = self.rma_make_picking.with_context({
'active_id': 1,
'active_ids': self.rma_customer_id.rma_line_ids.ids,
'active_model': 'rma.order.line',
'picking_type': 'outgoing',
}).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), 2,
"Incorrect number of pickings created")
picking_out = pickings[1]
moves = picking_out.move_lines
self.assertEquals(len(moves), 3,
"Incorrect number of moves created")
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,
"Wrong qty delivered")
if line.product_id == self.product_1:
self.assertEquals(line.qty_to_deliver, 3,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 3,
"Wrong qty outgoing")
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")
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_received, 2,
"Wrong qty received")
self.assertEquals(line.qty_to_deliver, 2,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 2,
"Wrong qty outgoing")
picking_out.action_assign()
picking_out.do_transfer()
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_to_deliver, 0,
"Wrong qty to deliver")
self.assertEquals(line.qty_outgoing, 0,
"Wrong qty outgoing")
if line.product_id == self.product_1:
self.assertEquals(line.qty_received, 3,
"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,
"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")
self.line.action_rma_done()
self.assertEquals(self.line.state, 'done',
"Wrong State")

View File

@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
# © 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()
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.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")

View File

@@ -0,0 +1,156 @@
# -*- coding: utf-8 -*-
# © 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()
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):
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")