Skip to content

Commit

Permalink
[MIG] rma_sale: Migration to 16.0
Browse files Browse the repository at this point in the history
- Standard procedure.
- Adapt to new `prepare_*_vals` methods.
- Renamed fields adaptation.

TT44214
  • Loading branch information
pedrobaeza committed Aug 29, 2023
1 parent 0a71d84 commit 3bfe02e
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 61 deletions.
14 changes: 7 additions & 7 deletions rma_sale/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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|

Expand Down Expand Up @@ -79,7 +79,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/rma/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 <https://github.com/OCA/rma/issues/new?body=module:%20rma_sale%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/rma/issues/new?body=module:%20rma_sale%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -125,6 +125,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ernestotejeda|

This module is part of the `OCA/rma <https://github.com/OCA/rma/tree/15.0/rma_sale>`_ project on GitHub.
This module is part of the `OCA/rma <https://github.com/OCA/rma/tree/16.0/rma_sale>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 4 additions & 1 deletion rma_sale/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
49 changes: 19 additions & 30 deletions rma_sale/models/rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -70,7 +71,7 @@ def _compute_allowed_move_ids(self):
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

Check warning on line 74 in rma_sale/models/rma.py

View check run for this annotation

Codecov / codecov/patch

rma_sale/models/rma.py#L74

Added line #L74 was not covered by tests

@api.depends("order_id")
def _compute_allowed_product_ids(self):
Expand All @@ -83,11 +84,10 @@ def _compute_allowed_product_ids(self):
else:
rec.allowed_product_ids = False # don't populate a big list

Check warning on line 85 in rma_sale/models/rma.py

View check run for this annotation

Codecov / codecov/patch

rma_sale/models/rma.py#L85

Added line #L85 was not covered by tests

@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

Check warning on line 90 in rma_sale/models/rma.py

View check run for this annotation

Codecov / codecov/patch

rma_sale/models/rma.py#L90

Added line #L90 was not covered by tests
return res

@api.onchange("order_id")
def _onchange_order_id(self):
Expand Down Expand Up @@ -132,36 +132,25 @@ def action_refund(self):
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

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()
vals["invoice_user_id"] = self.order_id.user_id.id
return vals

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
Expand All @@ -172,5 +161,5 @@ def _prepare_refund_line(self, line_form):
)
== 0
):
line_form.sale_line_ids.add(line)
return res
vals["sale_line_ids"] = [(4, line.id)]
return vals
8 changes: 4 additions & 4 deletions rma_sale/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Return Merchandise Authorization Management - Link with Sales</title>
<style type="text/css">

Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Return Merchandise Authorization Management - Link with Sales<
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/rma/tree/15.0/rma_sale"><img alt="OCA/rma" src="https://img.shields.io/badge/github-OCA%2Frma-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/rma-15-0/rma-15-0-rma_sale"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/145/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/rma/tree/16.0/rma_sale"><img alt="OCA/rma" src="https://img.shields.io/badge/github-OCA%2Frma-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/rma-16-0/rma-16-0-rma_sale"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/webui/builds.html?repo=OCA/rma&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows you to link a sales order to an RMA.
This can be done by creating an RMA from scratch and selecting the sales
order, creating one or more RMAs from a sales order form view or from a sales
Expand Down Expand Up @@ -430,7 +430,7 @@ <h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/rma/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/rma/issues/new?body=module:%20rma_sale%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/rma/issues/new?body=module:%20rma_sale%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -464,7 +464,7 @@ <h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/ernestotejeda"><img alt="ernestotejeda" src="https://github.com/ernestotejeda.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/rma/tree/15.0/rma_sale">OCA/rma</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/rma/tree/16.0/rma_sale">OCA/rma</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
33 changes: 17 additions & 16 deletions rma_sale/tests/test_rma_sale.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2020 Tecnativa - Ernesto Tejeda
# Copyright 2022 Tecnativa - Víctor Martínez
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.tests import Form, TransactionCase
Expand Down Expand Up @@ -61,17 +62,18 @@ def setUpClass(cls):
lambda r: r.product_id == cls.product_1
)
cls.order_out_picking = cls.sale_order.picking_ids
cls.order_out_picking.move_lines.quantity_done = 5
cls.order_out_picking.move_ids.quantity_done = 5
cls.order_out_picking.button_validate()

def test_create_rma_with_so(self):
rma_form = Form(self.env["rma"])
rma_form.partner_id = self.partner
rma_form.order_id = self.sale_order
rma_form.product_id = self.product_1
rma_form.product_uom_qty = 5
rma_form.location_id = self.sale_order.warehouse_id.rma_loc_id
rma = rma_form.save()
rma_vals = {
"partner_id": self.partner.id,
"order_id": self.sale_order.id,
"product_id": self.product_1.id,
"product_uom_qty": 5,
"location_id": self.sale_order.warehouse_id.rma_loc_id.id,
}
rma = self.env["rma"].create(rma_vals)
rma.action_confirm()
self.assertTrue(rma.reception_move_id)
self.assertFalse(rma.reception_move_id.origin_returned_move_id)
Expand All @@ -83,14 +85,14 @@ def test_create_rma_from_so(self):
self.assertEqual(rma.partner_id, order.partner_id)
self.assertEqual(rma.order_id, order)
self.assertEqual(rma.picking_id, self.order_out_picking)
self.assertEqual(rma.move_id, self.order_out_picking.move_lines)
self.assertEqual(rma.move_id, self.order_out_picking.move_ids)
self.assertEqual(rma.product_id, self.product_1)
self.assertEqual(rma.product_uom_qty, self.order_line.product_uom_qty)
self.assertEqual(rma.product_uom, self.order_line.product_uom)
self.assertEqual(rma.state, "confirmed")
self.assertEqual(
rma.reception_move_id.origin_returned_move_id,
self.order_out_picking.move_lines,
self.order_out_picking.move_ids,
)
self.assertEqual(
rma.reception_move_id.picking_id + self.order_out_picking,
Expand Down Expand Up @@ -172,7 +174,7 @@ def test_create_recurrent_rma(self):
delivery_wizard = delivery_form.save()
delivery_wizard.action_deliver()
picking = rma.delivery_move_ids.picking_id
picking.move_lines.quantity_done = rma.product_uom_qty
picking.move_ids.quantity_done = rma.product_uom_qty
picking._action_done()
# The product is returned to the customer, so we should be able to make
# another RMA in the future
Expand All @@ -188,8 +190,7 @@ def test_report_rma(self):
rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"])
operation = self.rma_operation_model.sudo().search([], limit=1)
rma.operation_id = operation.id
res = self.report_model._get_report_from_name(
"rma.report_rma"
)._render_qweb_text(rma.ids, False)
self.assertRegex(str(res[0]), self.sale_order.name)
self.assertRegex(str(res[0]), operation.name)
res = self.env["ir.actions.report"]._render_qweb_html("rma.report_rma", rma.ids)
res = str(res[0])
self.assertRegex(res, self.sale_order.name)
self.assertRegex(res, operation.name)
6 changes: 5 additions & 1 deletion rma_sale/views/rma_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
<field name="inherit_id" ref="rma.rma_view_form" />
<field name="arch" type="xml">
<field name="partner_invoice_id" position="after">
<field name="order_id" options="{'no_create': True}" />
<field
name="order_id"
options="{'no_create': True}"
attrs="{'readonly': [('state', '!=', 'draft')]}"
/>
</field>
<sheet>
<field name="allowed_picking_ids" invisible="1" />
Expand Down
3 changes: 2 additions & 1 deletion rma_sale/views/sale_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<field name="name">sale.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="groups_id" eval="[(4, ref('rma.rma_group_user_own'))]" />
<field name="arch" type="xml">
<button name="action_draft" position="after">
<button
name="action_create_rma"
type="object"
string="Create RMA"
states="sale,done"
groups="rma.rma_group_user_own"
/>
</button>
<div name="button_box">
Expand All @@ -21,6 +21,7 @@
class="oe_stat_button"
icon="fa-reply"
attrs="{'invisible': [('rma_count', '=', 0)]}"
groups="rma.rma_group_user_own"
>
<field name="rma_count" widget="statinfo" string="RMA" />
</button>
Expand Down
2 changes: 1 addition & 1 deletion rma_sale/wizard/sale_order_rma_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _compute_move_id(self):
for record in self:
move_id = False
if record.picking_id:
move_id = record.picking_id.move_lines.filtered(
move_id = record.picking_id.move_ids.filtered(
lambda r: (
r.sale_line_id == record.sale_line_id
and r.sale_line_id.product_id == record.product_id
Expand Down

0 comments on commit 3bfe02e

Please sign in to comment.