mirror of
https://github.com/OCA/rma.git
synced 2025-02-16 17:11:47 +02:00
[MIG] rma_sale: Migration to 16.0
- Standard procedure. - Adapt to new `prepare_*_vals` methods. - Renamed fields adaptation. - Improved test coverage. TT44214 s
This commit is contained in:
@@ -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 <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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -367,7 +367,7 @@ ul.auto-toc {
|
||||
!! 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&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
|
||||
@@ -430,7 +430,7 @@ number greater than the order line product quantity.</li>
|
||||
<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">
|
||||
@@ -464,7 +464,7 @@ mission is to support the collaborative development of Odoo features and
|
||||
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>
|
||||
|
||||
@@ -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
|
||||
@@ -61,17 +62,41 @@ class TestRmaSale(TestRmaSaleBase):
|
||||
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_rma_sale_computes_onchange(self):
|
||||
rma = self.env["rma"].new()
|
||||
# No m2m values when everything is selectable
|
||||
self.assertFalse(rma.allowed_picking_ids)
|
||||
self.assertFalse(rma.allowed_move_ids)
|
||||
self.assertFalse(rma.allowed_product_ids)
|
||||
# Partner selected
|
||||
rma.order_id = self.sale_order
|
||||
rma.partner_id = self.partner
|
||||
self.assertFalse(rma.order_id)
|
||||
self.assertEqual(rma.allowed_picking_ids._origin, self.order_out_picking)
|
||||
# Order selected
|
||||
rma.order_id = self.sale_order
|
||||
self.assertEqual(rma.allowed_picking_ids._origin, self.order_out_picking)
|
||||
rma.picking_id = self.order_out_picking
|
||||
self.assertEqual(rma.allowed_move_ids._origin, self.order_out_picking.move_ids)
|
||||
self.assertEqual(rma.allowed_product_ids._origin, self.product_1)
|
||||
# Onchanges
|
||||
rma.product_id = self.product_1
|
||||
rma._onchange_order_id()
|
||||
self.assertFalse(rma.product_id)
|
||||
self.assertFalse(rma.picking_id)
|
||||
|
||||
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)
|
||||
@@ -83,14 +108,14 @@ class TestRmaSale(TestRmaSaleBase):
|
||||
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,
|
||||
@@ -123,7 +148,7 @@ class TestRmaSale(TestRmaSaleBase):
|
||||
def test_create_rma_from_so_portal_user(self):
|
||||
order = self.sale_order
|
||||
wizard_obj = (
|
||||
self.env["sale.order.rma.wizard"].sudo().with_context(active_id=order)
|
||||
self.env["sale.order.rma.wizard"].sudo().with_context(active_id=order.id)
|
||||
)
|
||||
operation = self.rma_operation_model.sudo().search([], limit=1)
|
||||
line_vals = [
|
||||
@@ -149,6 +174,7 @@ class TestRmaSale(TestRmaSaleBase):
|
||||
rma = wizard.sudo().create_rma(from_portal=True)
|
||||
self.assertEqual(rma.order_id, order)
|
||||
self.assertIn(order.partner_id, rma.message_partner_ids)
|
||||
self.assertEqual(order.rma_count, 1)
|
||||
|
||||
def test_create_recurrent_rma(self):
|
||||
"""An RMA of a product that had an RMA in the past should be possible"""
|
||||
@@ -172,7 +198,7 @@ class TestRmaSale(TestRmaSaleBase):
|
||||
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
|
||||
@@ -188,8 +214,7 @@ class TestRmaSale(TestRmaSaleBase):
|
||||
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)
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
<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
|
||||
@@ -12,6 +11,7 @@
|
||||
type="object"
|
||||
string="Create RMA"
|
||||
states="sale,done"
|
||||
groups="rma.rma_group_user_own"
|
||||
/>
|
||||
</button>
|
||||
<div name="button_box">
|
||||
@@ -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>
|
||||
|
||||
@@ -161,7 +161,7 @@ class SaleOrderLineRmaWizard(models.TransientModel):
|
||||
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
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group>
|
||||
<field name="line_ids" nolabel="1">
|
||||
<field name="line_ids" nolabel="1" colspan="2">
|
||||
<tree editable="bottom">
|
||||
<field name="order_id" invisible="1" />
|
||||
<field name="allowed_product_ids" invisible="1" />
|
||||
|
||||
Reference in New Issue
Block a user