Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
third-party
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cooperatic-foodcoops
third-party
Commits
7e9e7948
Commit
7e9e7948
authored
Nov 13, 2024
by
Yvon Kerdoncuff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#7050 stock movement : block action if it could only be done partially
parent
67d6f2e7
Pipeline
#3916
failed with stage
in 0 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
5 deletions
+35
-5
models.py
stock/models.py
+35
-5
No files found.
stock/models.py
View file @
7e9e7948
...
...
@@ -98,10 +98,40 @@ class CagetteStock(models.Model):
# Exception rises when odoo method returns nothing
marshal_none_error
=
'cannot marshal None unless allow_none is enabled'
try
:
picking
=
api
.
create
(
'stock.picking'
,
fields
)
if
not
(
picking
is
None
):
api
.
execute
(
'stock.picking'
,
'action_done'
,
[
picking
])
picking_id
=
api
.
create
(
'stock.picking'
,
fields
)
if
picking_id
:
# Récupérer les lignes de mouvement associées au picking
picking_move_lines
=
api
.
search_read
(
'stock.move'
,
[(
'picking_id'
,
'='
,
picking_id
)],
# Filtre sur le picking_id
[
'id'
,
'product_id'
,
'product_qty'
]
# Champs nécessaires
)
# Pour chaque mouvement de picking, vérifier la disponibilité avant de procéder
for
move
in
picking_move_lines
:
product_id
=
move
[
'product_id'
][
0
]
# ID du produit
product_qty
=
move
[
'product_qty'
]
# Quantité demandée pour ce mouvement
stock_quant_data
=
api
.
search_read
(
'stock.quant'
,
[(
'product_id'
,
'='
,
product_id
),
(
'location_id'
,
'='
,
settings
.
STOCK_LOC_ID
)],
[
'quantity'
,
'reserved_quantity'
]
)
if
stock_quant_data
:
# Calcul de la quantité réservable
net_available_stock
=
stock_quant_data
[
0
][
'quantity'
]
-
stock_quant_data
[
0
][
'reserved_quantity'
]
# Vérifier si le stock net disponible est suffisant pour le mouvement actuel
if
product_qty
>
net_available_stock
:
# Lever une exception pour bloquer l'action
raise
Exception
(
'Réservation totale impossible pour le produit : {}. Quantité nette réservable : {}. Opération annulée.'
.
format
(
move
[
'product_id'
][
1
],
net_available_stock
))
# Utilisation du nom du produit
# Si le stock est suffisant, on effectue l'action de transfert immédiat
api
.
execute
(
'stock.picking'
,
'stock_immediate_transfer'
,
[
picking_id
])
except
Exception
as
e
:
if
not
(
marshal_none_error
in
str
(
e
)):
...
...
@@ -109,7 +139,7 @@ class CagetteStock(models.Model):
errors
.
append
(
str
(
e
))
return
{
'errors'
:
errors
,
'picking_id'
:
picking
}
'picking_id'
:
picking
_id
}
### NOT IN USE ###
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment