From 79c27f0acfe6e49fb915a75e0de67f02a3e11394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Vall=C3=A9s=20Fuster?= Date: Mon, 6 May 2024 16:14:19 +0200 Subject: [PATCH] [MIG] rma_purchase: Migration to v17 --- rma_purchase/__manifest__.py | 2 +- rma_purchase/models/account_move.py | 8 +++---- rma_purchase/models/purchase_order.py | 2 +- rma_purchase/models/purchase_order_line.py | 24 +++++++++---------- rma_purchase/models/rma_order_line.py | 10 ++++---- rma_purchase/tests/test_rma_purchase.py | 2 +- .../tests/test_rma_stock_account_purchase.py | 2 +- rma_purchase/views/rma_order_line_view.xml | 18 +++++++------- rma_purchase/wizards/rma_add_purchase.py | 2 +- rma_purchase/wizards/rma_make_picking.py | 4 ++-- .../rma_order_line_make_purchase_order.py | 4 ++-- rma_purchase/wizards/rma_refund.py | 4 ++-- 12 files changed, 38 insertions(+), 44 deletions(-) diff --git a/rma_purchase/__manifest__.py b/rma_purchase/__manifest__.py index 1e54be81c..8c7aa9dd2 100644 --- a/rma_purchase/__manifest__.py +++ b/rma_purchase/__manifest__.py @@ -2,7 +2,7 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) { "name": "RMA Purchase", - "version": "16.0.1.0.0", + "version": "17.0.1.0.0", "category": "RMA", "summary": "RMA from PO", "license": "LGPL-3", diff --git a/rma_purchase/models/account_move.py b/rma_purchase/models/account_move.py index c173139fd..8b0230906 100644 --- a/rma_purchase/models/account_move.py +++ b/rma_purchase/models/account_move.py @@ -8,15 +8,15 @@ class AccountMove(models.Model): _inherit = "account.move" def _prepare_invoice_line_from_rma_line(self, line): - data = super(AccountMove, self)._prepare_invoice_line_from_rma_line(line) + data = super()._prepare_invoice_line_from_rma_line(line) if line.purchase_order_line_id: - data["purchase_line_id"]: line.purchase_order_line_id.id + data["purchase_line_id"] = line.purchase_order_line_id.id return data def action_post(self): - res = super(AccountMove, self).action_post() + res = super().action_post() for move in self: - rma_mls = move.line_ids.filtered(lambda l: l.rma_line_id) + rma_mls = move.line_ids.filtered(lambda x: x.rma_line_id) if rma_mls: # Try to reconcile the interim accounts for RMA lines rmas = rma_mls.mapped("rma_line_id") diff --git a/rma_purchase/models/purchase_order.py b/rma_purchase/models/purchase_order.py index 4d81bc049..0ab65155f 100644 --- a/rma_purchase/models/purchase_order.py +++ b/rma_purchase/models/purchase_order.py @@ -10,7 +10,7 @@ class PurchaseOrder(models.Model): @api.model def new(self, vals, origin=None, ref=None): """Allows to propose a line based on the RMA information.""" - res = super(PurchaseOrder, self).new(vals) + res = super().new(vals) rma_line_id = self.env.context.get("rma_line_id") if rma_line_id: rma_line = self.env["rma.order.line"].browse(rma_line_id) diff --git a/rma_purchase/models/purchase_order_line.py b/rma_purchase/models/purchase_order_line.py index 4962d8617..6459e1c1d 100644 --- a/rma_purchase/models/purchase_order_line.py +++ b/rma_purchase/models/purchase_order_line.py @@ -22,16 +22,14 @@ def name_search(self, name="", args=None, operator="ilike", limit=100): (self._rec_name, operator, name), ("order_id.name", operator, name), ] - return super(PurchaseOrderLine, self).name_search( - name=name, args=args, operator=operator, limit=limit - ) + return super().name_search(name=name, args=args, operator=operator, limit=limit) @api.model def _name_search( self, name="", args=None, operator="ilike", limit=100, name_get_uid=None ): """Typed text is cleared here for better extensibility.""" - return super(PurchaseOrderLine, self)._name_search( + return super()._name_search( name="", args=args, operator=operator, @@ -50,8 +48,7 @@ def name_get(self): res.append( ( purchase.id, - "%s %s %s qty:%s" - % ( + "{} {} {} qty:{}".format( purchase.order_id.name, " ".join( str(x) @@ -68,11 +65,12 @@ def name_get(self): res.append(super(PurchaseOrderLine, purchase).name_get()[0]) return res else: - return super(PurchaseOrderLine, self).name_get() + return super().name_get() - @api.model - def create(self, vals): - rma_line_id = self.env.context.get("rma_line_id") - if rma_line_id: - vals["rma_line_id"] = rma_line_id - return super(PurchaseOrderLine, self).create(vals) + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + rma_line_id = self.env.context.get("rma_line_id") + if rma_line_id: + vals["rma_line_id"] = rma_line_id + return super().create(vals_list) diff --git a/rma_purchase/models/rma_order_line.py b/rma_purchase/models/rma_order_line.py index a2e1aea4f..79edccf9b 100644 --- a/rma_purchase/models/rma_order_line.py +++ b/rma_purchase/models/rma_order_line.py @@ -43,8 +43,6 @@ def _compute_qty_purchase(self): comodel_name="purchase.order.line", string="Originating Purchase Line", ondelete="restrict", - readonly=True, - states={"draft": [("readonly", False)]}, ) purchase_id = fields.Many2one( string="Source Purchase Order", @@ -92,7 +90,7 @@ def _compute_qty_purchase(self): def _onchange_product_id(self): """Domain for purchase_order_line_id is computed here to make it dynamic.""" - res = super(RmaOrderLine, self)._onchange_product_id() + res = super()._onchange_product_id() if not res.get("domain"): res["domain"] = {} domain = [ @@ -107,7 +105,7 @@ def _onchange_product_id(self): @api.onchange("operation_id") def _onchange_operation_id(self): - res = super(RmaOrderLine, self)._onchange_operation_id() + res = super()._onchange_operation_id() if self.operation_id: self.purchase_policy = self.operation_id.purchase_policy or "no" return res @@ -202,7 +200,7 @@ def _check_purchase_partner(self): ) def _remove_other_data_origin(self, exception): - res = super(RmaOrderLine, self)._remove_other_data_origin(exception) + res = super()._remove_other_data_origin(exception) if not exception == "purchase_order_line_id": self.purchase_order_line_id = False return res @@ -233,7 +231,7 @@ def _get_rma_purchased_qty(self): def _get_price_unit(self): self.ensure_one() - price_unit = super(RmaOrderLine, self)._get_price_unit() + price_unit = super()._get_price_unit() if self.purchase_order_line_id: moves = self.purchase_order_line_id.move_ids if moves: diff --git a/rma_purchase/tests/test_rma_purchase.py b/rma_purchase/tests/test_rma_purchase.py index 558d23894..8b4f546fa 100644 --- a/rma_purchase/tests/test_rma_purchase.py +++ b/rma_purchase/tests/test_rma_purchase.py @@ -7,7 +7,7 @@ class TestRmaPurchase(common.TransactionCase): def setUp(self): - super(TestRmaPurchase, self).setUp() + super().setUp() self.rma_obj = self.env["rma.order"] self.rma_line_obj = self.env["rma.order.line"] diff --git a/rma_purchase/tests/test_rma_stock_account_purchase.py b/rma_purchase/tests/test_rma_stock_account_purchase.py index c74842f2d..dec9dfc60 100644 --- a/rma_purchase/tests/test_rma_stock_account_purchase.py +++ b/rma_purchase/tests/test_rma_stock_account_purchase.py @@ -11,7 +11,7 @@ class TestRmaStockAccountPurchase(TestRmaStockAccount): @classmethod def setUpClass(cls): - super(TestRmaStockAccountPurchase, cls).setUpClass() + super().setUpClass() cls.pol_model = cls.env["purchase.order.line"] cls.po_model = cls.env["purchase.order"] cls.rma_operation_supplier_refund = cls.env.ref( diff --git a/rma_purchase/views/rma_order_line_view.xml b/rma_purchase/views/rma_order_line_view.xml index 6563cabd4..ab839d017 100644 --- a/rma_purchase/views/rma_order_line_view.xml +++ b/rma_purchase/views/rma_order_line_view.xml @@ -18,15 +18,15 @@ name="%(action_rma_order_line_make_purchase_order)d" string="Create Purchase Order" class="oe_highlight" - attrs="{'invisible':['|', ('qty_to_purchase', '=', 0), ('state', '!=', 'approved')]}" - context="{'rma_line_id': active_id, 'default_partner_id': partner_id}" + invisible="qty_to_purchase == 0 or state != 'approved'" + context="{'rma_line_id': id, 'default_partner_id': partner_id}" type="action" />