[IMP] : black, isort

This commit is contained in:
ahenriquez
2020-03-19 15:38:40 +01:00
parent 806d24c429
commit 3d27cde0d7
7 changed files with 406 additions and 343 deletions

View File

@@ -9,11 +9,9 @@
"summary": "Links RMA with Repairs.", "summary": "Links RMA with Repairs.",
"author": "Eficent, Odoo Community Association (OCA)", "author": "Eficent, Odoo Community Association (OCA)",
"website": "https://github.com/Eficent/stock-rma", "website": "https://github.com/Eficent/stock-rma",
"depends": [ "depends": ["rma_account", "repair_refurbish"],
"rma_account", "data": [
"repair_refurbish" "views/rma_order_view.xml",
],
"data": ["views/rma_order_view.xml",
"views/rma_operation_view.xml", "views/rma_operation_view.xml",
"views/repair_view.xml", "views/repair_view.xml",
"wizards/rma_order_line_make_repair_view.xml", "wizards/rma_order_line_make_repair_view.xml",

View File

@@ -8,9 +8,9 @@ class RepairOrder(models.Model):
_inherit = "repair.order" _inherit = "repair.order"
rma_line_id = fields.Many2one( rma_line_id = fields.Many2one(
comodel_name='rma.order.line', string='RMA', ondelete='restrict', comodel_name="rma.order.line", string="RMA", ondelete="restrict"
) )
under_warranty = fields.Boolean( under_warranty = fields.Boolean(
related='rma_line_id.under_warranty', readonly=False, related="rma_line_id.under_warranty", readonly=False
) )
invoice_status = fields.Selection(related='invoice_id.state') invoice_status = fields.Selection(related="invoice_id.state")

View File

@@ -5,11 +5,17 @@ from odoo import fields, models
class RmaOperation(models.Model): class RmaOperation(models.Model):
_inherit = 'rma.operation' _inherit = "rma.operation"
repair_type = fields.Selection([ repair_type = fields.Selection(
('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'), [
('received', 'Based on Received Quantities')], ("no", "Not required"),
string="Repair Policy", default='no') ("ordered", "Based on Ordered Quantities"),
delivery_policy = fields.Selection(selection_add=[ ("received", "Based on Received Quantities"),
('repair', 'Based on Repair Quantities')]) ],
string="Repair Policy",
default="no",
)
delivery_policy = fields.Selection(
selection_add=[("repair", "Based on Repair Quantities")]
)

View File

@@ -10,16 +10,17 @@ class RmaOrder(models.Model):
@api.multi @api.multi
def _compute_repair_count(self): def _compute_repair_count(self):
for rma in self: for rma in self:
repairs = rma.mapped('rma_line_ids.repair_ids') repairs = rma.mapped("rma_line_ids.repair_ids")
rma.repair_count = len(repairs) rma.repair_count = len(repairs)
repair_count = fields.Integer( repair_count = fields.Integer(
compute='_compute_repair_count', string='# of Repairs') compute="_compute_repair_count", string="# of Repairs"
)
@api.multi @api.multi
def action_view_repair_order(self): def action_view_repair_order(self):
action = self.env.ref('repair.action_repair_order_tree') action = self.env.ref("repair.action_repair_order_tree")
result = action.read()[0] result = action.read()[0]
repair_ids = self.mapped('rma_line_ids.repair_ids').ids repair_ids = self.mapped("rma_line_ids.repair_ids").ids
result['domain'] = [('id', 'in', repair_ids)] result["domain"] = [("id", "in", repair_ids)]
return result return result

View File

@@ -2,114 +2,135 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import api, fields, models from odoo import api, fields, models
from odoo.addons import decimal_precision as dp from odoo.addons import decimal_precision as dp
class RmaOrderLine(models.Model): class RmaOrderLine(models.Model):
_inherit = "rma.order.line" _inherit = "rma.order.line"
@api.depends('repair_ids', 'repair_type', 'repair_ids.state', @api.depends("repair_ids", "repair_type", "repair_ids.state", "qty_to_receive")
'qty_to_receive')
def _compute_qty_to_repair(self): def _compute_qty_to_repair(self):
for line in self: for line in self:
if line.repair_type == 'no': if line.repair_type == "no":
line.qty_to_repair = 0.0 line.qty_to_repair = 0.0
elif line.repair_type == 'ordered': elif line.repair_type == "ordered":
qty = line._get_rma_repaired_qty() + \ qty = line._get_rma_repaired_qty() + line._get_rma_under_repair_qty()
line._get_rma_under_repair_qty()
line.qty_to_repair = line.product_qty - qty line.qty_to_repair = line.product_qty - qty
elif line.repair_type == 'received': elif line.repair_type == "received":
qty = line._get_rma_repaired_qty() + \ qty = line._get_rma_repaired_qty() + line._get_rma_under_repair_qty()
line._get_rma_under_repair_qty()
line.qty_to_repair = line.qty_received - qty line.qty_to_repair = line.qty_received - qty
else: else:
line.qty_to_repair = 0.0 line.qty_to_repair = 0.0
@api.depends('repair_ids', 'repair_type', 'repair_ids.state', @api.depends("repair_ids", "repair_type", "repair_ids.state", "qty_to_receive")
'qty_to_receive')
def _compute_qty_repaired(self): def _compute_qty_repaired(self):
for line in self: for line in self:
line.qty_repaired = line._get_rma_repaired_qty() line.qty_repaired = line._get_rma_repaired_qty()
@api.depends('repair_ids', 'repair_type', 'repair_ids.state', @api.depends("repair_ids", "repair_type", "repair_ids.state", "qty_to_receive")
'qty_to_receive')
def _compute_qty_under_repair(self): def _compute_qty_under_repair(self):
for line in self: for line in self:
line.qty_under_repair = line._get_rma_under_repair_qty() line.qty_under_repair = line._get_rma_under_repair_qty()
@api.depends('repair_ids') @api.depends("repair_ids")
def _compute_repair_count(self): def _compute_repair_count(self):
for line in self: for line in self:
line.repair_count = len(line.repair_ids) line.repair_count = len(line.repair_ids)
repair_ids = fields.One2many( repair_ids = fields.One2many(
comodel_name='repair.order', inverse_name='rma_line_id', comodel_name="repair.order",
string='Repair Orders', readonly=True, inverse_name="rma_line_id",
states={'draft': [('readonly', False)]}, copy=False) string="Repair Orders",
readonly=True,
states={"draft": [("readonly", False)]},
copy=False,
)
qty_to_repair = fields.Float( qty_to_repair = fields.Float(
string='Qty To Repair', copy=False, string="Qty To Repair",
digits=dp.get_precision('Product Unit of Measure'), copy=False,
readonly=True, compute='_compute_qty_to_repair', digits=dp.get_precision("Product Unit of Measure"),
store=True) readonly=True,
compute="_compute_qty_to_repair",
store=True,
)
qty_under_repair = fields.Float( qty_under_repair = fields.Float(
string='Qty Under Repair', copy=False, string="Qty Under Repair",
digits=dp.get_precision('Product Unit of Measure'), copy=False,
readonly=True, compute='_compute_qty_under_repair', digits=dp.get_precision("Product Unit of Measure"),
store=True) readonly=True,
compute="_compute_qty_under_repair",
store=True,
)
qty_repaired = fields.Float( qty_repaired = fields.Float(
string='Qty Repaired', copy=False, string="Qty Repaired",
digits=dp.get_precision('Product Unit of Measure'), copy=False,
readonly=True, compute='_compute_qty_repaired', digits=dp.get_precision("Product Unit of Measure"),
store=True, help="Quantity repaired or being repaired.") readonly=True,
repair_type = fields.Selection(selection=[ compute="_compute_qty_repaired",
('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'), store=True,
('received', 'Based on Received Quantities')], help="Quantity repaired or being repaired.",
string="Repair Policy", default='no', required=True) )
repair_type = fields.Selection(
selection=[
("no", "Not required"),
("ordered", "Based on Ordered Quantities"),
("received", "Based on Received Quantities"),
],
string="Repair Policy",
default="no",
required=True,
)
repair_count = fields.Integer( repair_count = fields.Integer(
compute='_compute_repair_count', string='# of Repairs') compute="_compute_repair_count", string="# of Repairs"
)
delivery_policy = fields.Selection(selection_add=[ delivery_policy = fields.Selection(
('repair', 'Based on Repair Quantities')]) selection_add=[("repair", "Based on Repair Quantities")]
qty_to_pay = fields.Float( )
compute='_compute_qty_to_pay') qty_to_pay = fields.Float(compute="_compute_qty_to_pay")
qty_to_deliver = fields.Float( qty_to_deliver = fields.Float(compute="_compute_qty_to_deliver")
compute='_compute_qty_to_deliver')
@api.multi @api.multi
@api.depends('delivery_policy', 'product_qty', 'type', 'repair_ids', @api.depends(
'repair_ids.state', 'repair_ids.invoice_method', "delivery_policy",
'repair_type', 'repair_ids.invoice_status') "product_qty",
"type",
"repair_ids",
"repair_ids.state",
"repair_ids.invoice_method",
"repair_type",
"repair_ids.invoice_status",
)
def _compute_qty_to_pay(self): def _compute_qty_to_pay(self):
for rec in self.filtered(lambda l: l.delivery_policy == 'repair'): for rec in self.filtered(lambda l: l.delivery_policy == "repair"):
qty_to_pay = 0.0 qty_to_pay = 0.0
for repair in rec.repair_ids.filtered( for repair in rec.repair_ids.filtered(
lambda r: r.invoice_method != 'none' lambda r: r.invoice_method != "none" and r.invoice_status != "paid"
and r.invoice_status != 'paid'): ):
qty_to_pay += repair.product_qty qty_to_pay += repair.product_qty
rec.qty_to_pay = qty_to_pay rec.qty_to_pay = qty_to_pay
@api.multi @api.multi
def action_view_repair_order(self): def action_view_repair_order(self):
action = self.env.ref('repair.action_repair_order_tree') action = self.env.ref("repair.action_repair_order_tree")
result = action.read()[0] result = action.read()[0]
repair_ids = self.repair_ids.ids repair_ids = self.repair_ids.ids
if len(repair_ids) != 1: if len(repair_ids) != 1:
result['domain'] = [('id', 'in', repair_ids)] result["domain"] = [("id", "in", repair_ids)]
elif len(repair_ids) == 1: elif len(repair_ids) == 1:
res = self.env.ref('repair.view_repair_order_form', False) res = self.env.ref("repair.view_repair_order_form", False)
result['views'] = [(res and res.id or False, 'form')] result["views"] = [(res and res.id or False, "form")]
result['res_id'] = repair_ids[0] result["res_id"] = repair_ids[0]
return result return result
@api.multi @api.multi
def _get_rma_repaired_qty(self): def _get_rma_repaired_qty(self):
self.ensure_one() self.ensure_one()
qty = 0.0 qty = 0.0
for repair in self.repair_ids.filtered( for repair in self.repair_ids.filtered(lambda p: p.state == "done"):
lambda p: p.state == 'done'):
repair_qty = self.uom_id._compute_quantity( repair_qty = self.uom_id._compute_quantity(
repair.product_qty, repair.product_qty, repair.product_uom
repair.product_uom,
) )
qty += repair_qty qty += repair_qty
return qty return qty
@@ -119,29 +140,38 @@ class RmaOrderLine(models.Model):
self.ensure_one() self.ensure_one()
qty = 0.0 qty = 0.0
for repair in self.repair_ids.filtered( for repair in self.repair_ids.filtered(
lambda p: p.state not in ('draft', 'cancel', 'done')): lambda p: p.state not in ("draft", "cancel", "done")
):
repair_qty = self.uom_id._compute_quantity( repair_qty = self.uom_id._compute_quantity(
repair.product_qty, repair.product_qty, repair.product_uom
repair.product_uom,
) )
qty += repair_qty qty += repair_qty
return qty return qty
@api.onchange('operation_id') @api.onchange("operation_id")
def _onchange_operation_id(self): def _onchange_operation_id(self):
result = super(RmaOrderLine, self)._onchange_operation_id() result = super(RmaOrderLine, self)._onchange_operation_id()
if self.operation_id: if self.operation_id:
self.repair_type = self.operation_id.repair_type or 'no' self.repair_type = self.operation_id.repair_type or "no"
return result return result
@api.multi @api.multi
@api.depends('move_ids', 'move_ids.state', @api.depends(
'delivery_policy', 'product_qty', 'type', 'qty_delivered', "move_ids",
'qty_received', 'repair_ids', 'repair_type', "move_ids.state",
'repair_ids.state', 'qty_to_pay', 'repair_ids.invoice_status') "delivery_policy",
"product_qty",
"type",
"qty_delivered",
"qty_received",
"repair_ids",
"repair_type",
"repair_ids.state",
"qty_to_pay",
"repair_ids.invoice_status",
)
def _compute_qty_to_deliver(self): def _compute_qty_to_deliver(self):
res = super(RmaOrderLine, self)._compute_qty_to_deliver() res = super(RmaOrderLine, self)._compute_qty_to_deliver()
for rec in self.filtered(lambda l: l.delivery_policy == 'repair'): for rec in self.filtered(lambda l: l.delivery_policy == "repair"):
rec.qty_to_deliver = rec.qty_repaired - rec.qty_delivered - \ rec.qty_to_deliver = rec.qty_repaired - rec.qty_delivered - rec.qty_to_pay
rec.qty_to_pay
return res return res

View File

@@ -5,190 +5,211 @@ from odoo.tests import common
class TestRmaRepair(common.SingleTransactionCase): class TestRmaRepair(common.SingleTransactionCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TestRmaRepair, cls).setUpClass() super(TestRmaRepair, cls).setUpClass()
cls.rma_obj = cls.env['rma.order'] cls.rma_obj = cls.env["rma.order"]
cls.rma_line_obj = cls.env['rma.order.line'] cls.rma_line_obj = cls.env["rma.order.line"]
cls.rma_op = cls.env['rma.operation'] cls.rma_op = cls.env["rma.operation"]
cls.rma_add_invoice_wiz = cls.env['rma_add_invoice'] cls.rma_add_invoice_wiz = cls.env["rma_add_invoice"]
cls.rma_make_repair_wiz = cls.env['rma.order.line.make.repair'] cls.rma_make_repair_wiz = cls.env["rma.order.line.make.repair"]
cls.repair_line_obj = cls.env['repair.line'] cls.repair_line_obj = cls.env["repair.line"]
cls.acc_obj = cls.env['account.account'] cls.acc_obj = cls.env["account.account"]
cls.inv_obj = cls.env['account.invoice'] cls.inv_obj = cls.env["account.invoice"]
cls.invl_obj = cls.env['account.invoice.line'] cls.invl_obj = cls.env["account.invoice.line"]
cls.product_obj = cls.env['product.product'] cls.product_obj = cls.env["product.product"]
cls.partner_obj = cls.env['res.partner'] cls.partner_obj = cls.env["res.partner"]
cls.rma_route_cust = cls.env.ref('rma.route_rma_customer') cls.rma_route_cust = cls.env.ref("rma.route_rma_customer")
receivable_type = cls.env.ref('account.data_account_type_receivable') receivable_type = cls.env.ref("account.data_account_type_receivable")
# Create partners # Create partners
customer1 = cls.partner_obj.create({'name': 'Customer 1'}) customer1 = cls.partner_obj.create({"name": "Customer 1"})
# Create RMA group and operation: # Create RMA group and operation:
cls.rma_group_customer = cls.rma_obj.create({ cls.rma_group_customer = cls.rma_obj.create(
'partner_id': customer1.id, {"partner_id": customer1.id, "type": "customer"}
'type': 'customer', )
}) cls.operation_1 = cls.rma_op.create(
cls.operation_1 = cls.rma_op.create({ {
'code': 'TEST', "code": "TEST",
'name': 'Repair afer receive', "name": "Repair afer receive",
'type': 'customer', "type": "customer",
'receipt_policy': 'ordered', "receipt_policy": "ordered",
'repair_type': 'received', "repair_type": "received",
'in_route_id': cls.rma_route_cust.id, "in_route_id": cls.rma_route_cust.id,
'out_route_id': cls.rma_route_cust.id, "out_route_id": cls.rma_route_cust.id,
}) }
cls.operation_2 = cls.rma_op.create({ )
'code': 'TEST', cls.operation_2 = cls.rma_op.create(
'name': 'Repair on order', {
'type': 'customer', "code": "TEST",
'receipt_policy': 'ordered', "name": "Repair on order",
'repair_type': 'ordered', "type": "customer",
'in_route_id': cls.rma_route_cust.id, "receipt_policy": "ordered",
'out_route_id': cls.rma_route_cust.id, "repair_type": "ordered",
}) "in_route_id": cls.rma_route_cust.id,
cls.operation_3 = cls.rma_op.create({ "out_route_id": cls.rma_route_cust.id,
'code': 'TEST', }
'name': 'Deliver after repair', )
'type': 'customer', cls.operation_3 = cls.rma_op.create(
'receipt_policy': 'ordered', {
'repair_type': 'ordered', "code": "TEST",
'delivery_policy': 'repair', "name": "Deliver after repair",
'in_route_id': cls.rma_route_cust.id, "type": "customer",
'out_route_id': cls.rma_route_cust.id, "receipt_policy": "ordered",
}) "repair_type": "ordered",
"delivery_policy": "repair",
"in_route_id": cls.rma_route_cust.id,
"out_route_id": cls.rma_route_cust.id,
}
)
# Create products # Create products
cls.product_1 = cls.product_obj.create({ cls.product_1 = cls.product_obj.create(
'name': 'Test Product 1', {
'type': 'product', "name": "Test Product 1",
'list_price': 100.0, "type": "product",
'rma_customer_operation_id': cls.operation_1.id, "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', cls.product_2 = cls.product_obj.create(
'list_price': 150.0, {
'rma_customer_operation_id': cls.operation_2.id, "name": "Test Product 2",
}) "type": "product",
cls.product_3 = cls.product_obj.create({ "list_price": 150.0,
'name': 'Test Product 3', "rma_customer_operation_id": cls.operation_2.id,
'type': 'product', }
'list_price': 1.0, )
'rma_customer_operation_id': cls.operation_3.id, cls.product_3 = cls.product_obj.create(
}) {
"name": "Test Product 3",
"type": "product",
"list_price": 1.0,
"rma_customer_operation_id": cls.operation_3.id,
}
)
# Create Invoices: # Create Invoices:
customer_account = cls.acc_obj.search( customer_account = cls.acc_obj.search(
[('user_type_id', '=', receivable_type.id)], limit=1).id [("user_type_id", "=", receivable_type.id)], limit=1
cls.inv_customer = cls.inv_obj.create({ ).id
'partner_id': customer1.id, cls.inv_customer = cls.inv_obj.create(
'account_id': customer_account, {
'type': 'out_invoice', "partner_id": customer1.id,
}) "account_id": customer_account,
cls.inv_line_1 = cls.invl_obj.create({ "type": "out_invoice",
'name': cls.product_1.name, }
'product_id': cls.product_1.id, )
'quantity': 12.0, cls.inv_line_1 = cls.invl_obj.create(
'price_unit': 100.0, {
'invoice_id': cls.inv_customer.id, "name": cls.product_1.name,
'uom_id': cls.product_1.uom_id.id, "product_id": cls.product_1.id,
'account_id': customer_account, "quantity": 12.0,
}) "price_unit": 100.0,
cls.inv_line_2 = cls.invl_obj.create({ "invoice_id": cls.inv_customer.id,
'name': cls.product_2.name, "uom_id": cls.product_1.uom_id.id,
'product_id': cls.product_2.id, "account_id": customer_account,
'quantity': 15.0, }
'price_unit': 150.0, )
'invoice_id': cls.inv_customer.id, cls.inv_line_2 = cls.invl_obj.create(
'uom_id': cls.product_2.uom_id.id, {
'account_id': customer_account, "name": cls.product_2.name,
}) "product_id": cls.product_2.id,
cls.inv_customer2 = cls.inv_obj.create({ "quantity": 15.0,
'partner_id': customer1.id, "price_unit": 150.0,
'account_id': customer_account, "invoice_id": cls.inv_customer.id,
'type': 'out_invoice', "uom_id": cls.product_2.uom_id.id,
}) "account_id": customer_account,
cls.inv_line_3 = cls.invl_obj.create({ }
'name': cls.product_3.name, )
'product_id': cls.product_3.id, cls.inv_customer2 = cls.inv_obj.create(
'quantity': 1.0, {
'price_unit': 1000.0, "partner_id": customer1.id,
'invoice_id': cls.inv_customer2.id, "account_id": customer_account,
'uom_id': cls.product_3.uom_id.id, "type": "out_invoice",
'account_id': customer_account, }
}) )
cls.rma_group_customer_2 = cls.rma_obj.create({ cls.inv_line_3 = cls.invl_obj.create(
'partner_id': customer1.id, {
'type': 'customer', "name": cls.product_3.name,
}) "product_id": cls.product_3.id,
cls.bank_journal = cls.env['account.journal'].search( "quantity": 1.0,
[('type', '=', 'bank')], limit=1) "price_unit": 1000.0,
cls.material = cls.product_obj.create({ "invoice_id": cls.inv_customer2.id,
'name': 'Materials', "uom_id": cls.product_3.uom_id.id,
'type': 'product', "account_id": customer_account,
}) }
)
cls.rma_group_customer_2 = cls.rma_obj.create(
{"partner_id": customer1.id, "type": "customer"}
)
cls.bank_journal = cls.env["account.journal"].search(
[("type", "=", "bank")], limit=1
)
cls.material = cls.product_obj.create({"name": "Materials", "type": "product"})
cls.material.product_tmpl_id.standard_price = 10 cls.material.product_tmpl_id.standard_price = 10
cls.stock_location = cls.env.ref('stock.stock_location_stock') cls.stock_location = cls.env.ref("stock.stock_location_stock")
def test_01_add_from_invoice_customer(self): def test_01_add_from_invoice_customer(self):
"""Test wizard to create RMA from a customer invoice.""" """Test wizard to create RMA from a customer invoice."""
add_inv = self.rma_add_invoice_wiz.with_context({ add_inv = self.rma_add_invoice_wiz.with_context(
'customer': True, {
'active_ids': self.rma_group_customer.id, "customer": True,
'active_model': 'rma.order', "active_ids": self.rma_group_customer.id,
}).create({ "active_model": "rma.order",
'invoice_line_ids': }
[(6, 0, self.inv_customer.invoice_line_ids.ids)], ).create({"invoice_line_ids": [(6, 0, self.inv_customer.invoice_line_ids.ids)]})
})
add_inv.add_lines() add_inv.add_lines()
self.assertEqual(len(self.rma_group_customer.rma_line_ids), 2) self.assertEqual(len(self.rma_group_customer.rma_line_ids), 2)
rma_1 = self.rma_group_customer.rma_line_ids.filtered( rma_1 = self.rma_group_customer.rma_line_ids.filtered(
lambda r: r.product_id == self.product_1) lambda r: r.product_id == self.product_1
)
rma_1.repair_type = self.operation_1.repair_type rma_1.repair_type = self.operation_1.repair_type
self.assertEquals(rma_1.operation_id, self.operation_1, self.assertEquals(
"Operation should be operation_1") rma_1.operation_id, self.operation_1, "Operation should be operation_1"
)
rma_2 = self.rma_group_customer.rma_line_ids.filtered( rma_2 = self.rma_group_customer.rma_line_ids.filtered(
lambda r: r.product_id == self.product_2) lambda r: r.product_id == self.product_2
)
rma_2.repair_type = self.operation_2.repair_type rma_2.repair_type = self.operation_2.repair_type
self.assertEquals(rma_2.operation_id, self.operation_2, self.assertEquals(
"Operation should be operation_2") rma_2.operation_id, self.operation_2, "Operation should be operation_2"
)
def test_02_rma_repair_operation(self): def test_02_rma_repair_operation(self):
"""Test RMA quantities using repair operations.""" """Test RMA quantities using repair operations."""
# Received repair_type: # Received repair_type:
rma_1 = self.rma_group_customer.rma_line_ids.filtered( rma_1 = self.rma_group_customer.rma_line_ids.filtered(
lambda r: r.product_id == self.product_1) lambda r: r.product_id == self.product_1
self.assertEquals(rma_1.operation_id.repair_type, 'received', )
"Incorrect Repair operation") self.assertEquals(
self.assertEquals(rma_1.qty_to_repair, 0.0, rma_1.operation_id.repair_type, "received", "Incorrect Repair operation"
"Quantity to repair should be 0.0") )
self.assertEquals(rma_1.qty_to_repair, 0.0, "Quantity to repair should be 0.0")
# Ordered repair_type: # Ordered repair_type:
rma_2 = self.rma_group_customer.rma_line_ids.filtered( rma_2 = self.rma_group_customer.rma_line_ids.filtered(
lambda r: r.product_id == self.product_2) lambda r: r.product_id == self.product_2
self.assertEquals(rma_2.operation_id.repair_type, 'ordered', )
"Incorrect Repair operation") self.assertEquals(
rma_2.operation_id.repair_type, "ordered", "Incorrect Repair operation"
)
self.assertEqual(rma_2.qty_to_repair, 15.0) self.assertEqual(rma_2.qty_to_repair, 15.0)
def test_03_create_repair_order(self): def test_03_create_repair_order(self):
"""Generate a Repair Order from a customer RMA.""" """Generate a Repair Order from a customer RMA."""
rma = self.rma_group_customer.rma_line_ids.filtered( rma = self.rma_group_customer.rma_line_ids.filtered(
lambda r: r.product_id == self.product_2) lambda r: r.product_id == self.product_2
)
rma.action_rma_to_approve() rma.action_rma_to_approve()
rma.action_rma_approve() rma.action_rma_approve()
self.assertEqual(rma.repair_count, 0) self.assertEqual(rma.repair_count, 0)
self.assertEqual(rma.qty_to_repair, 15.0) self.assertEqual(rma.qty_to_repair, 15.0)
self.assertEqual(rma.qty_repaired, 0.0) self.assertEqual(rma.qty_repaired, 0.0)
make_repair = self.rma_make_repair_wiz.with_context({ make_repair = self.rma_make_repair_wiz.with_context(
'customer': True, {"customer": True, "active_ids": rma.ids, "active_model": "rma.order.line"}
'active_ids': rma.ids, ).create({"description": "Test refund"})
'active_model': 'rma.order.line',
}).create({
'description': 'Test refund',
})
make_repair.make_repair_order() make_repair.make_repair_order()
rma.repair_ids.action_repair_confirm() rma.repair_ids.action_repair_confirm()
self.assertEqual(rma.repair_count, 1) self.assertEqual(rma.repair_count, 1)
@@ -198,44 +219,44 @@ class TestRmaRepair(common.SingleTransactionCase):
def test_04_deliver_after_repair(self): def test_04_deliver_after_repair(self):
"""Only deliver after repair""" """Only deliver after repair"""
add_inv = self.rma_add_invoice_wiz.with_context({ add_inv = self.rma_add_invoice_wiz.with_context(
'customer': True, {
'active_ids': self.rma_group_customer_2.id, "customer": True,
'active_model': 'rma.order', "active_ids": self.rma_group_customer_2.id,
}).create({ "active_model": "rma.order",
'invoice_line_ids': }
[(6, 0, self.inv_customer2.invoice_line_ids.ids)], ).create(
}) {"invoice_line_ids": [(6, 0, self.inv_customer2.invoice_line_ids.ids)]}
)
add_inv.add_lines() add_inv.add_lines()
rma = self.rma_group_customer_2.rma_line_ids.filtered( rma = self.rma_group_customer_2.rma_line_ids.filtered(
lambda r: r.product_id == self.product_3) lambda r: r.product_id == self.product_3
)
rma.operation_id = self.operation_3.id rma.operation_id = self.operation_3.id
rma._onchange_operation_id() rma._onchange_operation_id()
rma.action_rma_to_approve() rma.action_rma_to_approve()
rma.action_rma_approve() rma.action_rma_approve()
self.assertEqual(rma.qty_to_deliver, 0.0) self.assertEqual(rma.qty_to_deliver, 0.0)
make_repair = self.rma_make_repair_wiz.with_context({ make_repair = self.rma_make_repair_wiz.with_context(
'customer': True, {"customer": True, "active_ids": rma.ids, "active_model": "rma.order.line"}
'active_ids': rma.ids, ).create({"description": "Test deliver"})
'active_model': 'rma.order.line',
}).create({
'description': 'Test deliver',
})
make_repair.make_repair_order() make_repair.make_repair_order()
repair = rma.repair_ids repair = rma.repair_ids
line = self.repair_line_obj.create({ line = self.repair_line_obj.create(
'name': 'consume stuff to repair', {
'repair_id': repair.id, "name": "consume stuff to repair",
'type': 'add', "repair_id": repair.id,
'product_id': self.material.id, "type": "add",
'product_uom': self.material.uom_id.id, "product_id": self.material.id,
'product_uom_qty': 1.0, "product_uom": self.material.uom_id.id,
'location_id': self.stock_location.id, "product_uom_qty": 1.0,
'location_dest_id': self.stock_location.id, "location_id": self.stock_location.id,
'price_unit': 10.0 "location_dest_id": self.stock_location.id,
}) "price_unit": 10.0,
}
)
line.onchange_product_id() line.onchange_product_id()
repair.invoice_method = 'after_repair' repair.invoice_method = "after_repair"
repair.action_repair_confirm() repair.action_repair_confirm()
repair.action_repair_start() repair.action_repair_start()
repair.action_repair_end() repair.action_repair_end()
@@ -244,6 +265,6 @@ class TestRmaRepair(common.SingleTransactionCase):
repair.invoice_id.action_invoice_open() repair.invoice_id.action_invoice_open()
self.assertEqual(rma.qty_to_deliver, 0.0) self.assertEqual(rma.qty_to_deliver, 0.0)
repair.invoice_id.pay_and_reconcile(self.bank_journal, 200.0) repair.invoice_id.pay_and_reconcile(self.bank_journal, 200.0)
self.assertEqual(repair.invoice_status, 'paid') self.assertEqual(repair.invoice_status, "paid")
self.assertEqual(rma.qty_to_pay, 0.0) self.assertEqual(rma.qty_to_pay, 0.0)
self.assertEqual(rma.qty_to_deliver, 1.0) self.assertEqual(rma.qty_to_deliver, 1.0)

View File

@@ -1,18 +1,21 @@
# Copyright 2017 Eficent Business and IT Consulting Services S.L. # Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0). # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).
import odoo.addons.decimal_precision as dp
from odoo import _, api, fields, models from odoo import _, api, fields, models
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
import odoo.addons.decimal_precision as dp
class RmaLineMakeRepair(models.TransientModel): class RmaLineMakeRepair(models.TransientModel):
_name = "rma.order.line.make.repair" _name = "rma.order.line.make.repair"
_description = "Make Repair Order from RMA Line" _description = "Make Repair Order from RMA Line"
item_ids = fields.One2many( item_ids = fields.One2many(
comodel_name='rma.order.line.make.repair.item', comodel_name="rma.order.line.make.repair.item",
inverse_name='wiz_id', string='Items') inverse_name="wiz_id",
string="Items",
)
@api.model @api.model
def _prepare_item(self, line): def _prepare_item(self, line):
@@ -22,56 +25,55 @@ class RmaLineMakeRepair(models.TransientModel):
else: else:
to_refurbish = refurbish_product_id = False to_refurbish = refurbish_product_id = False
return { return {
'line_id': line.id, "line_id": line.id,
'product_id': line.product_id.id, "product_id": line.product_id.id,
'product_qty': line.qty_to_repair, "product_qty": line.qty_to_repair,
'rma_id': line.rma_id.id, "rma_id": line.rma_id.id,
'out_route_id': line.out_route_id.id, "out_route_id": line.out_route_id.id,
'product_uom_id': line.uom_id.id, "product_uom_id": line.uom_id.id,
'partner_id': line.partner_id.id, "partner_id": line.partner_id.id,
'to_refurbish': to_refurbish, "to_refurbish": to_refurbish,
'refurbish_product_id': refurbish_product_id, "refurbish_product_id": refurbish_product_id,
'location_id': line.location_id.id, "location_id": line.location_id.id,
'location_dest_id': line.location_id.id, "location_dest_id": line.location_id.id,
'invoice_method': 'after_repair', "invoice_method": "after_repair",
} }
@api.model @api.model
def default_get(self, fields_list): def default_get(self, fields_list):
res = super(RmaLineMakeRepair, self).default_get( res = super(RmaLineMakeRepair, self).default_get(fields_list)
fields_list) rma_line_obj = self.env["rma.order.line"]
rma_line_obj = self.env['rma.order.line'] rma_line_ids = self.env.context["active_ids"] or []
rma_line_ids = self.env.context['active_ids'] or [] active_model = self.env.context["active_model"]
active_model = self.env.context['active_model']
if not rma_line_ids: if not rma_line_ids:
return res return res
assert active_model == 'rma.order.line', 'Bad context propagation' assert active_model == "rma.order.line", "Bad context propagation"
items = [] items = []
lines = rma_line_obj.browse(rma_line_ids) lines = rma_line_obj.browse(rma_line_ids)
for line in lines: for line in lines:
items.append([0, 0, self._prepare_item(line)]) items.append([0, 0, self._prepare_item(line)])
res['item_ids'] = items res["item_ids"] = items
return res return res
@api.multi @api.multi
def make_repair_order(self): def make_repair_order(self):
res = [] res = []
repair_obj = self.env['repair.order'] repair_obj = self.env["repair.order"]
for item in self.item_ids: for item in self.item_ids:
rma_line = item.line_id rma_line = item.line_id
data = item._prepare_repair_order(rma_line) data = item._prepare_repair_order(rma_line)
repair = repair_obj.create(data) repair = repair_obj.create(data)
res.append(repair.id) res.append(repair.id)
return { return {
'domain': [('id', 'in', res)], "domain": [("id", "in", res)],
'name': _('Repairs'), "name": _("Repairs"),
'view_type': 'form', "view_type": "form",
'view_mode': 'tree,form', "view_mode": "tree,form",
'res_model': 'repair.order', "res_model": "repair.order",
'view_id': False, "view_id": False,
'context': False, "context": False,
'type': 'ir.actions.act_window' "type": "ir.actions.act_window",
} }
@@ -79,13 +81,13 @@ class RmaLineMakeRepairItem(models.TransientModel):
_name = "rma.order.line.make.repair.item" _name = "rma.order.line.make.repair.item"
_description = "RMA Line Make Repair Item" _description = "RMA Line Make Repair Item"
@api.constrains('product_qty') @api.constrains("product_qty")
def _check_prodcut_qty(self): def _check_prodcut_qty(self):
for rec in self: for rec in self:
if rec.product_qty <= 0.0: if rec.product_qty <= 0.0:
raise ValidationError(_('Quantity must be positive.')) raise ValidationError(_("Quantity must be positive."))
@api.onchange('to_refurbish') @api.onchange("to_refurbish")
def _onchange_to_refurbish(self): def _onchange_to_refurbish(self):
if self.to_refurbish: if self.to_refurbish:
self.refurbish_product_id = self.product_id.refurbish_product_id self.refurbish_product_id = self.product_id.refurbish_product_id
@@ -93,50 +95,52 @@ class RmaLineMakeRepairItem(models.TransientModel):
self.refurbish_product_id = False self.refurbish_product_id = False
wiz_id = fields.Many2one( wiz_id = fields.Many2one(
comodel_name='rma.order.line.make.repair', string='Wizard', comodel_name="rma.order.line.make.repair", string="Wizard", ondelete="cascade"
ondelete='cascade',
) )
line_id = fields.Many2one( line_id = fields.Many2one(
comodel_name='rma.order.line', string='RMA', comodel_name="rma.order.line", string="RMA", required=True
required=True,
) )
rma_id = fields.Many2one( rma_id = fields.Many2one(
comodel_name='rma.order', related='line_id.rma_id', comodel_name="rma.order", related="line_id.rma_id", string="RMA Order"
string='RMA Order',
) )
product_id = fields.Many2one( product_id = fields.Many2one(
comodel_name='product.product', string='Product', readonly=True, comodel_name="product.product", string="Product", readonly=True
) )
product_qty = fields.Float( product_qty = fields.Float(
string='Quantity to repair', digits=dp.get_precision('Product UoS'), string="Quantity to repair", digits=dp.get_precision("Product UoS")
) )
product_uom_id = fields.Many2one( product_uom_id = fields.Many2one(
comodel_name='uom.uom', string='UoM', readonly=True, comodel_name="uom.uom", string="UoM", readonly=True
) )
out_route_id = fields.Many2one( out_route_id = fields.Many2one(
comodel_name='stock.location.route', string='Outbound Route', comodel_name="stock.location.route",
domain=[('rma_selectable', '=', True)], string="Outbound Route",
domain=[("rma_selectable", "=", True)],
) )
partner_id = fields.Many2one( partner_id = fields.Many2one(
comodel_name='res.partner', string='Customer', required=False, comodel_name="res.partner",
domain=[('customer', '=', True)], readonly=True, string="Customer",
required=False,
domain=[("customer", "=", True)],
readonly=True,
) )
location_id = fields.Many2one( location_id = fields.Many2one(
comodel_name="stock.location", string="Location", required=True, comodel_name="stock.location", string="Location", required=True
) )
location_dest_id = fields.Many2one( location_dest_id = fields.Many2one(
comodel_name="stock.location", string="Destination location", comodel_name="stock.location", string="Destination location", required=True
required=True,
) )
to_refurbish = fields.Boolean(string="To Refurbish?") to_refurbish = fields.Boolean(string="To Refurbish?")
refurbish_product_id = fields.Many2one( refurbish_product_id = fields.Many2one(
comodel_name="product.product", string="Refurbished Product", comodel_name="product.product", string="Refurbished Product"
) )
invoice_method = fields.Selection( invoice_method = fields.Selection(
string="Invoice Method", selection=[ string="Invoice Method",
selection=[
("none", "No Invoice"), ("none", "No Invoice"),
("b4repair", "Before Repair"), ("b4repair", "Before Repair"),
("after_repair", "After Repair")], ("after_repair", "After Repair"),
],
required=True, required=True,
help="Selecting 'Before Repair' or 'After Repair' will allow you " help="Selecting 'Before Repair' or 'After Repair' will allow you "
"to generate invoice before or after the repair is done " "to generate invoice before or after the repair is done "
@@ -146,27 +150,30 @@ class RmaLineMakeRepairItem(models.TransientModel):
@api.model @api.model
def _prepare_repair_order(self, rma_line): def _prepare_repair_order(self, rma_line):
location_dest = (self.location_dest_id if not self.to_refurbish else location_dest = (
rma_line.product_id.property_stock_refurbish) self.location_dest_id
refurbish_location_dest_id = (self.location_dest_id.id if if not self.to_refurbish
self.to_refurbish else False) else rma_line.product_id.property_stock_refurbish
addr = rma_line.partner_id.address_get(['delivery', 'invoice']) )
refurbish_location_dest_id = (
self.location_dest_id.id if self.to_refurbish else False
)
addr = rma_line.partner_id.address_get(["delivery", "invoice"])
return { return {
'product_id': rma_line.product_id.id, "product_id": rma_line.product_id.id,
'partner_id': rma_line.partner_id.id, "partner_id": rma_line.partner_id.id,
'pricelist_id': rma_line.partner_id.property_product_pricelist.id "pricelist_id": rma_line.partner_id.property_product_pricelist.id or False,
or False, "product_qty": self.product_qty,
'product_qty': self.product_qty, "rma_line_id": rma_line.id,
'rma_line_id': rma_line.id, "product_uom": rma_line.product_id.uom_po_id.id,
'product_uom': rma_line.product_id.uom_po_id.id, "company_id": rma_line.company_id.id,
'company_id': rma_line.company_id.id, "location_id": self.location_id.id,
'location_id': self.location_id.id, "location_dest_id": location_dest.id,
'location_dest_id': location_dest.id, "refurbish_location_dest_id": refurbish_location_dest_id,
'refurbish_location_dest_id': refurbish_location_dest_id, "refurbish_product_id": self.refurbish_product_id.id,
'refurbish_product_id': self.refurbish_product_id.id, "to_refurbish": self.to_refurbish,
'to_refurbish': self.to_refurbish, "invoice_method": self.invoice_method,
'invoice_method': self.invoice_method, "address_id": addr["delivery"],
'address_id': addr['delivery'], "partner_invoice_id": addr["invoice"],
'partner_invoice_id': addr['invoice'], "lot_id": rma_line.lot_id.id,
'lot_id': rma_line.lot_id.id,
} }