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
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
Alexis AOUN
third-party
Commits
ae23416e
Commit
ae23416e
authored
Jun 25, 2021
by
Damien Moulard
Committed by
Alexis Aoun
Jul 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add total qty to buy field
parent
493a9296
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
22 deletions
+58
-22
orders_helper.js
orders/static/js/orders_helper.js
+49
-21
models.py
products/models.py
+9
-1
No files found.
orders/static/js/orders_helper.js
View file @
ae23416e
...
@@ -260,7 +260,6 @@ function is_product_related_to_supplier(product, supplier) {
...
@@ -260,7 +260,6 @@ function is_product_related_to_supplier(product, supplier) {
/**
/**
* Update 'purchase_ok' of a product
* Update 'purchase_ok' of a product
*
*
* @param {int} p_id product id
* @param {int} p_id product id
* @param {Boolean} npa value to set purchase_ok to
* @param {Boolean} npa value to set purchase_ok to
*/
*/
...
@@ -382,22 +381,6 @@ function generate_inventory() {
...
@@ -382,22 +381,6 @@ function generate_inventory() {
/* - ORDER */
/* - ORDER */
function
goto_main_screen
(
doc
)
{
order_doc
=
doc
;
products
=
order_doc
.
products
;
selected_suppliers
=
order_doc
.
selected_suppliers
;
update_order
();
update_main_screen
();
switch_screen
();
}
function
back
()
{
reset_data
();
update_order_selection_screen
();
switch_screen
(
'order_selection'
);
}
/**
/**
* Event fct: on click on an order button
* Event fct: on click on an order button
*/
*/
...
@@ -499,6 +482,22 @@ function update_order() {
...
@@ -499,6 +482,22 @@ function update_order() {
/* - DISPLAY */
/* - DISPLAY */
function
goto_main_screen
(
doc
)
{
order_doc
=
doc
;
products
=
order_doc
.
products
;
selected_suppliers
=
order_doc
.
selected_suppliers
;
update_order
();
update_main_screen
();
switch_screen
();
}
function
back
()
{
reset_data
();
update_order_selection_screen
();
switch_screen
(
'order_selection'
);
}
/**
/**
* Create a string to represent a supplier column in product data
* Create a string to represent a supplier column in product data
* @returns String
* @returns String
...
@@ -559,6 +558,9 @@ function prepare_datatable_data(product_ids = []) {
...
@@ -559,6 +558,9 @@ function prepare_datatable_data(product_ids = []) {
}
}
for
(
product
of
products_to_format
)
{
for
(
product
of
products_to_format
)
{
// Calculate product's total qty to buy
let
qty_to_buy
=
0
;
let
item
=
{
let
item
=
{
id
:
product
.
id
,
id
:
product
.
id
,
name
:
product
.
name
,
name
:
product
.
name
,
...
@@ -569,17 +571,26 @@ function prepare_datatable_data(product_ids = []) {
...
@@ -569,17 +571,26 @@ function prepare_datatable_data(product_ids = []) {
uom
:
product
.
uom_id
[
1
]
uom
:
product
.
uom_id
[
1
]
};
};
// If product
not related to supplier : false ; else null (qty to be set) or qty
// If product
related to supplier: qty or null (qty to be set)
for
(
product_supplier
of
product
.
suppliers
)
{
for
(
product_supplier
of
product
.
suppliers
)
{
item
[
supplier_column_name
(
product_supplier
)]
=
(
"qty"
in
product_supplier
)
?
product_supplier
.
qty
:
null
;
let
supplier_qty
=
(
"qty"
in
product_supplier
)
?
product_supplier
.
qty
:
null
;
item
[
supplier_column_name
(
product_supplier
)]
=
supplier_qty
;
// Update product's total qty to buy if qty set for this supplier
if
(
supplier_qty
!==
null
)
{
// TODO calculate according to package_qty
qty_to_buy
+=
supplier_qty
;
}
}
}
// If product not related to supplier: false;
for
(
supplier
of
selected_suppliers
)
{
for
(
supplier
of
selected_suppliers
)
{
if
(
!
is_product_related_to_supplier
(
product
,
supplier
))
{
if
(
!
is_product_related_to_supplier
(
product
,
supplier
))
{
item
[
supplier_column_name
(
supplier
)]
=
false
;
item
[
supplier_column_name
(
supplier
)]
=
false
;
}
}
}
}
item
.
qty_to_buy
=
qty_to_buy
;
data
.
push
(
item
);
data
.
push
(
item
);
}
}
...
@@ -590,7 +601,7 @@ function prepare_datatable_data(product_ids = []) {
...
@@ -590,7 +601,7 @@ function prepare_datatable_data(product_ids = []) {
* @returns Array of formatted data for datatable columns setup
* @returns Array of formatted data for datatable columns setup
*/
*/
function
prepare_datatable_columns
()
{
function
prepare_datatable_columns
()
{
columns
=
[
let
columns
=
[
{
{
data
:
"id"
,
data
:
"id"
,
title
:
`<div id="table_header_select_all" class="txtcenter">
title
:
`<div id="table_header_select_all" class="txtcenter">
...
@@ -630,11 +641,13 @@ function prepare_datatable_columns() {
...
@@ -630,11 +641,13 @@ function prepare_datatable_columns() {
{
{
data
:
"qty_available"
,
data
:
"qty_available"
,
title
:
"Stock"
,
title
:
"Stock"
,
className
:
"dt-body-center"
,
width
:
"4%"
width
:
"4%"
},
},
{
{
data
:
"incoming_qty"
,
data
:
"incoming_qty"
,
title
:
"Quantité entrante"
,
title
:
"Quantité entrante"
,
className
:
"dt-body-center"
,
width
:
"4%"
width
:
"4%"
}
}
];
];
...
@@ -662,6 +675,14 @@ function prepare_datatable_columns() {
...
@@ -662,6 +675,14 @@ function prepare_datatable_columns() {
columns
.
push
({
columns
.
push
({
data
:
"uom"
,
data
:
"uom"
,
title
:
"UDM"
,
title
:
"UDM"
,
className
:
"dt-body-center"
,
width
:
"4%"
});
columns
.
push
({
data
:
"qty_to_buy"
,
title
:
"Qté Achat"
,
className
:
"dt-body-center"
,
width
:
"4%"
width
:
"4%"
});
});
...
@@ -716,7 +737,7 @@ function display_products() {
...
@@ -716,7 +737,7 @@ function display_products() {
$
(
'.main'
).
show
();
$
(
'.main'
).
show
();
//
Save value o
n inputs change
//
O
n inputs change
$
(
'#products_table'
).
on
(
'input'
,
'tbody td .product_qty_input'
,
function
()
{
$
(
'#products_table'
).
on
(
'input'
,
'tbody td .product_qty_input'
,
function
()
{
let
val
=
parseFloat
(
$
(
this
).
val
());
let
val
=
parseFloat
(
$
(
this
).
val
());
...
@@ -727,7 +748,14 @@ function display_products() {
...
@@ -727,7 +748,14 @@ function display_products() {
const
prod_id
=
id_split
[
1
];
const
prod_id
=
id_split
[
1
];
const
supplier_id
=
id_split
[
3
];
const
supplier_id
=
id_split
[
3
];
// Save value
save_product_supplier_qty
(
prod_id
,
supplier_id
,
val
);
save_product_supplier_qty
(
prod_id
,
supplier_id
,
val
);
// Update row
const
product
=
products
.
find
(
p
=>
p
.
id
==
prod_id
);
const
new_row_data
=
prepare_datatable_data
([
product
.
id
])[
0
];
products_table
.
row
(
$
(
this
).
closest
(
'tr'
)).
data
(
new_row_data
).
draw
();
update_order
();
update_order
();
}
}
});
});
...
...
products/models.py
View file @
ae23416e
...
@@ -436,7 +436,7 @@ class CagetteProducts(models.Model):
...
@@ -436,7 +436,7 @@ class CagetteProducts(models.Model):
today
=
datetime
.
date
.
today
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
today
=
datetime
.
date
.
today
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
# Get products/supplier relation
# Get products/supplier relation
f
=
[
"product_tmpl_id"
,
'date_start'
,
'date_end'
]
f
=
[
"product_tmpl_id"
,
'date_start'
,
'date_end'
,
'package_qty'
]
c
=
[[
'name'
,
'='
,
int
(
supplier_id
)]]
c
=
[[
'name'
,
'='
,
int
(
supplier_id
)]]
psi
=
api
.
search_read
(
'product.supplierinfo'
,
c
,
f
)
psi
=
api
.
search_read
(
'product.supplierinfo'
,
c
,
f
)
...
@@ -455,6 +455,14 @@ class CagetteProducts(models.Model):
...
@@ -455,6 +455,14 @@ class CagetteProducts(models.Model):
products_t
=
api
.
search_read
(
'product.template'
,
c
,
f
)
products_t
=
api
.
search_read
(
'product.template'
,
c
,
f
)
filtered_products_t
=
[
p
for
p
in
products_t
if
p
[
"state"
]
!=
"end"
and
p
[
"state"
]
!=
"obsolete"
]
filtered_products_t
=
[
p
for
p
in
products_t
if
p
[
"state"
]
!=
"end"
and
p
[
"state"
]
!=
"obsolete"
]
# Add package qty to product data
for
i
,
fp
in
enumerate
(
filtered_products_t
):
psi_item
=
next
(
item
for
item
in
psi
if
item
[
"product_tmpl_id"
]
is
not
False
and
item
[
"product_tmpl_id"
][
0
]
==
fp
[
"id"
])
filtered_products_t
[
i
][
'supplierinfo'
]
=
{
'supplier_id'
:
supplier_id
,
'package_qty'
:
psi_item
[
"package_qty"
]
}
# Note: if product.product is needed, get "product_variant_ids" from product template
# Note: if product.product is needed, get "product_variant_ids" from product template
res
[
"products"
]
=
filtered_products_t
res
[
"products"
]
=
filtered_products_t
...
...
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