From 54e08e856fd2f8d07057eef3ca12b2d395fcfb23 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 29 Aug 2023 20:24:09 +0200 Subject: [PATCH] [MIG] rma_sale: Migration to 16.0 - Standard procedure. - Adapt to new `prepare_*_vals` methods. - Renamed fields adaptation. - Improved test coverage. TT44214 s --- rma_sale/README.rst | 14 ++--- rma_sale/__manifest__.py | 5 +- rma_sale/models/rma.py | 51 +++++++--------- rma_sale/static/description/index.html | 8 +-- rma_sale/tests/test_rma_sale.py | 59 +++++++++++++------ rma_sale/views/rma_views.xml | 6 +- rma_sale/views/sale_views.xml | 3 +- rma_sale/wizard/sale_order_rma_wizard.py | 2 +- .../wizard/sale_order_rma_wizard_views.xml | 2 +- 9 files changed, 86 insertions(+), 64 deletions(-) diff --git a/rma_sale/README.rst b/rma_sale/README.rst index a867b0a7..180d9c4e 100644 --- a/rma_sale/README.rst +++ b/rma_sale/README.rst @@ -14,14 +14,14 @@ Return Merchandise Authorization Management - Link with Sales :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frma-lightgray.png?logo=github - :target: https://github.com/OCA/rma/tree/15.0/rma_sale + :target: https://github.com/OCA/rma/tree/16.0/rma_sale :alt: OCA/rma .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/rma-15-0/rma-15-0-rma_sale + :target: https://translation.odoo-community.org/projects/rma-16-0/rma-16-0-rma_sale :alt: Translate me on Weblate -.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/145/15.0 - :alt: Try me on Runbot +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/rma&target_branch=16.0 + :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -79,7 +79,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -125,6 +125,6 @@ Current `maintainer `__: |maintainer-ernestotejeda| -This module is part of the `OCA/rma `_ project on GitHub. +This module is part of the `OCA/rma `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index 507cd8d6..3642eed0 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -1,9 +1,12 @@ # Copyright 2020 Tecnativa - Ernesto Tejeda +# Copyright 2022-2023 Tecnativa - Víctor Martínez +# Copyright 2021-2023 Tecnativa - David Vidal +# Copyright 2021-2023 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Return Merchandise Authorization Management - Link with Sales", "summary": "Sale Order - Return Merchandise Authorization (RMA)", - "version": "15.0.1.2.0", + "version": "16.0.1.0.0", "development_status": "Production/Stable", "category": "RMA", "website": "https://github.com/OCA/rma", diff --git a/rma_sale/models/rma.py b/rma_sale/models/rma.py index 31b3254e..b07b7151 100644 --- a/rma_sale/models/rma.py +++ b/rma_sale/models/rma.py @@ -16,8 +16,9 @@ class Rma(models.Model): " ('partner_id', 'child_of', commercial_partner_id)," " ('state', 'in', ['sale', 'done'])," "]", - readonly=True, - states={"draft": [("readonly", False)]}, + store=True, + readonly=False, + compute="_compute_order_id", ) allowed_picking_ids = fields.Many2many( comodel_name="stock.picking", @@ -28,7 +29,7 @@ class Rma(models.Model): "[('state', '=', 'done'), ('picking_type_id.code', '=', 'outgoing')] " ) allowed_move_ids = fields.Many2many( - comodel_name="sale.order.line", + comodel_name="stock.move", compute="_compute_allowed_move_ids", ) move_id = fields.Many2one(domain="[('id', 'in', allowed_move_ids)]") @@ -70,7 +71,7 @@ class Rma(models.Model): lambda r: r.picking_id == self.picking_id and r.state == "done" ).ids else: - rec.allowed_move_ids = self.picking_id.move_lines.ids + rec.allowed_move_ids = self.picking_id.move_ids.ids @api.depends("order_id") def _compute_allowed_product_ids(self): @@ -83,11 +84,10 @@ class Rma(models.Model): else: rec.allowed_product_ids = False # don't populate a big list - @api.onchange("partner_id") - def _onchange_partner_id(self): - res = super()._onchange_partner_id() + @api.depends("partner_id") + def _compute_order_id(self): + """Empty sales order when changing partner.""" self.order_id = False - return res @api.onchange("order_id") def _onchange_order_id(self): @@ -132,36 +132,25 @@ class Rma(models.Model): rma._link_refund_with_reception_move() return res - def _prepare_refund(self, invoice_form, origin): + def _prepare_refund_vals(self, origin=False): """Inject salesman from sales order (if any)""" - res = super()._prepare_refund(invoice_form, origin) + vals = super()._prepare_refund_vals(origin=origin) if self.order_id: - invoice_form.invoice_user_id = self.order_id.user_id - return res + vals["invoice_user_id"] = self.order_id.user_id.id + return vals - def _get_refund_line_price_unit(self): - """Get the sale order price unit""" - if self.sale_line_id: - return self.sale_line_id.price_unit - return super()._get_refund_line_price_unit() - - def _get_refund_line_product(self): - """To be overriden in a third module with the proper origin values - in case a kit is linked with the rma""" - if not self.sale_line_id: - return super()._get_refund_line_product() - return self.sale_line_id.product_id - - def _prepare_refund_line(self, line_form): + def _prepare_refund_line_vals(self): """Add line data and link to the sales order, only if the RMA is for the whole move quantity. In other cases, incorrect delivered/invoiced quantities will be logged on the sales order, so better to let the operations not linked. """ - res = super()._prepare_refund_line(line_form) + vals = super()._prepare_refund_line_vals() line = self.sale_line_id if line: - line_form.discount = line.discount - line_form.sequence = line.sequence + vals["product_id"] = line.product_id.id + vals["price_unit"] = line.price_unit + vals["discount"] = line.discount + vals["sequence"] = line.sequence move = self.reception_move_id if ( move @@ -172,5 +161,5 @@ class Rma(models.Model): ) == 0 ): - line_form.sale_line_ids.add(line) - return res + vals["sale_line_ids"] = [(4, line.id)] + return vals diff --git a/rma_sale/static/description/index.html b/rma_sale/static/description/index.html index 74d1706f..7aff80c2 100644 --- a/rma_sale/static/description/index.html +++ b/rma_sale/static/description/index.html @@ -3,7 +3,7 @@ - + Return Merchandise Authorization Management - Link with Sales