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
Paul
odoo
Commits
10892577
Commit
10892577
authored
Mar 20, 2021
by
François C.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow supplier reference product search in purchase order context
parent
9b200321
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
174 additions
and
2 deletions
+174
-2
__init__.py
lacagette_addons/cagette_product/__init__.py
+1
-1
__openerp__.py
lacagette_addons/cagette_product/__openerp__.py
+7
-1
__init__.py
lacagette_addons/cagette_product/models/__init__.py
+3
-0
product_product.py
lacagette_addons/cagette_product/models/product_product.py
+96
-0
product_template.py
lacagette_addons/cagette_product/models/product_template.py
+67
-0
No files found.
lacagette_addons/cagette_product/__init__.py
View file @
10892577
...
...
@@ -4,4 +4,4 @@
# @author: La Cagette
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from
.
import
models
lacagette_addons/cagette_product/__openerp__.py
View file @
10892577
...
...
@@ -16,10 +16,16 @@
# method B, you need to add the module name of the method B in the 'depends'
# list before the module name of method A
{
'name'
:
'Cagette - Product'
,
'name'
:
'
La
Cagette - Product'
,
'version'
:
'9.0.1.1.6'
,
'category'
:
'Custom'
,
'summary'
:
'Implements La Cagette product specific views and action'
,
'description'
:
"""
Actions implémentées :
\n
- Impression d'étiquettes
- Lors de la recherche par nom d'un produit, rechercher également par code fournisseur
- Lors de la sauvegarde d'une fiche article, vérification de la validité du code barre (EAN8, EAN13 ou chaîne vide).
"""
,
'author'
:
'La Cagette'
,
'website'
:
'https://lacagette-coop.fr'
,
'depends'
:
[
...
...
lacagette_addons/cagette_product/models/__init__.py
0 → 100644
View file @
10892577
# -*- coding: utf-8 -*-
from
.
import
product_product
,
product_template
lacagette_addons/cagette_product/models/product_product.py
0 → 100644
View file @
10892577
# -*- encoding: utf-8 -*-
##############################################################################
#
# Product - Average Consumption Module for Odoo
# Copyright (C) 2021-Today GRAP (http://www.grap.coop)
# @author Damien Moulard
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from
openerp
import
models
,
fields
,
api
class
ProductProduct
(
models
.
Model
):
_inherit
=
"product.product"
@api.model
def
name_search
(
self
,
name
=
''
,
args
=
None
,
operator
=
'ilike'
,
limit
=
100
):
res
=
super
(
ProductProduct
,
self
)
.
name_search
(
name
=
name
,
args
=
args
,
operator
=
operator
,
context
=
self
.
_context
,
limit
=
limit
)
# Supplier id in self._context doesn't seem to be used in regular name_search,
# so don't use it here neither for consistency
# print(self._context)
try
:
# Context: asking for purchasable products: search with supplier code
if
args
[
0
][
0
]
==
'purchase_ok'
:
sql
=
"""
SELECT pt.name, pp.id, psi.product_code
FROM product_template pt
INNER JOIN product_product pp ON pt.id = pp.product_tmpl_id
INNER JOIN product_supplierinfo psi ON pt.id = psi.product_tmpl_id
WHERE pt.purchase_ok IS TRUE
AND psi.product_code ILIKE '{}
%
'
LIMIT {}
"""
.
format
(
name
,
limit
)
self
.
env
.
cr
.
execute
(
sql
)
psi
=
self
.
env
.
cr
.
dictfetchall
()
# Complete res to <limit> results,
# and/or replace in result to have at least 3 results from this search
nb_to_add
=
limit
-
len
(
res
)
nb_to_replace
=
0
if
len
(
res
)
==
limit
:
nb_to_replace
=
3
nb_to_add
=
0
elif
len
(
res
)
==
limit
-
1
:
nb_to_replace
=
2
nb_to_add
=
1
elif
len
(
res
)
==
limit
-
2
:
nb_to_replace
=
1
nb_to_add
=
2
# Replace last elements, if there are elements to replace
psi_i
=
0
i
=
0
while
i
<
nb_to_replace
and
psi_i
<
len
(
psi
):
psi_item
=
[
psi
[
psi_i
][
'id'
],
'[ref four. '
+
psi
[
psi_i
][
'product_code'
]
+
'] '
+
psi
[
psi_i
][
'name'
]
]
res
[
limit
-
nb_to_replace
+
i
]
=
psi_item
i
+=
1
psi_i
+=
1
# Add elements to complete to <limit> results
i
=
0
while
i
<
nb_to_add
and
psi_i
<
len
(
psi
):
psi_item
=
[
psi
[
psi_i
][
'id'
],
'[ref four. '
+
psi
[
psi_i
][
'product_code'
]
+
'] '
+
psi
[
psi_i
][
'name'
]
]
res
.
append
(
psi_item
)
i
+=
1
psi_i
+=
1
except
Exception
as
e
:
# Error is likely that there is no context: search normally
print
(
e
)
return
res
lacagette_addons/cagette_product/models/product_template.py
0 → 100644
View file @
10892577
# -*- encoding: utf-8 -*-
##############################################################################
#
# Product - Average Consumption Module for Odoo
# Copyright (C) 2021-Today GRAP (http://www.grap.coop)
# @author Damien Moulard
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from
openerp
import
models
,
fields
,
api
from
openerp.exceptions
import
ValidationError
import
math
class
ProductTemplate
(
models
.
Model
):
_inherit
=
"product.template"
@api.constrains
(
'barcode'
)
def
_check_barcode
(
self
):
""" Vérification du code barre avant de sauvegarder une fiche article"""
for
record
in
self
:
barcode_str
=
''
if
not
record
.
barcode
else
str
(
record
.
barcode
)
if
len
(
barcode_str
)
==
0
:
return
None
elif
not
barcode_str
.
isdigit
():
raise
ValidationError
(
"Le code-barre n'est pas au bon format : "
+
"il doit être composé de chiffres uniquement."
)
elif
(
len
(
barcode_str
)
>
0
and
len
(
barcode_str
)
!=
8
and
len
(
barcode_str
)
!=
13
):
raise
ValidationError
(
"Le code-barre n'est pas au bon format : "
+
"il faut 8 ou 13 chiffres. "
+
"Vous pouvez aussi laisser le champ vide."
)
else
:
# Vérification de la validité codebarre: calcul du dernier digit
# Sur un code-barre composé des chiffres (sans le dernier digit):
# N1 N2 ... Nn-1 Nn
# On calcule la somme :
# Nn * 3 + Nn-1 * 1 + Nn-2 * 3 + Nn-3 * 1 ...
# On soustrait le résultat à l'arrondi à la dizaine supérieur
# Le résultat devrait être le dernier digit
checksum
=
0
for
i
in
range
(
len
(
barcode_str
)
-
2
,
-
1
,
-
1
):
d
=
3
if
(
len
(
barcode_str
)
-
1
-
i
+
1
)
%
2
==
0
else
1
checksum
+=
int
(
barcode_str
[
i
])
*
d
roundup
=
int
(
math
.
ceil
(
checksum
/
10.0
)
*
10
)
check_digit
=
roundup
-
checksum
if
str
(
check_digit
)
!=
barcode_str
[
len
(
barcode_str
)
-
1
]:
raise
ValidationError
(
"Le code-barre n'est pas valide. "
+
"(la validation par la clé de vérification a échoué)"
)
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