mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[11.0][MIG] rma_repair (#55)
This commit is contained in:
committed by
JasminSForgeFlow
parent
30ae9fcbcb
commit
d87a5d7e46
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from . import models
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
{
|
||||
"name": "RMA Repair",
|
||||
"version": "9.0.1.0.0",
|
||||
"version": "11.0.1.0.0",
|
||||
"license": "LGPL-3",
|
||||
"category": "RMA",
|
||||
"summary": "Links RMA with Repairs.",
|
||||
@@ -18,6 +17,6 @@
|
||||
"views/rma_order_line_view.xml",
|
||||
"data/mrp_repair_sequence.xml",
|
||||
],
|
||||
"installable": False,
|
||||
"installable": True,
|
||||
"auto_install": True,
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from . import mrp_repair
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from openerp import fields, models
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class MrpRepair(models.Model):
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from openerp import fields, models
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class RmaOperation(models.Model):
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from openerp import api, fields, models
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class RmaOrder(models.Model):
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from openerp import api, fields, models
|
||||
from openerp.addons import decimal_precision as dp
|
||||
from odoo import api, fields, models
|
||||
from odoo.addons import decimal_precision as dp
|
||||
|
||||
|
||||
class RmaOrderLine(models.Model):
|
||||
@@ -75,8 +74,7 @@ class RmaOrderLine(models.Model):
|
||||
qty = 0.0
|
||||
for repair in self.repair_ids.filtered(
|
||||
lambda p: p.state != 'cancel'):
|
||||
repair_qty = self.env['product.uom']._compute_qty_obj(
|
||||
self.uom_id,
|
||||
repair_qty = self.uom_id._compute_quantity(
|
||||
repair.product_qty,
|
||||
repair.product_uom,
|
||||
)
|
||||
|
||||
@@ -1,6 +1,2 @@
|
||||
# -*- 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
|
||||
from . import test_rma_repair
|
||||
|
||||
@@ -1,374 +0,0 @@
|
||||
# -*- 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")
|
||||
@@ -1,96 +0,0 @@
|
||||
# -*- 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")
|
||||
154
rma_repair/tests/test_rma_repair.py
Normal file
154
rma_repair/tests/test_rma_repair.py
Normal file
@@ -0,0 +1,154 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestRmaRepair(common.SingleTransactionCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestRmaRepair, cls).setUpClass()
|
||||
|
||||
cls.rma_obj = cls.env['rma.order']
|
||||
cls.rma_line_obj = cls.env['rma.order.line']
|
||||
cls.rma_op = cls.env['rma.operation']
|
||||
cls.rma_add_invoice_wiz = cls.env['rma_add_invoice']
|
||||
cls.rma_make_repair_wiz = cls.env['rma.order.line.make.repair']
|
||||
cls.acc_obj = cls.env['account.account']
|
||||
cls.inv_obj = cls.env['account.invoice']
|
||||
cls.invl_obj = cls.env['account.invoice.line']
|
||||
cls.product_obj = cls.env['product.product']
|
||||
cls.partner_obj = cls.env['res.partner']
|
||||
|
||||
cls.rma_route_cust = cls.env.ref('rma.route_rma_customer')
|
||||
receivable_type = cls.env.ref('account.data_account_type_receivable')
|
||||
|
||||
# Create partners
|
||||
customer1 = cls.partner_obj.create({'name': 'Customer 1'})
|
||||
|
||||
# Create RMA group and operation:
|
||||
cls.rma_group_customer = cls.rma_obj.create({
|
||||
'partner_id': customer1.id,
|
||||
'type': 'customer',
|
||||
})
|
||||
cls.operation_1 = cls.rma_op.create({
|
||||
'code': 'TEST',
|
||||
'name': 'Repair afer receive',
|
||||
'type': 'customer',
|
||||
'receipt_policy': 'ordered',
|
||||
'repair_type': 'received',
|
||||
'in_route_id': cls.rma_route_cust.id,
|
||||
'out_route_id': cls.rma_route_cust.id,
|
||||
})
|
||||
cls.operation_2 = cls.rma_op.create({
|
||||
'code': 'TEST',
|
||||
'name': 'Repair on order',
|
||||
'type': 'customer',
|
||||
'receipt_policy': 'ordered',
|
||||
'repair_type': 'ordered',
|
||||
'in_route_id': cls.rma_route_cust.id,
|
||||
'out_route_id': cls.rma_route_cust.id,
|
||||
})
|
||||
|
||||
# Create products
|
||||
cls.product_1 = cls.product_obj.create({
|
||||
'name': 'Test Product 1',
|
||||
'type': 'product',
|
||||
'list_price': 100.0,
|
||||
'rma_customer_operation_id': cls.operation_1.id,
|
||||
})
|
||||
cls.product_2 = cls.product_obj.create({
|
||||
'name': 'Test Product 2',
|
||||
'type': 'product',
|
||||
'list_price': 150.0,
|
||||
'rma_customer_operation_id': cls.operation_2.id,
|
||||
})
|
||||
|
||||
# Create Invoices:
|
||||
customer_account = cls.acc_obj.search(
|
||||
[('user_type_id', '=', receivable_type.id)], limit=1).id
|
||||
cls.inv_customer = cls.inv_obj.create({
|
||||
'partner_id': customer1.id,
|
||||
'account_id': customer_account,
|
||||
'type': 'out_invoice',
|
||||
})
|
||||
cls.inv_line_1 = cls.invl_obj.create({
|
||||
'name': cls.product_1.name,
|
||||
'product_id': cls.product_1.id,
|
||||
'quantity': 12.0,
|
||||
'price_unit': 100.0,
|
||||
'invoice_id': cls.inv_customer.id,
|
||||
'uom_id': cls.product_1.uom_id.id,
|
||||
'account_id': customer_account,
|
||||
})
|
||||
cls.inv_line_2 = cls.invl_obj.create({
|
||||
'name': cls.product_2.name,
|
||||
'product_id': cls.product_2.id,
|
||||
'quantity': 15.0,
|
||||
'price_unit': 150.0,
|
||||
'invoice_id': cls.inv_customer.id,
|
||||
'uom_id': cls.product_2.uom_id.id,
|
||||
'account_id': customer_account,
|
||||
})
|
||||
|
||||
def test_01_add_from_invoice_customer(self):
|
||||
"""Test wizard to create RMA from a customer invoice."""
|
||||
add_inv = self.rma_add_invoice_wiz.with_context({
|
||||
'customer': True,
|
||||
'active_ids': self.rma_group_customer.id,
|
||||
'active_model': 'rma.order',
|
||||
}).create({
|
||||
'invoice_line_ids':
|
||||
[(6, 0, self.inv_customer.invoice_line_ids.ids)],
|
||||
})
|
||||
add_inv.add_lines()
|
||||
self.assertEqual(len(self.rma_group_customer.rma_line_ids), 2)
|
||||
rma_1 = self.rma_group_customer.rma_line_ids.filtered(
|
||||
lambda r: r.product_id == self.product_1)
|
||||
rma_1.repair_type = self.operation_1.repair_type
|
||||
self.assertEquals(rma_1.operation_id, self.operation_1,
|
||||
"Operation should be operation_1")
|
||||
rma_2 = self.rma_group_customer.rma_line_ids.filtered(
|
||||
lambda r: r.product_id == self.product_2)
|
||||
rma_2.repair_type = self.operation_2.repair_type
|
||||
self.assertEquals(rma_2.operation_id, self.operation_2,
|
||||
"Operation should be operation_2")
|
||||
|
||||
def test_02_rma_repair_operation(self):
|
||||
"""Test RMA quantities using repair operations."""
|
||||
# Received repair_type:
|
||||
rma_1 = self.rma_group_customer.rma_line_ids.filtered(
|
||||
lambda r: r.product_id == self.product_1)
|
||||
self.assertEquals(rma_1.operation_id.repair_type, 'received',
|
||||
"Incorrect Repair operation")
|
||||
self.assertEquals(rma_1.qty_to_repair, 0.0,
|
||||
"Quantity to repair should be 0.0")
|
||||
# Ordered repair_type:
|
||||
rma_2 = self.rma_group_customer.rma_line_ids.filtered(
|
||||
lambda r: r.product_id == self.product_2)
|
||||
self.assertEquals(rma_2.operation_id.repair_type, 'ordered',
|
||||
"Incorrect Repair operation")
|
||||
self.assertEqual(rma_2.qty_to_repair, 15.0)
|
||||
|
||||
def test_03_create_repair_order(self):
|
||||
"""Generate a Repair Order from a customer RMA."""
|
||||
rma = self.rma_group_customer.rma_line_ids.filtered(
|
||||
lambda r: r.product_id == self.product_2)
|
||||
rma.action_rma_to_approve()
|
||||
rma.action_rma_approve()
|
||||
self.assertEqual(rma.repair_count, 0)
|
||||
self.assertEqual(rma.qty_to_repair, 15.0)
|
||||
self.assertEqual(rma.qty_repaired, 0.0)
|
||||
make_repair = self.rma_make_repair_wiz.with_context({
|
||||
'customer': True,
|
||||
'active_ids': rma.ids,
|
||||
'active_model': 'rma.order.line',
|
||||
}).create({
|
||||
'description': 'Test refund',
|
||||
})
|
||||
make_repair.make_repair_order()
|
||||
rma.repair_ids.action_repair_confirm()
|
||||
self.assertEqual(rma.repair_count, 1)
|
||||
self.assertEqual(rma.qty_to_repair, 0.0)
|
||||
self.assertEqual(rma.qty_repaired, 15.0)
|
||||
@@ -1,156 +0,0 @@
|
||||
# -*- 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")
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from . import rma_order_line_make_repair
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).
|
||||
|
||||
import openerp.addons.decimal_precision as dp
|
||||
from openerp import _, api, fields, models
|
||||
from openerp.exceptions import ValidationError
|
||||
import odoo.addons.decimal_precision as dp
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class RmaLineMakeRepair(models.TransientModel):
|
||||
@@ -24,7 +23,6 @@ class RmaLineMakeRepair(models.TransientModel):
|
||||
to_refurbish = refurbish_product_id = False
|
||||
return {
|
||||
'line_id': line.id,
|
||||
'rma_line_id': line.id,
|
||||
'product_id': line.product_id.id,
|
||||
'product_qty': line.qty_to_repair,
|
||||
'rma_id': line.rma_id.id,
|
||||
@@ -96,11 +94,11 @@ class RmaLineMakeRepairItem(models.TransientModel):
|
||||
|
||||
wiz_id = fields.Many2one(
|
||||
comodel_name='rma.order.line.make.repair', string='Wizard',
|
||||
ondelete='cascade', readonly=True,
|
||||
ondelete='cascade',
|
||||
)
|
||||
line_id = fields.Many2one(
|
||||
comodel_name='rma.order.line', string='RMA',
|
||||
required=True, readonly=True,
|
||||
required=True,
|
||||
)
|
||||
rma_id = fields.Many2one(
|
||||
comodel_name='rma.order', related='line_id.rma_id',
|
||||
@@ -149,15 +147,15 @@ class RmaLineMakeRepairItem(models.TransientModel):
|
||||
@api.model
|
||||
def _prepare_repair_order(self, rma_line):
|
||||
location_dest = (self.location_dest_id if not self.to_refurbish else
|
||||
self.product_id.property_stock_refurbish)
|
||||
rma_line.product_id.property_stock_refurbish)
|
||||
refurbish_location_dest_id = (self.location_dest_id.id if
|
||||
self.to_refurbish else False)
|
||||
return {
|
||||
'product_id': self.product_id.id,
|
||||
'partner_id': self.partner_id.id,
|
||||
'product_id': rma_line.product_id.id,
|
||||
'partner_id': rma_line.partner_id.id,
|
||||
'product_qty': self.product_qty,
|
||||
'rma_line_id': self.line_id.id,
|
||||
'product_uom': self.product_id.uom_po_id.id,
|
||||
'rma_line_id': rma_line.id,
|
||||
'product_uom': rma_line.product_id.uom_po_id.id,
|
||||
'company_id': rma_line.company_id.id,
|
||||
'location_id': self.location_id.id,
|
||||
'location_dest_id': location_dest.id,
|
||||
|
||||
@@ -28,12 +28,12 @@
|
||||
</field>
|
||||
</group>
|
||||
<newline/>
|
||||
<group colspan="2">
|
||||
<footer>
|
||||
<button name="make_repair_order"
|
||||
string="Create Repair Orders" type="object"
|
||||
class="oe_highlight"/>
|
||||
<button special="cancel" string="Cancel" class="oe_link"/>
|
||||
</group>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
@@ -46,16 +46,7 @@
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.values" id="rma_order_line_make_repair_multi">
|
||||
<field name="model_id" ref="model_rma_order_line" />
|
||||
<field name="name">Create Repairs</field>
|
||||
<field name="key2">client_action_multi</field>
|
||||
<field name="value"
|
||||
eval="'ir.actions.act_window,' + str(ref('action_rma_order_line_make_repair'))" />
|
||||
<field name="key">action</field>
|
||||
<field name="model">rma.order.line</field>
|
||||
<field name="binding_model_id" ref="rma_repair.model_rma_order_line"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user