Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
odoo
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
0
Merge Requests
0
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
odoo
Commits
f42b52db
Commit
f42b52db
authored
Jun 06, 2021
by
François C.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent user to order the same product twice in an a single purchase order
parent
57044e23
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
1 deletions
+24
-1
purchase_order.py
lacagette_addons/lacagette_purchase/models/purchase_order.py
+24
-1
No files found.
lacagette_addons/lacagette_purchase/models/purchase_order.py
View file @
f42b52db
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from
openerp
import
api
,
models
,
fields
from
openerp
import
api
,
models
,
fields
from
openerp.tools.translate
import
_
from
openerp.exceptions
import
UserError
class
PurchaseOrder
(
models
.
Model
):
class
PurchaseOrder
(
models
.
Model
):
_inherit
=
'purchase.order'
_inherit
=
'purchase.order'
def
verify_product_line_unicity
(
self
):
pdts
=
{}
for
order
in
self
:
for
line
in
order
.
order_line
:
if
not
line
.
product_id
.
id
in
pdts
:
pdts
[
line
.
product_id
.
id
]
=
0
pdts
[
line
.
product_id
.
id
]
+=
1
pids
=
[]
for
pid
,
nb
in
pdts
.
items
():
if
nb
>
1
:
pids
.
append
(
pid
)
if
len
(
pids
)
>
0
:
products
=
self
.
env
[
'product.product'
]
.
search
([(
'id'
,
'in'
,
pids
)])
message
=
''
for
p
in
products
:
message
+=
p
.
display_name
+
' ('
+
str
(
p
.
product_tmpl_id
.
id
)
+
')'
message
+=
' --> '
+
str
(
pdts
[
p
.
id
])
+
" lines
\n
"
raise
UserError
(
_
(
message
))
@api.multi
@api.multi
def
write
(
self
,
vals
):
def
write
(
self
,
vals
):
res
=
super
(
PurchaseOrder
,
self
)
.
write
(
vals
)
res
=
super
(
PurchaseOrder
,
self
)
.
write
(
vals
)
if
'state'
in
vals
and
vals
[
'state'
]
==
'purchase'
:
if
'state'
in
vals
and
vals
[
'state'
]
==
'purchase'
:
import
requests
import
requests
# First of all, verify that no product has been added twice or more
# an error is raised if a product appears more than once
self
.
verify_product_line_unicity
()
conf
=
self
.
env
[
'ir.config_parameter'
]
conf
=
self
.
env
[
'ir.config_parameter'
]
export_url
=
str
(
conf
.
get_param
(
'cagette_purchase.orders_proxy_url'
))
.
strip
()
export_url
=
str
(
conf
.
get_param
(
'cagette_purchase.orders_proxy_url'
))
.
strip
()
export_url
+=
'/export/'
+
str
(
self
.
id
)
export_url
+=
'/export/'
+
str
(
self
.
id
)
...
...
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