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
cb2d1c59
Commit
cb2d1c59
authored
Apr 14, 2022
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ALC: display product price or prices
parent
2825333f
Pipeline
#2110
passed with stage
in 1 minute 27 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
24 deletions
+60
-24
oders_helper_style.css
orders/static/css/oders_helper_style.css
+2
-1
orders_helper.js
orders/static/js/orders_helper.js
+58
-23
No files found.
orders/static/css/oders_helper_style.css
View file @
cb2d1c59
...
@@ -264,7 +264,8 @@
...
@@ -264,7 +264,8 @@
padding
:
.5rem
.5rem
;
padding
:
.5rem
.5rem
;
}
}
.supplier_package_qty
{
.supplier_package_qty
,
.supplier_price
{
font-style
:
italic
;
font-style
:
italic
;
font-size
:
1.3rem
;
font-size
:
1.3rem
;
}
}
...
...
orders/static/js/orders_helper.js
View file @
cb2d1c59
...
@@ -31,7 +31,7 @@ var dbc = null,
...
@@ -31,7 +31,7 @@ var dbc = null,
var
clicked_order_pill
=
null
;
var
clicked_order_pill
=
null
;
let
userAgent
=
navigator
.
userAgent
;
let
userAgent
=
navigator
.
userAgent
;
var
timerId
;
var
timerId
=
null
;
/* - UTILS */
/* - UTILS */
...
@@ -272,8 +272,8 @@ function compute_purchase_qty_for_coverage(product, coeff, stock, incoming_qty,
...
@@ -272,8 +272,8 @@ function compute_purchase_qty_for_coverage(product, coeff, stock, incoming_qty,
purchase_package_qty_for_coverage
*=
coeff
;
purchase_package_qty_for_coverage
*=
coeff
;
}
}
}
}
// return Round up to unit for all products
return
Math
.
ceil
(
purchase_package_qty_for_coverage
);
return
Math
.
ceil
(
purchase_package_qty_for_coverage
);
// return Round up to unit for all products
}
}
function
compute_and_affect_product_supplier_quantities
(
coeff
,
days
)
{
function
compute_and_affect_product_supplier_quantities
(
coeff
,
days
)
{
...
@@ -282,22 +282,19 @@ function compute_and_affect_product_supplier_quantities(coeff, days) {
...
@@ -282,22 +282,19 @@ function compute_and_affect_product_supplier_quantities(coeff, days) {
product
product
]
of
Object
.
entries
(
products
))
{
]
of
Object
.
entries
(
products
))
{
if
(
'suppliersinfo'
in
product
&&
product
.
suppliersinfo
.
length
>
0
)
{
if
(
'suppliersinfo'
in
product
&&
product
.
suppliersinfo
.
length
>
0
)
{
let
purchase_qty_for_coverage
=
null
;
// Durée couverture produit = (stock + qté entrante + qté commandée ) / conso quotidienne
// Durée couverture produit = (stock + qté entrante + qté commandée ) / conso quotidienne
const
stock
=
product
.
qty_available
;
const
stock
=
product
.
qty_available
;
const
incoming_qty
=
product
.
incoming_qty
;
const
incoming_qty
=
product
.
incoming_qty
;
const
daily_conso
=
product
.
daily_conso
;
const
daily_conso
=
product
.
daily_conso
;
purchase_package_qty_for_coverage
=
compute_purchase_qty_for_coverage
(
product
,
coeff
,
stock
,
incoming_qty
,
daily_conso
,
days
);
let
purchase_package_qty_for_coverage
=
compute_purchase_qty_for_coverage
(
product
,
coeff
,
stock
,
incoming_qty
,
daily_conso
,
days
);
// Set qty to purchase for first supplier only
// Set qty to purchase for first supplier only
products
[
key
].
suppliersinfo
[
0
].
qty
=
purchase_package_qty_for_coverage
;
products
[
key
].
suppliersinfo
[
0
].
qty
=
purchase_package_qty_for_coverage
;
}
}
}
}
}
}
/**
/**
* Compute the qty to buy for each product, depending the coverage days.
* Compute the qty to buy for each product, depending the coverage days.
* Set the computed qty for the first supplier only.
* Set the computed qty for the first supplier only.
...
@@ -1431,12 +1428,23 @@ function display_suppliers() {
...
@@ -1431,12 +1428,23 @@ function display_suppliers() {
});
});
}
}
/**
* Compute data to display in products table
*
* Package qties & prices are related to suppliers,
* so 1 product can have multiple values for these.
* In case of different values, display value under input in supplier column
*
* @param {Object} product
* @returns Object of computed data to add to product object
*/
function
_compute_product_data
(
product
)
{
function
_compute_product_data
(
product
)
{
let
item
=
{};
let
item
=
{};
/* Supplier related data */
/* Supplier related data */
let
purchase_qty
=
0
;
// Calculate product's total purchase qty
let
purchase_qty
=
0
;
// Calculate product's total purchase qty
let
p_package_qties
=
[];
// Look for differences in package qties
let
p_package_qties
=
[];
// Look for differences in package qties
let
p_price
=
[];
for
(
let
p_supplierinfo
of
product
.
suppliersinfo
)
{
for
(
let
p_supplierinfo
of
product
.
suppliersinfo
)
{
// Preset qty for input if product related to supplier: existing qty or null (null -> qty to be set, display an empty input)
// Preset qty for input if product related to supplier: existing qty or null (null -> qty to be set, display an empty input)
...
@@ -1451,6 +1459,7 @@ function _compute_product_data(product) {
...
@@ -1451,6 +1459,7 @@ function _compute_product_data(product) {
// Store temporarily product package qties
// Store temporarily product package qties
p_package_qties
.
push
(
p_supplierinfo
.
package_qty
);
p_package_qties
.
push
(
p_supplierinfo
.
package_qty
);
p_price
.
push
(
p_supplierinfo
.
price
);
}
}
item
.
purchase_qty
=
purchase_qty
;
item
.
purchase_qty
=
purchase_qty
;
...
@@ -1463,13 +1472,19 @@ function _compute_product_data(product) {
...
@@ -1463,13 +1472,19 @@ function _compute_product_data(product) {
}
}
if
(
p_package_qties
.
length
==
0
||
!
p_package_qties
.
every
((
val
,
i
,
arr
)
=>
val
===
arr
[
0
]))
{
if
(
p_package_qties
.
length
==
0
||
!
p_package_qties
.
every
((
val
,
i
,
arr
)
=>
val
===
arr
[
0
]))
{
// Don't display package qty if no supplierinf
or if not all package qties are equals,
// Don't display package qty if no supplierinf
o or if not all package qties are equals
item
.
package_qty
=
'X'
;
item
.
package_qty
=
'X'
;
}
else
{
}
else
{
// If all package qties are equals, display it
// If all package qties are equals, display it
item
.
package_qty
=
p_package_qties
[
0
];
item
.
package_qty
=
p_package_qties
[
0
];
}
}
if
(
p_price
.
length
==
0
||
!
p_price
.
every
((
val
,
i
,
arr
)
=>
val
===
arr
[
0
]))
{
item
.
price
=
'X'
;
}
else
{
item
.
price
=
p_price
[
0
];
}
/* Coverage related data */
/* Coverage related data */
const
coverage_days
=
(
order_doc
.
coverage_days
!==
null
)
?
order_doc
.
coverage_days
:
0
;
const
coverage_days
=
(
order_doc
.
coverage_days
!==
null
)
?
order_doc
.
coverage_days
:
0
;
let
qty_not_covered
=
0
;
let
qty_not_covered
=
0
;
...
@@ -1607,6 +1622,7 @@ function prepare_datatable_columns() {
...
@@ -1607,6 +1622,7 @@ function prepare_datatable_columns() {
let
content
=
`<div id="
${
base_id
}
_cell_content" class="custom_cell_content">
let
content
=
`<div id="
${
base_id
}
_cell_content" class="custom_cell_content">
<input type="number" class="product_qty_input" id="
${
base_id
}
_qty_input" min="-1" value=
${
data
}
>`
;
<input type="number" class="product_qty_input" id="
${
base_id
}
_qty_input" min="-1" value=
${
data
}
>`
;
// Add package qty & price data if they differ between suppliers
if
(
full
.
package_qty
===
'X'
)
{
if
(
full
.
package_qty
===
'X'
)
{
let
product_data
=
products
.
find
(
p
=>
p
.
id
==
full
.
id
);
let
product_data
=
products
.
find
(
p
=>
p
.
id
==
full
.
id
);
...
@@ -1617,6 +1633,16 @@ function prepare_datatable_columns() {
...
@@ -1617,6 +1633,16 @@ function prepare_datatable_columns() {
}
}
}
}
if
(
full
.
price
===
'X'
)
{
let
product_data
=
products
.
find
(
p
=>
p
.
id
==
full
.
id
);
if
(
product_data
!==
undefined
)
{
let
supplierinfo
=
product_data
.
suppliersinfo
.
find
(
psi
=>
psi
.
supplier_id
==
supplier
.
id
);
content
+=
`<span class="supplier_price">Prix HT :
${
supplierinfo
.
price
}
€</span>`
;
}
}
content
+=
`</div>`
;
content
+=
`</div>`
;
return
content
;
return
content
;
...
@@ -1640,19 +1666,30 @@ function prepare_datatable_columns() {
...
@@ -1640,19 +1666,30 @@ function prepare_datatable_columns() {
});
});
columns
.
push
({
columns
.
push
({
data
:
"p
urchase_qty
"
,
data
:
"p
rice
"
,
title
:
"
Qté Achat
"
,
title
:
"
Prix HT
"
,
className
:
"dt-body-center"
,
className
:
"dt-body-center"
,
render
:
function
(
data
)
{
return
(
data
===
'X'
)
?
data
:
`
${
data
}
€`
;
},
width
:
"4%"
width
:
"4%"
});
});
columns
.
push
({
columns
.
push
({
data
:
"
qty_not_covered
"
,
data
:
"
purchase_qty
"
,
title
:
"
Besoin non couvert (qté)
"
,
title
:
"
Qté Achat
"
,
className
:
"dt-body-center"
,
className
:
"dt-body-center"
,
width
:
"4%"
width
:
"4%"
});
});
// Not in use for now
// columns.push({
// data: "qty_not_covered",
// title: "Besoin non couvert (qté)",
// className: "dt-body-center",
// width: "4%"
// });
columns
.
push
({
columns
.
push
({
data
:
"days_covered"
,
data
:
"days_covered"
,
title
:
"Jours de couverture"
,
title
:
"Jours de couverture"
,
...
@@ -1664,7 +1701,7 @@ function prepare_datatable_columns() {
...
@@ -1664,7 +1701,7 @@ function prepare_datatable_columns() {
title
:
``
,
title
:
``
,
className
:
"dt-body-center"
,
className
:
"dt-body-center"
,
orderable
:
false
,
orderable
:
false
,
render
:
function
(
data
)
{
render
:
function
()
{
return
`<button type="button" class="btn--primary product_actions">Actions</button>`
;
return
`<button type="button" class="btn--primary product_actions">Actions</button>`
;
},
},
width
:
"4%"
width
:
"4%"
...
@@ -1811,16 +1848,18 @@ function display_products(params) {
...
@@ -1811,16 +1848,18 @@ function display_products(params) {
.
focus
();
.
focus
();
}
}
})
})
.
on
(
'click'
,
'tbody td .product_actions'
,
function
(
e
)
{
.
on
(
'click'
,
'tbody td .product_actions'
,
function
()
{
// Save / unsave selected row
// Save / unsave selected row
const
p_id
=
products_table
.
row
(
$
(
this
).
closest
(
'tr'
)).
data
().
id
;
const
p_id
=
products_table
.
row
(
$
(
this
).
closest
(
'tr'
)).
data
().
id
;
const
product
=
products
.
find
(
p
=>
p
.
id
==
p_id
);
const
product
=
products
.
find
(
p
=>
p
.
id
==
p_id
);
let
modal_product_actions
=
$
(
'#templates #modal_product_actions'
);
let
modal_product_actions
=
$
(
'#templates #modal_product_actions'
);
modal_product_actions
.
find
(
".product_name"
).
text
(
product
.
name
);
modal_product_actions
.
find
(
".product_name"
).
text
(
product
.
name
);
modal_product_actions
.
find
(
".actual_stock_input"
).
val
(
product
.
qty_available
);
modal_product_actions
.
find
(
".actual_stock_input"
).
val
(
product
.
qty_available
);
const
product_can_be_archived
=
product
.
incoming_qty
===
0
;
const
product_can_be_archived
=
product
.
incoming_qty
===
0
;
if
(
product_can_be_archived
==
true
)
{
if
(
product_can_be_archived
==
true
)
{
modal_product_actions
.
find
(
'input[name="archive-action"]'
).
prop
(
"disabled"
,
false
);
modal_product_actions
.
find
(
'input[name="archive-action"]'
).
prop
(
"disabled"
,
false
);
modal_product_actions
.
find
(
'input[name="archive-action"]'
).
closest
(
"label"
)
modal_product_actions
.
find
(
'input[name="archive-action"]'
).
closest
(
"label"
)
...
@@ -1832,6 +1871,7 @@ function display_products(params) {
...
@@ -1832,6 +1871,7 @@ function display_products(params) {
}
}
let
product_price_action_template
=
$
(
'#templates #product_price_action_template'
);
let
product_price_action_template
=
$
(
'#templates #product_price_action_template'
);
modal_product_actions
.
find
(
".product_prices_area"
).
empty
();
modal_product_actions
.
find
(
".product_prices_area"
).
empty
();
for
(
let
supplierinfo
of
product
.
suppliersinfo
)
{
for
(
let
supplierinfo
of
product
.
suppliersinfo
)
{
let
supplier
=
suppliers_list
.
find
(
s
=>
s
.
id
==
supplierinfo
.
supplier_id
);
let
supplier
=
suppliers_list
.
find
(
s
=>
s
.
id
==
supplierinfo
.
supplier_id
);
...
@@ -2639,17 +2679,12 @@ $(document).ready(function() {
...
@@ -2639,17 +2679,12 @@ $(document).ready(function() {
// Have to capture mousedown and mouseup events, instead of using only click event
// Have to capture mousedown and mouseup events, instead of using only click event
// Indeed, capturing click only remove the ability to click to have focus on the input to type a number.
// Indeed, capturing click only remove the ability to click to have focus on the input to type a number.
$
(
document
).
on
(
"mousedown"
,
'[type="number"]'
,
function
()
{
$
(
document
).
on
(
"mousedown"
,
'[type="number"]'
,
function
()
{
const
clicked
=
this
;
qties_values
[
$
(
this
).
attr
(
'id'
)]
=
$
(
this
).
val
();
qties_values
[
$
(
clicked
).
attr
(
'id'
)]
=
$
(
clicked
).
val
();
});
});
$
(
document
).
on
(
"mouseup"
,
'[type="number"]'
,
function
()
{
$
(
document
).
on
(
"mouseup"
,
'[type="number"]'
,
function
()
{
const
clicked
=
this
;
try
{
try
{
if
(
$
(
clicked
).
val
()
!=
qties_values
[
$
(
clicked
).
attr
(
'id'
)])
{
if
(
$
(
this
).
val
()
!=
qties_values
[
$
(
this
).
attr
(
'id'
)])
{
process_new_product_qty
(
clicked
);
process_new_product_qty
(
this
);
}
}
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
...
...
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