Skip to content

Commit dc3baaa

Browse files
[MIG] stock_account_fifo_return_origin: Migration to 18.0
1 parent 7aad014 commit dc3baaa

File tree

10 files changed

+112
-52
lines changed

10 files changed

+112
-52
lines changed

stock_account_fifo_return_origin/README.rst

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ Stock Account FIFO Return Origin
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github
20-
:target: https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_account_fifo_return_origin
20+
:target: https://github.com/OCA/stock-logistics-workflow/tree/18.0/stock_account_fifo_return_origin
2121
:alt: OCA/stock-logistics-workflow
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_account_fifo_return_origin
23+
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-18-0/stock-logistics-workflow-18-0-stock_account_fifo_return_origin
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=16.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=18.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
3030

31-
This module makes adjustment to the standard behavior with regards to candidate SVLs
32-
that are used in purchase returns; if the SVL linked to the origin move (receipt) has
33-
remaining quantity, that SVL should be consumed first.
31+
This module makes adjustment to the standard behavior with regards to
32+
candidate SVLs that are used in purchase returns; if the SVL linked to
33+
the origin move (receipt) has remaining quantity, that SVL should be
34+
consumed first.
3435

3536
**Table of contents**
3637

@@ -43,20 +44,28 @@ Bug Tracker
4344
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-workflow/issues>`_.
4445
In case of trouble, please check there if your issue has already been reported.
4546
If you spotted it first, help us to smash it by providing a detailed and welcomed
46-
`feedback <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_account_fifo_return_origin%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
47+
`feedback <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_account_fifo_return_origin%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
4748

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

5051
Credits
5152
=======
5253

5354
Authors
54-
~~~~~~~
55+
-------
5556

5657
* Quartile
5758

59+
Contributors
60+
------------
61+
62+
- `Quartile <https://www.quartile.co>`__:
63+
64+
- Yoshi Tashiro
65+
- Aung Ko Ko Lin
66+
5867
Maintainers
59-
~~~~~~~~~~~
68+
-----------
6069

6170
This module is maintained by the OCA.
6271

@@ -68,6 +77,17 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
6877
mission is to support the collaborative development of Odoo features and
6978
promote its widespread use.
7079

71-
This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_account_fifo_return_origin>`_ project on GitHub.
80+
.. |maintainer-yostashiro| image:: https://github.com/yostashiro.png?size=40px
81+
:target: https://github.com/yostashiro
82+
:alt: yostashiro
83+
.. |maintainer-aungkokolin1997| image:: https://github.com/aungkokolin1997.png?size=40px
84+
:target: https://github.com/aungkokolin1997
85+
:alt: aungkokolin1997
86+
87+
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
88+
89+
|maintainer-yostashiro| |maintainer-aungkokolin1997|
90+
91+
This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/18.0/stock_account_fifo_return_origin>`_ project on GitHub.
7292

7393
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

stock_account_fifo_return_origin/__manifest__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33

44
{
55
"name": "Stock Account FIFO Return Origin",
6-
"version": "16.0.1.0.0",
6+
"summary": "Prioritize the origin receipt SVL for purchase return valuation.",
7+
"version": "18.0.1.0.0",
78
"license": "AGPL-3",
89
"author": "Quartile, Odoo Community Association (OCA)",
910
"website": "https://github.com/OCA/stock-logistics-workflow",
1011
"depends": ["stock_account"],
12+
"maintainers": ["yostashiro", "aungkokolin1997"],
13+
"installable": True,
1114
}

stock_account_fifo_return_origin/models/product.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
class Product(models.Model):
88
_inherit = "product.product"
99

10-
def _get_fifo_candidates(self, company):
11-
candidates = super()._get_fifo_candidates(company)
12-
returned_moves = self.env.context.get("origin_returned_moves")
13-
if not returned_moves:
10+
def _get_fifo_candidates(self, company, lot=False):
11+
candidates = super()._get_fifo_candidates(company, lot=lot)
12+
origin_move = self.env.context.get("origin_returned_move")
13+
if not origin_move:
1414
return candidates
15-
returned_moves = returned_moves.filtered(lambda x: x.product_id == self)
16-
origin_svl = returned_moves.stock_valuation_layer_ids.filtered(
15+
origin_svl = origin_move.stock_valuation_layer_ids.filtered(
1716
lambda x: x.remaining_qty > 0.00
1817
)
19-
candidates = origin_svl | candidates
20-
return candidates
18+
return origin_svl | candidates

stock_account_fifo_return_origin/models/stock_move.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
class StockMove(models.Model):
88
_inherit = "stock.move"
99

10-
def _action_done(self, cancel_backorder=False):
11-
origin_returned_moves = self.browse()
12-
for move in self:
13-
if move._is_out():
14-
origin_returned_moves |= move.origin_returned_move_id
15-
# We cannot assign origin returned move context to individual moves, therefore
16-
# assign them all to self
17-
if origin_returned_moves:
18-
self = self.with_context(origin_returned_moves=origin_returned_moves)
19-
return super()._action_done(cancel_backorder)
10+
def _get_out_svl_vals(self, forced_quantity):
11+
return_moves = self.filtered(lambda m: m.origin_returned_move_id)
12+
other_moves = self - return_moves
13+
svl_vals_list = (
14+
super(StockMove, other_moves)._get_out_svl_vals(forced_quantity)
15+
if other_moves
16+
else []
17+
)
18+
for move in return_moves:
19+
svl_vals_list += super(
20+
StockMove,
21+
move.with_context(origin_returned_move=move.origin_returned_move_id),
22+
)._get_out_svl_vals(forced_quantity)
23+
return svl_vals_list

stock_account_fifo_return_origin/models/stock_move_line.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ class StockMoveLine(models.Model):
1010
@api.model
1111
def _create_correction_svl(self, move, diff):
1212
if move._is_in() and diff < 0:
13-
move = move.with_context(origin_returned_moves=move)
13+
move = move.with_context(origin_returned_move=move)
1414
return super()._create_correction_svl(move, diff)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- [Quartile](https://www.quartile.co):
2+
- Yoshi Tashiro
3+
- Aung Ko Ko Lin

stock_account_fifo_return_origin/readme/DESCRIPTION.rst renamed to stock_account_fifo_return_origin/readme/DESCRIPTION.md

File renamed without changes.

stock_account_fifo_return_origin/static/description/index.html

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/*
1010
:Author: David Goodger (goodger@python.org)
11-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1516
1617
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1718
customize this style sheet.
@@ -274,7 +275,7 @@
274275
margin-left: 2em ;
275276
margin-right: 2em }
276277

277-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
278279
pre.code, code { background-color: #eeeeee }
279280
pre.code .comment, code .comment { color: #5C6576 }
280281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
300301
span.pre {
301302
white-space: pre }
302303

303-
span.problematic {
304+
span.problematic, pre.problematic {
304305
color: red }
305306

306307
span.section-subtitle {
@@ -368,17 +369,19 @@ <h1 class="title">Stock Account FIFO Return Origin</h1>
368369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
369370
!! source digest: sha256:f365b070c877cb49d483654699911d0f9d351de248cfca5a6cdf11258d8a7017
370371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
371-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" 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 image-reference" href="https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_account_fifo_return_origin"><img alt="OCA/stock-logistics-workflow" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_account_fifo_return_origin"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372-
<p>This module makes adjustment to the standard behavior with regards to candidate SVLs
373-
that are used in purchase returns; if the SVL linked to the origin move (receipt) has
374-
remaining quantity, that SVL should be consumed first.</p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" 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 image-reference" href="https://github.com/OCA/stock-logistics-workflow/tree/18.0/stock_account_fifo_return_origin"><img alt="OCA/stock-logistics-workflow" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-18-0/stock-logistics-workflow-18-0-stock_account_fifo_return_origin"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373+
<p>This module makes adjustment to the standard behavior with regards to
374+
candidate SVLs that are used in purchase returns; if the SVL linked to
375+
the origin move (receipt) has remaining quantity, that SVL should be
376+
consumed first.</p>
375377
<p><strong>Table of contents</strong></p>
376378
<div class="contents local topic" id="contents">
377379
<ul class="simple">
378380
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-1">Bug Tracker</a></li>
379381
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
380382
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
381-
<li><a class="reference internal" href="#maintainers" id="toc-entry-4">Maintainers</a></li>
383+
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
384+
<li><a class="reference internal" href="#maintainers" id="toc-entry-5">Maintainers</a></li>
382385
</ul>
383386
</li>
384387
</ul>
@@ -388,7 +391,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
388391
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/issues">GitHub Issues</a>.
389392
In case of trouble, please check there if your issue has already been reported.
390393
If you spotted it first, help us to smash it by providing a detailed and welcomed
391-
<a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_account_fifo_return_origin%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
394+
<a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_account_fifo_return_origin%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
392395
<p>Do not contact contributors directly about support or help with technical issues.</p>
393396
</div>
394397
<div class="section" id="credits">
@@ -399,14 +402,28 @@ <h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
399402
<li>Quartile</li>
400403
</ul>
401404
</div>
405+
<div class="section" id="contributors">
406+
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
407+
<ul class="simple">
408+
<li><a class="reference external" href="https://www.quartile.co">Quartile</a>:<ul>
409+
<li>Yoshi Tashiro</li>
410+
<li>Aung Ko Ko Lin</li>
411+
</ul>
412+
</li>
413+
</ul>
414+
</div>
402415
<div class="section" id="maintainers">
403-
<h2><a class="toc-backref" href="#toc-entry-4">Maintainers</a></h2>
416+
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
404417
<p>This module is maintained by the OCA.</p>
405-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
418+
<a class="reference external image-reference" href="https://odoo-community.org">
419+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
420+
</a>
406421
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
407422
mission is to support the collaborative development of Odoo features and
408423
promote its widespread use.</p>
409-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_account_fifo_return_origin">OCA/stock-logistics-workflow</a> project on GitHub.</p>
424+
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
425+
<p><a class="reference external image-reference" href="https://github.com/yostashiro"><img alt="yostashiro" src="https://github.com/yostashiro.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/aungkokolin1997"><img alt="aungkokolin1997" src="https://github.com/aungkokolin1997.png?size=40px" /></a></p>
426+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/tree/18.0/stock_account_fifo_return_origin">OCA/stock-logistics-workflow</a> project on GitHub.</p>
410427
<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>
411428
</div>
412429
</div>

stock_account_fifo_return_origin/tests/test_stock_account_fifo_return_origin.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

44

5-
from odoo.tests.common import Form, TransactionCase
5+
from odoo.tests import Form
66

7+
from odoo.addons.base.tests.common import BaseCommon
78

8-
class TestStockAccountFifoReturnOrigin(TransactionCase):
9+
10+
class TestStockAccountFifoReturnOrigin(BaseCommon):
911
@classmethod
1012
def setUpClass(cls):
1113
super().setUpClass()
@@ -19,7 +21,6 @@ def setUpClass(cls):
1921
cls.product = cls.env["product.product"].create(
2022
{
2123
"name": "Test Product",
22-
"type": "product",
2324
"categ_id": product_category.id,
2425
}
2526
)
@@ -35,12 +36,11 @@ def create_receipt_picking(self, price_unit):
3536
"picking_type_id": self.picking_type_in.id,
3637
}
3738
)
38-
3939
move = self.env["stock.move"].create(
4040
{
4141
"name": "Test Move",
4242
"product_id": self.product.id,
43-
"product_uom_qty": 10,
43+
"quantity": 10,
4444
"product_uom": self.product.uom_id.id,
4545
"location_id": self.supplier_location.id,
4646
"location_dest_id": self.stock_location.id,
@@ -50,7 +50,7 @@ def create_receipt_picking(self, price_unit):
5050
)
5151
move._action_confirm()
5252
move._action_assign()
53-
move.move_line_ids.qty_done = 10
53+
move.move_line_ids.quantity = 10
5454
picking.button_validate()
5555
return picking
5656

@@ -59,12 +59,10 @@ def test_stock_account_fifo_return(self):
5959
move = picking.move_ids[0]
6060
stock_valuation_layer = move.stock_valuation_layer_ids[0]
6161
self.assertEqual(stock_valuation_layer.value, 1000)
62-
6362
picking = self.create_receipt_picking(200)
6463
move = picking.move_ids[0]
6564
stock_valuation_layer = move.stock_valuation_layer_ids[0]
6665
self.assertEqual(stock_valuation_layer.value, 2000)
67-
6866
return_picking_wizard_form = Form(
6967
self.env["stock.return.picking"].with_context(
7068
active_ids=picking.ids,
@@ -74,12 +72,26 @@ def test_stock_account_fifo_return(self):
7472
)
7573
return_picking_wizard = return_picking_wizard_form.save()
7674
return_picking_wizard.product_return_moves.write({"quantity": 10})
77-
return_picking_wizard_action = return_picking_wizard.create_returns()
75+
return_picking_wizard_action = return_picking_wizard.action_create_returns()
7876
return_picking = self.env["stock.picking"].browse(
7977
return_picking_wizard_action["res_id"]
8078
)
8179
return_move = return_picking.move_ids
82-
return_move.move_line_ids.qty_done = 10
80+
return_move.move_line_ids.quantity = 10
8381
return_picking.button_validate()
8482
return_valuation_layer = return_move.stock_valuation_layer_ids[0]
8583
self.assertEqual(abs(return_valuation_layer.value), 2000)
84+
85+
def test_create_correction_svl(self):
86+
self.create_receipt_picking(100)
87+
picking = self.create_receipt_picking(200)
88+
picking.action_toggle_is_locked()
89+
move = picking.move_ids[0]
90+
move_line = move.move_line_ids[0]
91+
move_line.quantity = 8
92+
correction_svl = move.stock_valuation_layer_ids.filtered(
93+
lambda svl: svl.quantity < 0
94+
)
95+
self.assertTrue(correction_svl)
96+
# Should use receipt's cost (200), not FIFO oldest (100)
97+
self.assertEqual(correction_svl.value, -400.0)

0 commit comments

Comments
 (0)