From 723212b57ebda7b9fa2eb35f6f1014b6c4ea5348 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Thu, 19 Mar 2020 15:43:10 +0100 Subject: [PATCH] [MIG]rma_repair to v13 --- rma_repair/__init__.py | 3 +- rma_repair/__manifest__.py | 10 +- rma_repair/models/repair.py | 8 +- rma_repair/models/rma_operation.py | 4 +- rma_repair/models/rma_order.py | 8 +- rma_repair/models/rma_order_line.py | 19 +-- rma_repair/tests/test_rma_repair.py | 142 +++++++++--------- rma_repair/wizards/__init__.py | 3 +- .../wizards/rma_order_line_make_repair.py | 12 +- .../rma_order_line_make_repair_view.xml | 3 - 10 files changed, 99 insertions(+), 113 deletions(-) diff --git a/rma_repair/__init__.py b/rma_repair/__init__.py index 32915a6d..8051eeb4 100644 --- a/rma_repair/__init__.py +++ b/rma_repair/__init__.py @@ -1,4 +1,5 @@ -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +# Copyright 2020 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import models from . import wizards diff --git a/rma_repair/__manifest__.py b/rma_repair/__manifest__.py index 912bd2e9..73341db5 100644 --- a/rma_repair/__manifest__.py +++ b/rma_repair/__manifest__.py @@ -1,13 +1,12 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) - +# Copyright 2020 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "RMA Repair", - "version": "12.0.1.2.0", + "version": "13.0.1.0.0", "license": "LGPL-3", "category": "RMA", "summary": "Links RMA with Repairs.", - "author": "Eficent, Odoo Community Association (OCA)", + "author": "ForgeFlow S.L., Odoo Community Association (OCA)", "website": "https://github.com/Eficent/stock-rma", "depends": ["rma_account", "repair_refurbish"], "data": [ @@ -19,5 +18,4 @@ "data/repair_sequence.xml", ], "installable": True, - "auto_install": True, } diff --git a/rma_repair/models/repair.py b/rma_repair/models/repair.py index 9aafdb0b..f247bf7d 100644 --- a/rma_repair/models/repair.py +++ b/rma_repair/models/repair.py @@ -1,5 +1,5 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +# Copyright 2020 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import fields, models @@ -13,4 +13,6 @@ class RepairOrder(models.Model): under_warranty = fields.Boolean( related="rma_line_id.under_warranty", readonly=False ) - invoice_status = fields.Selection(related="invoice_id.state") + invoice_status = fields.Selection( + related="invoice_id.state", string="Invoice Status" + ) diff --git a/rma_repair/models/rma_operation.py b/rma_repair/models/rma_operation.py index 464f3893..c2ee3dd1 100644 --- a/rma_repair/models/rma_operation.py +++ b/rma_repair/models/rma_operation.py @@ -1,5 +1,5 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +# Copyright 2020 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import fields, models diff --git a/rma_repair/models/rma_order.py b/rma_repair/models/rma_order.py index 8a5de370..6e24b994 100644 --- a/rma_repair/models/rma_order.py +++ b/rma_repair/models/rma_order.py @@ -1,13 +1,12 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +# Copyright 2020 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import api, fields, models +from odoo import fields, models class RmaOrder(models.Model): _inherit = "rma.order" - @api.multi def _compute_repair_count(self): for rma in self: repairs = rma.mapped("rma_line_ids.repair_ids") @@ -17,7 +16,6 @@ class RmaOrder(models.Model): compute="_compute_repair_count", string="# of Repairs" ) - @api.multi def action_view_repair_order(self): action = self.env.ref("repair.action_repair_order_tree") result = action.read()[0] diff --git a/rma_repair/models/rma_order_line.py b/rma_repair/models/rma_order_line.py index 4394921f..466f38fb 100644 --- a/rma_repair/models/rma_order_line.py +++ b/rma_repair/models/rma_order_line.py @@ -1,10 +1,8 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +# Copyright 2020 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import api, fields, models -from odoo.addons import decimal_precision as dp - class RmaOrderLine(models.Model): _inherit = "rma.order.line" @@ -49,7 +47,7 @@ class RmaOrderLine(models.Model): qty_to_repair = fields.Float( string="Qty To Repair", copy=False, - digits=dp.get_precision("Product Unit of Measure"), + digits="Product Unit of Measure", readonly=True, compute="_compute_qty_to_repair", store=True, @@ -57,7 +55,7 @@ class RmaOrderLine(models.Model): qty_under_repair = fields.Float( string="Qty Under Repair", copy=False, - digits=dp.get_precision("Product Unit of Measure"), + digits="Product Unit of Measure", readonly=True, compute="_compute_qty_under_repair", store=True, @@ -65,7 +63,7 @@ class RmaOrderLine(models.Model): qty_repaired = fields.Float( string="Qty Repaired", copy=False, - digits=dp.get_precision("Product Unit of Measure"), + digits="Product Unit of Measure", readonly=True, compute="_compute_qty_repaired", store=True, @@ -91,7 +89,6 @@ class RmaOrderLine(models.Model): qty_to_pay = fields.Float(compute="_compute_qty_to_pay") qty_to_deliver = fields.Float(compute="_compute_qty_to_deliver") - @api.multi @api.depends( "delivery_policy", "product_qty", @@ -106,12 +103,11 @@ class RmaOrderLine(models.Model): for rec in self.filtered(lambda l: l.delivery_policy == "repair"): qty_to_pay = 0.0 for repair in rec.repair_ids.filtered( - lambda r: r.invoice_method != "none" and r.invoice_status != "paid" + lambda r: r.invoice_method != "none" and r.invoice_status != "posted" ): qty_to_pay += repair.product_qty rec.qty_to_pay = qty_to_pay - @api.multi def action_view_repair_order(self): action = self.env.ref("repair.action_repair_order_tree") result = action.read()[0] @@ -124,7 +120,6 @@ class RmaOrderLine(models.Model): result["res_id"] = repair_ids[0] return result - @api.multi def _get_rma_repaired_qty(self): self.ensure_one() qty = 0.0 @@ -135,7 +130,6 @@ class RmaOrderLine(models.Model): qty += repair_qty return qty - @api.multi def _get_rma_under_repair_qty(self): self.ensure_one() qty = 0.0 @@ -155,7 +149,6 @@ class RmaOrderLine(models.Model): self.repair_type = self.operation_id.repair_type or "no" return result - @api.multi @api.depends( "move_ids", "move_ids.state", diff --git a/rma_repair/tests/test_rma_repair.py b/rma_repair/tests/test_rma_repair.py index 9539540b..9068090a 100644 --- a/rma_repair/tests/test_rma_repair.py +++ b/rma_repair/tests/test_rma_repair.py @@ -1,6 +1,7 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +# Copyright 2020 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import fields from odoo.tests import common @@ -12,24 +13,23 @@ class TestRmaRepair(common.SingleTransactionCase): 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_add_invoice_wiz = cls.env["rma_add_account_move"] cls.rma_make_repair_wiz = cls.env["rma.order.line.make.repair"] cls.repair_line_obj = cls.env["repair.line"] cls.acc_obj = cls.env["account.account"] - cls.inv_obj = cls.env["account.invoice"] - cls.invl_obj = cls.env["account.invoice.line"] + cls.inv_obj = cls.env["account.move"] + cls.invl_obj = cls.env["account.move.line"] cls.product_obj = cls.env["product.product"] cls.partner_obj = cls.env["res.partner"] - + cls.acc_bank_stmt_model = cls.env["account.bank.statement"] 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"}) + cls.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"} + {"partner_id": cls.customer1.id, "type": "customer"} ) cls.operation_1 = cls.rma_op.create( { @@ -91,58 +91,59 @@ class TestRmaRepair(common.SingleTransactionCase): } ) # 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, - } - ) - cls.inv_customer2 = cls.inv_obj.create( - { - "partner_id": customer1.id, - "account_id": customer_account, - "type": "out_invoice", - } - ) - cls.inv_line_3 = cls.invl_obj.create( - { - "name": cls.product_3.name, - "product_id": cls.product_3.id, - "quantity": 1.0, - "price_unit": 1000.0, - "invoice_id": cls.inv_customer2.id, - "uom_id": cls.product_3.uom_id.id, - "account_id": customer_account, - } + + cls.company_id = cls.env.user.company_id + cls.currency_id = cls.company_id.currency_id + + cls.inv_customer = cls.env["account.move"].create( + [ + { + "type": "out_invoice", + "partner_id": cls.customer1.id, + "invoice_date": fields.Date.from_string("2016-01-01"), + "currency_id": cls.currency_id.id, + "invoice_line_ids": [ + ( + 0, + None, + { + "product_id": cls.product_1.id, + "product_uom_id": cls.product_1.uom_id.id, + "quantity": 12, + "price_unit": 1000, + }, + ), + ( + 0, + None, + { + "product_id": cls.product_2.id, + "product_uom_id": cls.product_2.uom_id.id, + "quantity": 15.0, + "price_unit": 150.0, + }, + ), + ( + 0, + None, + { + "product_id": cls.product_3.id, + "product_uom_id": cls.product_3.uom_id.id, + "quantity": 1, + "price_unit": 1000, + }, + ), + ], + } + ] ) + + cls.inv_line_1 = cls.inv_customer.invoice_line_ids[0] + cls.inv_line_2 = cls.inv_customer.invoice_line_ids[1] + cls.inv_line_3 = cls.inv_customer.invoice_line_ids[2] + cls.rma_group_customer_2 = cls.rma_obj.create( - {"partner_id": customer1.id, "type": "customer"} + {"partner_id": cls.customer1.id, "type": "customer"} ) cls.bank_journal = cls.env["account.journal"].search( [("type", "=", "bank")], limit=1 @@ -160,9 +161,9 @@ class TestRmaRepair(common.SingleTransactionCase): "active_ids": self.rma_group_customer.id, "active_model": "rma.order", } - ).create({"invoice_line_ids": [(6, 0, self.inv_customer.invoice_line_ids.ids)]}) + ).create({"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) + self.assertEqual(len(self.rma_group_customer.rma_line_ids), 3) rma_1 = self.rma_group_customer.rma_line_ids.filtered( lambda r: r.product_id == self.product_1 ) @@ -209,7 +210,7 @@ class TestRmaRepair(common.SingleTransactionCase): 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"}) + ).new() make_repair.make_repair_order() rma.repair_ids.action_repair_confirm() self.assertEqual(rma.repair_count, 1) @@ -225,9 +226,7 @@ class TestRmaRepair(common.SingleTransactionCase): "active_ids": self.rma_group_customer_2.id, "active_model": "rma.order", } - ).create( - {"invoice_line_ids": [(6, 0, self.inv_customer2.invoice_line_ids.ids)]} - ) + ).create({"line_ids": [(6, 0, self.inv_customer.invoice_line_ids.ids)]}) add_inv.add_lines() rma = self.rma_group_customer_2.rma_line_ids.filtered( lambda r: r.product_id == self.product_3 @@ -239,7 +238,7 @@ class TestRmaRepair(common.SingleTransactionCase): self.assertEqual(rma.qty_to_deliver, 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 deliver"}) + ).new() make_repair.make_repair_order() repair = rma.repair_ids line = self.repair_line_obj.create( @@ -262,9 +261,12 @@ class TestRmaRepair(common.SingleTransactionCase): repair.action_repair_end() repair.action_repair_invoice_create() self.assertEqual(rma.qty_repaired, 1.0) - repair.invoice_id.action_invoice_open() self.assertEqual(rma.qty_to_deliver, 0.0) - repair.invoice_id.pay_and_reconcile(self.bank_journal, 200.0) - self.assertEqual(repair.invoice_status, "paid") + repair.invoice_id.post() + + repair.invoice_id.action_invoice_register_payment() + self.assertEqual(repair.invoice_status, "posted") self.assertEqual(rma.qty_to_pay, 0.0) - self.assertEqual(rma.qty_to_deliver, 1.0) + self.assertEqual(rma.qty_repaired, 1.0) + self.assertEqual(rma.delivery_policy, "repair") + self.assertEqual(rma.qty_delivered, 0.0) diff --git a/rma_repair/wizards/__init__.py b/rma_repair/wizards/__init__.py index 29cb35b3..9a165090 100644 --- a/rma_repair/wizards/__init__.py +++ b/rma_repair/wizards/__init__.py @@ -1,3 +1,4 @@ -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +# Copyright 2020 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import rma_order_line_make_repair diff --git a/rma_repair/wizards/rma_order_line_make_repair.py b/rma_repair/wizards/rma_order_line_make_repair.py index 569941e1..f016d38e 100644 --- a/rma_repair/wizards/rma_order_line_make_repair.py +++ b/rma_repair/wizards/rma_order_line_make_repair.py @@ -1,11 +1,9 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. -# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0). +# Copyright 2020 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import _, api, fields, models from odoo.exceptions import ValidationError -import odoo.addons.decimal_precision as dp - class RmaLineMakeRepair(models.TransientModel): _name = "rma.order.line.make.repair" @@ -56,7 +54,6 @@ class RmaLineMakeRepair(models.TransientModel): res["item_ids"] = items return res - @api.multi def make_repair_order(self): res = [] repair_obj = self.env["repair.order"] @@ -68,7 +65,6 @@ class RmaLineMakeRepair(models.TransientModel): return { "domain": [("id", "in", res)], "name": _("Repairs"), - "view_type": "form", "view_mode": "tree,form", "res_model": "repair.order", "view_id": False, @@ -106,9 +102,7 @@ class RmaLineMakeRepairItem(models.TransientModel): product_id = fields.Many2one( comodel_name="product.product", string="Product", readonly=True ) - product_qty = fields.Float( - string="Quantity to repair", digits=dp.get_precision("Product UoS") - ) + product_qty = fields.Float(string="Quantity to repair", digits="Product UoS") product_uom_id = fields.Many2one( comodel_name="uom.uom", string="UoM", readonly=True ) diff --git a/rma_repair/wizards/rma_order_line_make_repair_view.xml b/rma_repair/wizards/rma_order_line_make_repair_view.xml index 529f4e15..8d5cfb99 100644 --- a/rma_repair/wizards/rma_order_line_make_repair_view.xml +++ b/rma_repair/wizards/rma_order_line_make_repair_view.xml @@ -1,6 +1,4 @@ - @@ -43,7 +41,6 @@ Create Repair ir.actions.act_window rma.order.line.make.repair - form form new