Skip to content

Commit

Permalink
Merge PR #981 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed May 3, 2023
2 parents 6102fbe + 4498c6d commit 6f87865
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 53 deletions.
7 changes: 4 additions & 3 deletions pos_order_return/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ invoiced, a refund invoice will be made.
Known issues / Roadmap
======================

When migrating the module ``pos_order_return`` in version > 12.0 please merge
both modules ``pos_order_return`` and ``pos_order_return_traceability`` into a
single module.
* When migrating the module ``pos_order_return`` in version > 12.0 please merge
both modules ``pos_order_return`` and ``pos_order_return_traceability`` into a
single module.
* Stock update on session close is uncovered right now.

Bug Tracker
===========
Expand Down
39 changes: 24 additions & 15 deletions pos_order_return/models/pos_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# Copyright 2018 David Vidal <david.vidal@tecnativa.com>
# Copyright 2018 Lambda IS DOOEL <https://www.lambda-is.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.tests import Form


class PosOrder(models.Model):
Expand Down Expand Up @@ -111,9 +110,13 @@ def action_pos_order_paid(self):

def _create_picking_return(self):
self.ensure_one()
picking = self.returned_order_id.picking_ids
ctx = dict(self.env.context, active_ids=picking.ids, active_id=picking.id)
wizard = self.env["stock.return.picking"].with_context(ctx).create({})
return_form = Form(
self.env["stock.return.picking"].with_context(
active_id=self.returned_order_id.picking_ids.id,
active_model="stock.picking",
)
)
wizard = return_form.save()
# Discard not returned lines
wizard.product_return_moves.filtered(
lambda x: x.product_id not in self.mapped("lines.product_id")
Expand All @@ -127,20 +130,26 @@ def _create_picking_return(self):
if to_return[move.product_id] < move.quantity:
move.quantity = to_return[move.product_id]
to_return[move.product_id] -= move.quantity
return wizard
picking = self.env["stock.picking"].browse(wizard.create_returns()["res_id"])
for move in picking.move_lines:
move.quantity_done = move.product_uom_qty
picking._action_done()
picking.write(
{
"pos_session_id": self.session_id.id,
"pos_order_id": self.id,
"origin": self.name,
}
)
return picking

def _create_order_picking(self):
"""Odoo bases return picking if the quantities are negative, but it's
not linked to the original one"""
orders = self.filtered(
lambda x: not x.returned_order_id or not x.returned_order_id.picking_ids
)
res = super()._create_order_picking()
for order in self - orders:
wizard = order._create_picking_return()
res = wizard.create_returns()
order.write({"picking_ids": (6, 0, [res["res_id"]])})
return res
self.ensure_one()
if not self.returned_order_id.picking_ids:
return super()._create_order_picking()
self.picking_ids = self._create_picking_return()


class PosOrderLine(models.Model):
Expand Down
7 changes: 4 additions & 3 deletions pos_order_return/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
When migrating the module ``pos_order_return`` in version > 12.0 please merge
both modules ``pos_order_return`` and ``pos_order_return_traceability`` into a
single module.
* When migrating the module ``pos_order_return`` in version > 12.0 please merge
both modules ``pos_order_return`` and ``pos_order_return_traceability`` into a
single module.
* Stock update on session close is uncovered right now.
9 changes: 6 additions & 3 deletions pos_order_return/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>Point of Sale Order Return</title>
<style type="text/css">

Expand Down Expand Up @@ -430,9 +430,12 @@ <h1><a class="toc-backref" href="#id2">Usage</a></h1>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#id3">Known issues / Roadmap</a></h1>
<p>When migrating the module <tt class="docutils literal">pos_order_return</tt> in version &gt; 12.0 please merge
<ul class="simple">
<li>When migrating the module <tt class="docutils literal">pos_order_return</tt> in version &gt; 12.0 please merge
both modules <tt class="docutils literal">pos_order_return</tt> and <tt class="docutils literal">pos_order_return_traceability</tt> into a
single module.</p>
single module.</li>
<li>Stock update on session close is uncovered right now.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
Expand Down
60 changes: 31 additions & 29 deletions pos_order_return/tests/test_pos_order_return.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Copyright 2018 Tecnativa - David Vidal
# Copyright 2018 Lambda IS DOOEL <https://www.lambda-is.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import unittest

from odoo.tests import common, tagged


@tagged("post_install", "-at_install")
class TestPOSOrderReturn(common.SavepointCase):
def setUp(self):
super(TestPOSOrderReturn, self).setUp()
self.pricelist = self.env["product.pricelist"].create(
@classmethod
def setUpClass(cls):
super(TestPOSOrderReturn, cls).setUpClass()
cls.pricelist = cls.env["product.pricelist"].create(
{
"name": "Test pricelist",
"item_ids": [
Expand All @@ -27,13 +25,13 @@ def setUp(self):
],
}
)
self.partner = self.env["res.partner"].create(
cls.partner = cls.env["res.partner"].create(
{
"name": "Mr. Odoo",
"property_product_pricelist": self.pricelist.id,
"property_product_pricelist": cls.pricelist.id,
}
)
self.product_1 = self.env["product.product"].create(
cls.product_1 = cls.env["product.product"].create(
{
"name": "Test product 1",
"standard_price": 1.0,
Expand All @@ -42,7 +40,7 @@ def setUp(self):
"taxes_id": False,
}
)
self.product_2 = self.env["product.product"].create(
cls.product_2 = cls.env["product.product"].create(
{
"name": "Test product 2",
"standard_price": 1.0,
Expand All @@ -51,14 +49,21 @@ def setUp(self):
"taxes_id": False,
}
)
self.PosOrder = self.env["pos.order"]
self.pos_config = self.env.ref("point_of_sale.pos_config_main")
self.pos_config.open_session_cb()
self.pos_order = self.PosOrder.create(
cls.PosOrder = cls.env["pos.order"]
cls.pos_config = cls.env.ref("point_of_sale.pos_config_main")
cls.pos_config.write(
{
"session_id": self.pos_config.current_session_id.id,
"partner_id": self.partner.id,
"pricelist_id": self.partner.property_product_pricelist.id,
"available_pricelist_ids": [(6, 0, cls.pricelist.ids)],
"pricelist_id": cls.pricelist.id,
}
)
cls.pos_config.company_id.point_of_sale_update_stock_quantities = False
cls.pos_config.open_session_cb()
cls.pos_order = cls.PosOrder.create(
{
"session_id": cls.pos_config.current_session_id.id,
"partner_id": cls.partner.id,
"pricelist_id": cls.partner.property_product_pricelist.id,
"amount_tax": 0,
"amount_total": 2700,
"amount_paid": 2700,
Expand All @@ -69,7 +74,7 @@ def setUp(self):
0,
{
"name": "POSLINE/0001",
"product_id": self.product_1.id,
"product_id": cls.product_1.id,
"price_unit": 450,
"price_subtotal": 450,
"price_subtotal_incl": 450,
Expand All @@ -81,7 +86,7 @@ def setUp(self):
0,
{
"name": "POSLINE/0002",
"product_id": self.product_2.id,
"product_id": cls.product_2.id,
"price_unit": 450,
"price_subtotal": 450,
"price_subtotal_incl": 450,
Expand All @@ -93,7 +98,7 @@ def setUp(self):
0,
{
"name": "POSLINE/0003",
"product_id": self.product_1.id,
"product_id": cls.product_1.id,
"price_unit": 450,
"price_subtotal": 450,
"price_subtotal_incl": 450,
Expand All @@ -104,21 +109,19 @@ def setUp(self):
}
)
pos_make_payment = (
self.env["pos.make.payment"]
cls.env["pos.make.payment"]
.with_context(
{
"active_ids": [self.pos_order.id],
"active_id": self.pos_order.id,
"active_ids": [cls.pos_order.id],
"active_id": cls.pos_order.id,
}
)
.create({})
)
pos_make_payment.with_context(active_id=self.pos_order.id).check()
self.pos_order._create_order_picking()
res = self.pos_order.action_pos_order_invoice()
self.invoice = self.env["account.move"].browse(res["res_id"])
pos_make_payment.with_context(active_id=cls.pos_order.id).check()
res = cls.pos_order.action_pos_order_invoice()
cls.invoice = cls.env["account.move"].browse(res["res_id"])

@unittest.skip("Errors introduced due to recent odoo changes")
def test_pos_order_full_refund(self):
self.pos_order.refund()
refund_order = self.pos_order.refund_order_ids
Expand All @@ -140,7 +143,6 @@ def test_pos_order_full_refund(self):
# Partner balance is 0
self.assertEqual(sum(self.partner.mapped("invoice_ids.amount_total_signed")), 0)

@unittest.skip("Errors introduced due to recent odoo changes")
def test_pos_order_partial_refund(self):
partial_refund = (
self.env["pos.partial.return.wizard"]
Expand Down

0 comments on commit 6f87865

Please sign in to comment.