Skip to content

Commit 08a6bfc

Browse files
committed
[IMP] stock_picking_backorder_reason: Allow to cancel backorder transparently
As user does not want to have necessarily a reason wizard to cancel the backorder, add a parameter that allows to bypass that wizard.
1 parent a677209 commit 08a6bfc

File tree

7 files changed

+115
-43
lines changed

7 files changed

+115
-43
lines changed

stock_picking_backorder_reason/README.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
Stock Picking Backorder Reason
33
==============================
44

5-
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
67
!! This file is generated by oca-gen-addon-readme !!
78
!! changes will be overwritten. !!
89
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:0f8a117f9f235fddba6560b3452a7791aeec955054a578c8ecae4e01ec899376
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
912
1013
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1114
:target: https://odoo-community.org/page/development-status
@@ -19,11 +22,11 @@ Stock Picking Backorder Reason
1922
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
2023
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_picking_backorder_reason
2124
:alt: Translate me on Weblate
22-
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23-
:target: https://runbot.odoo-community.org/runbot/154/16.0
24-
:alt: Try me on Runbot
25+
.. |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
27+
:alt: Try me on Runboat
2528

26-
|badge1| |badge2| |badge3| |badge4| |badge5|
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
2730

2831
This module allows to help user defining a backorder reason when it is
2932
launched on picking validation. This reason will be written on picking chatter level.
@@ -71,7 +74,7 @@ Bug Tracker
7174

7275
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-workflow/issues>`_.
7376
In case of trouble, please check there if your issue has already been reported.
74-
If you spotted it first, help us smashing it by providing a detailed and welcomed
77+
If you spotted it first, help us to smash it by providing a detailed and welcomed
7578
`feedback <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_picking_backorder_reason%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
7679

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

stock_picking_backorder_reason/models/stock_picking.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
33

44
from odoo import _, api, fields, models
5+
from odoo.fields import Command
56

67

78
class StockPicking(models.Model):
@@ -41,7 +42,35 @@ def _compute_backorder_reason_strategy(self):
4142
def _check_backorder_reason(self):
4243
return self.filtered("picking_type_id.backorder_reason")
4344

45+
def _action_backorder_transparent_cancel(self):
46+
return (
47+
self.env["stock.backorder.reason.choice"]
48+
.new(
49+
{
50+
"picking_ids": [Command.set(self.ids)],
51+
"choice_line_ids": [
52+
Command.create({"picking_id": pick_id}) for pick_id in self.ids
53+
],
54+
}
55+
)
56+
.apply()
57+
)
58+
4459
def _action_backorder_reason(self, show_transfers=False):
60+
if self.is_transparent_backorder_cancel:
61+
return (
62+
self.env["stock.backorder.reason.choice"]
63+
.new(
64+
{
65+
"picking_ids": [Command.set(self.ids)],
66+
"choice_line_ids": [
67+
Command.create({"picking_id": pick_id})
68+
for pick_id in self.ids
69+
],
70+
}
71+
)
72+
.apply()
73+
)
4574
view = self.env.ref(
4675
"stock_picking_backorder_reason.stock_backorder_choice_view_form"
4776
)
@@ -60,13 +89,27 @@ def _action_backorder_reason(self, show_transfers=False):
6089
),
6190
}
6291

92+
def _check_transparent_cancel(self):
93+
return self.filtered(lambda p: p.is_transparent_backorder_cancel)
94+
6395
def _pre_action_done_hook(self):
6496
if not self.env.context.get("skip_backorder_reason"):
6597
# Check if backorder is needed and then if reason is needed
6698
pickings_with_backorder = self._check_backorder()
99+
pickings_with_transparent_cancel = self._check_transparent_cancel()
100+
if pickings_with_transparent_cancel:
101+
return self._action_backorder_transparent_cancel()
67102
pickings_with_reason = pickings_with_backorder._check_backorder_reason()
68103
if pickings_with_reason:
69104
return pickings_with_reason._action_backorder_reason(
70105
show_transfers=self._should_show_transfers()
71106
)
72107
return super()._pre_action_done_hook()
108+
109+
@property
110+
def is_transparent_backorder_cancel(self):
111+
return bool(
112+
self.picking_type_id.backorder_reason
113+
and self.picking_type_id.backorder_reason_transparent_cancel
114+
and self.backorder_reason_strategy == "cancel"
115+
)

stock_picking_backorder_reason/models/stock_picking_type.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class StockPickingType(models.Model):
2727
help="Check this in order to consider pickings in this type as "
2828
"Purchase ones for backorder reason cancellation.",
2929
)
30+
backorder_reason_transparent_cancel = fields.Boolean(
31+
help="If this is checked and if the partner strategy is 'Cancel', "
32+
"nothing will be shown to the user and the backorder will be cancelled."
33+
)
3034

3135
@api.depends("backorder_reason")
3236
def _compute_backorder_reason_sale(self):

stock_picking_backorder_reason/static/description/index.html

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
43
<head>
54
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6-
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
5+
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
76
<title>Stock Picking Backorder Reason</title>
87
<style type="text/css">
98

109
/*
1110
:Author: David Goodger ([email protected])
12-
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
11+
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
1312
:Copyright: This stylesheet has been placed in the public domain.
1413
1514
Default cascading style sheet for the HTML output of Docutils.
1615
17-
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
16+
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1817
customize this style sheet.
1918
*/
2019

@@ -366,8 +365,10 @@ <h1 class="title">Stock Picking Backorder Reason</h1>
366365
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
367366
!! This file is generated by oca-gen-addon-readme !!
368367
!! changes will be overwritten. !!
368+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
369+
!! source digest: sha256:0f8a117f9f235fddba6560b3452a7791aeec955054a578c8ecae4e01ec899376
369370
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
370-
<p><a class="reference external" 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" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_backorder_reason"><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" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_picking_backorder_reason"><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/154/16.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
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/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_backorder_reason"><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_picking_backorder_reason"><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>
371372
<p>This module allows to help user defining a backorder reason when it is
372373
launched on picking validation. This reason will be written on picking chatter level.</p>
373374
<p>A reason can have several backorder strategy to apply:</p>
@@ -384,19 +385,19 @@ <h1 class="title">Stock Picking Backorder Reason</h1>
384385
<p><strong>Table of contents</strong></p>
385386
<div class="contents local topic" id="contents">
386387
<ul class="simple">
387-
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
388-
<li><a class="reference internal" href="#known-issues-roadmap" id="id2">Known issues / Roadmap</a></li>
389-
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
390-
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
391-
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
392-
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
393-
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
388+
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
389+
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-2">Known issues / Roadmap</a></li>
390+
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
391+
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
392+
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
393+
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
394+
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
394395
</ul>
395396
</li>
396397
</ul>
397398
</div>
398399
<div class="section" id="configuration">
399-
<h1><a class="toc-backref" href="#id1">Configuration</a></h1>
400+
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
400401
<ol class="arabic simple">
401402
<li>Go to Inventory &gt; Configuration &gt; Operation Types</li>
402403
<li>Select the one you want to activate the feature and check the
@@ -424,38 +425,38 @@ <h1><a class="toc-backref" href="#id1">Configuration</a></h1>
424425
</ol>
425426
</div>
426427
<div class="section" id="known-issues-roadmap">
427-
<h1><a class="toc-backref" href="#id2">Known issues / Roadmap</a></h1>
428+
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
428429
<ul class="simple">
429430
<li>For the time being, options are set on wizard level. One may want to have
430431
the granularity on line one.</li>
431432
</ul>
432433
</div>
433434
<div class="section" id="bug-tracker">
434-
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
435+
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
435436
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/issues">GitHub Issues</a>.
436437
In case of trouble, please check there if your issue has already been reported.
437-
If you spotted it first, help us smashing it by providing a detailed and welcomed
438+
If you spotted it first, help us to smash it by providing a detailed and welcomed
438439
<a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_picking_backorder_reason%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
439440
<p>Do not contact contributors directly about support or help with technical issues.</p>
440441
</div>
441442
<div class="section" id="credits">
442-
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
443+
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
443444
<div class="section" id="authors">
444-
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
445+
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
445446
<ul class="simple">
446447
<li>ACSONE SA/NV</li>
447448
</ul>
448449
</div>
449450
<div class="section" id="contributors">
450-
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
451+
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
451452
<ul class="simple">
452453
<li>Jacques-Etienne Baudoux &lt;<a class="reference external" href="mailto:je&#64;bcim.be">je&#64;bcim.be</a>&gt;</li>
453454
<li>Laurent Mignon &lt;<a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a>&gt;</li>
454455
<li>Denis Roussel &lt;<a class="reference external" href="mailto:denis.roussel&#64;acsone.eu">denis.roussel&#64;acsone.eu</a>&gt;</li>
455456
</ul>
456457
</div>
457458
<div class="section" id="maintainers">
458-
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
459+
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
459460
<p>This module is maintained by the OCA.</p>
460461
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
461462
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose

stock_picking_backorder_reason/tests/test_sale_backorder_reason.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,15 @@ def test_sale_picking_backorder_create_backorder_partner_create(self):
5858
self.sale_backorder = "create"
5959

6060
self._check_backorder_behavior()
61+
62+
def test_sale_picking_backorder_partner_cancel_transparent(self):
63+
"""
64+
In this case, we test a partner that has his backorder policy
65+
set to 'Cancel', the picking type activated for backorder reason
66+
and the transparent action in case of cancel activated too.
67+
"""
68+
self.picking.picking_type_id.backorder_reason_transparent_cancel = True
69+
self.partner.sale_reason_backorder_strategy = "cancel"
70+
result = self.picking.button_validate()
71+
self.assertTrue(result is True)
72+
self.assertFalse(self.picking.backorder_ids)

stock_picking_backorder_reason/views/stock_picking_type.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
name="backorder_reason_purchase"
2525
attrs="{'invisible': [('backorder_reason', '=', False)]}"
2626
/>
27+
<field
28+
name="backorder_reason_transparent_cancel"
29+
attrs="{'invisible': [('backorder_reason', '=', False)]}"
30+
/>
2731
</group>
2832
</group>
2933
</field>

stock_picking_backorder_reason/wizards/stock_backorder_reason_choice.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,28 @@ def apply(self):
6868
# Set the reason on each picking
6969
pickings.message_post(body=wizard._get_message())
7070
keep_backorder_pickings = self.env["stock.picking"].browse()
71-
if wizard.backorder_action_to_do == "create":
72-
keep_backorder_pickings = pickings
73-
elif wizard.backorder_action_to_do == "use_partner_option":
74-
keep_backorder_pickings = pickings.filtered(
75-
lambda picking: picking.backorder_reason_strategy == "create"
76-
)
77-
elif not wizard.backorder_action_to_do:
78-
# Let do the normal way
79-
return pickings.with_context(
80-
skip_backorder_reason=True
81-
)._pre_action_done_hook()
82-
pickings_to_cancel = pickings - keep_backorder_pickings
83-
if keep_backorder_pickings:
84-
backorder_wizard = confirmation_obj.create(
85-
wizard._prepare_backorder_confirmation(keep_backorder_pickings)
86-
)
87-
backorder_wizard.with_context(skip_backorder_reason=True).process()
71+
if all(
72+
picking.is_transparent_backorder_cancel for picking in self.picking_ids
73+
):
74+
pickings_to_cancel = self.picking_ids
75+
else:
76+
if wizard.backorder_action_to_do == "create":
77+
keep_backorder_pickings = pickings
78+
elif wizard.backorder_action_to_do == "use_partner_option":
79+
keep_backorder_pickings = pickings.filtered(
80+
lambda picking: picking.backorder_reason_strategy == "create"
81+
)
82+
elif not wizard.backorder_action_to_do:
83+
# Let do the normal way
84+
return pickings.with_context(
85+
skip_backorder_reason=True
86+
)._pre_action_done_hook()
87+
pickings_to_cancel = pickings - keep_backorder_pickings
88+
if keep_backorder_pickings:
89+
backorder_wizard = confirmation_obj.create(
90+
wizard._prepare_backorder_confirmation(keep_backorder_pickings)
91+
)
92+
backorder_wizard.with_context(skip_backorder_reason=True).process()
8893

8994
if pickings_to_cancel:
9095
backorder_wizard = confirmation_obj.with_context(

0 commit comments

Comments
 (0)