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
b58475ef
Commit
b58475ef
authored
Aug 10, 2023
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent mona & meal voucher payment above remaining due amount
parent
e0850dfb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
20 deletions
+94
-20
models.js
lacagette_addons/lacagette_mona/static/src/js/models.js
+2
-2
screens.js
lacagette_addons/lacagette_mona/static/src/js/screens.js
+61
-9
fr.po
lacagette_addons/pos_meal_voucher/i18n/fr.po
+1
-1
screens.js
lacagette_addons/pos_meal_voucher/static/src/js/screens.js
+30
-8
No files found.
lacagette_addons/lacagette_mona/static/src/js/models.js
View file @
b58475ef
...
@@ -10,9 +10,9 @@ odoo.define("lacagette_mona.models", function (require) {
...
@@ -10,9 +10,9 @@ odoo.define("lacagette_mona.models", function (require) {
var
OrderSuper
=
models
.
Order
.
prototype
;
var
OrderSuper
=
models
.
Order
.
prototype
;
var
Order
=
models
.
Order
.
extend
({
var
Order
=
models
.
Order
.
extend
({
get_total_mona_received
:
function
(){
get_total_mona_received
:
function
(
ignore_selected_line
=
false
){
return
round_pr
(
this
.
paymentlines
.
reduce
((
function
(
sum
,
paymentLine
)
{
return
round_pr
(
this
.
paymentlines
.
reduce
((
function
(
sum
,
paymentLine
)
{
if
(
paymentLine
.
is_mona
())
{
if
(
paymentLine
.
is_mona
()
&&
(
!
ignore_selected_line
||
ignore_selected_line
&&
!
paymentLine
.
selected
)
)
{
return
sum
+
paymentLine
.
get_amount
();
return
sum
+
paymentLine
.
get_amount
();
}
else
{
}
else
{
return
sum
;
return
sum
;
...
...
lacagette_addons/lacagette_mona/static/src/js/screens.js
View file @
b58475ef
...
@@ -8,27 +8,25 @@ odoo.define("lacagette_mona.screens", function (require) {
...
@@ -8,27 +8,25 @@ odoo.define("lacagette_mona.screens", function (require) {
var
QWeb
=
core
.
qweb
;
var
QWeb
=
core
.
qweb
;
var
Model
=
require
(
'web.DataModel'
);
var
Model
=
require
(
'web.DataModel'
);
var
config_parameter
=
new
Model
(
'ir.config_parameter'
);
var
config_parameter
=
new
Model
(
'ir.config_parameter'
);
var
utils
=
require
(
"web.utils"
);
var
round_pr
=
utils
.
round_precision
;
screens
.
PaymentScreenWidget
.
include
({
screens
.
PaymentScreenWidget
.
include
({
click_paymentmethods
:
function
(
id
)
{
click_paymentmethods
:
function
(
id
)
{
var
self
=
this
;
var
self
=
this
;
var
methods
=
this
.
_super
.
apply
(
this
,
arguments
);
var
methods
=
this
.
_super
.
apply
(
this
,
arguments
);
// NOTE: applying _super() before mona checks might cause side effects (payment terminal issue?)
var
paymentScreen
=
this
.
pos
.
gui
.
current_screen
;
var
paymentScreen
=
this
.
pos
.
gui
.
current_screen
;
var
order
=
this
.
pos
.
get_order
();
var
order
=
this
.
pos
.
get_order
();
if
(
!
order
.
selected_paymentline
.
is_meal_voucher
()
&&
order
.
selected_paymentline
.
cashregister
.
journal
.
mona_used
)
{
if
(
!
order
.
selected_paymentline
.
is_meal_voucher
()
&&
order
.
selected_paymentline
.
cashregister
.
journal
.
mona_used
)
{
let
total_mona_eligible
=
order
.
get_total_mona_eligible_including_meal_vouchers
();
let
total_mona_eligible
=
order
.
get_total_mona_eligible_including_meal_vouchers
();
let
mona_payment_amount
=
total_mona_eligible
;
let
total_mona_received_without_last_line
=
order
.
get_total_mona_received
(
true
);
order
.
selected_paymentline
.
set_amount
(
total_mona_eligible
);
// Mona limit already reached
paymentScreen
.
order_changes
();
if
(
total_mona_received_without_last_line
===
total_mona_eligible
)
{
paymentScreen
.
render_paymentlines
();
paymentScreen
.
$
(
".paymentline.selected .edit"
).
text
(
paymentScreen
.
format_currency_no_symbol
(
total_mona_eligible
));
let
total_mona_received
=
order
.
get_total_mona_received
();
if
(
total_mona_received
>
total_mona_eligible
)
{
this
.
gui
.
show_popup
(
"alert"
,
{
this
.
gui
.
show_popup
(
"alert"
,
{
'title'
:
_t
(
"Impossible de rajouter un paiement MonA"
),
'title'
:
_t
(
"Impossible de rajouter un paiement MonA"
),
'body'
:
_t
(
"Le montant éligible a déjà été payé."
),
'body'
:
_t
(
"Le montant éligible a déjà été payé."
),
...
@@ -36,7 +34,29 @@ odoo.define("lacagette_mona.screens", function (require) {
...
@@ -36,7 +34,29 @@ odoo.define("lacagette_mona.screens", function (require) {
self
.
remove_selected_paymentline
(
order
);
self
.
remove_selected_paymentline
(
order
);
}
}
});
});
return
;
}
// if mona payment already exists & was less than total eligible
if
(
total_mona_received_without_last_line
>
0
&&
total_mona_received_without_last_line
<
total_mona_eligible
)
{
mona_payment_amount
=
total_mona_eligible
-
total_mona_received_without_last_line
;
}
/* Limit payment to remaining order due amount */
// simulate paid amount: last payment line replaced with mona amount
let
total_before_last_line
=
round_pr
(
order
.
get_total_paid
()
-
order
.
selected_paymentline
.
get_amount
(),
this
.
pos
.
currency
.
rounding
);
let
amount_paid_with_mona
=
round_pr
(
total_before_last_line
+
mona_payment_amount
,
this
.
pos
.
currency
.
rounding
);
let
order_total
=
order
.
get_total_with_tax
();
// equivalent to check if mona payment amount > due amount. If so limit eligible amount to due amount.
if
(
amount_paid_with_mona
>
order_total
)
{
mona_payment_amount
=
round_pr
(
order_total
-
total_before_last_line
,
this
.
pos
.
currency
.
rounding
);
}
}
order
.
selected_paymentline
.
set_amount
(
mona_payment_amount
);
paymentScreen
.
order_changes
();
paymentScreen
.
render_paymentlines
();
paymentScreen
.
$
(
".paymentline.selected .edit"
).
text
(
paymentScreen
.
format_currency_no_symbol
(
mona_payment_amount
));
}
else
if
(
order
.
selected_paymentline
.
is_meal_voucher
()
&&
order
.
get_total_meal_vouchers_eligible_including_mona
()
==
0
)
{
}
else
if
(
order
.
selected_paymentline
.
is_meal_voucher
()
&&
order
.
get_total_meal_vouchers_eligible_including_mona
()
==
0
)
{
this
.
gui
.
show_popup
(
"alert"
,
{
this
.
gui
.
show_popup
(
"alert"
,
{
'title'
:
_t
(
"Impossible de payer en titre restaurant"
),
'title'
:
_t
(
"Impossible de payer en titre restaurant"
),
...
@@ -67,5 +87,37 @@ odoo.define("lacagette_mona.screens", function (require) {
...
@@ -67,5 +87,37 @@ odoo.define("lacagette_mona.screens", function (require) {
this
.
el
.
querySelector
(
"#monA-received-amount"
).
textContent
=
this
.
format_currency
(
total_mona_received
);
this
.
el
.
querySelector
(
"#monA-received-amount"
).
textContent
=
this
.
format_currency
(
total_mona_received
);
}
}
},
},
payment_input
:
function
(
input
)
{
this
.
_super
.
apply
(
this
,
arguments
);
var
order
=
this
.
pos
.
get_order
();
if
(
order
.
selected_paymentline
&&
order
.
selected_paymentline
.
cashregister
.
journal
.
mona_used
)
{
var
total_eligible
=
order
.
get_total_mona_eligible_including_meal_vouchers
();
var
total_received
=
order
.
get_total_mona_received
();
let
current_max
=
total_eligible
;
// If there is change -> the amount of last payment line was above the order remaining due amount
let
order_change
=
order
.
get_change
();
if
(
order_change
>
0
)
{
let
last_line_amount
=
order
.
selected_paymentline
.
get_amount
();
let
limit_amount
=
round_pr
(
last_line_amount
-
order_change
,
this
.
pos
.
currency
.
rounding
)
current_max
=
Math
.
min
(
current_max
,
limit_amount
);
}
if
(
total_received
>
current_max
){
this
.
gui
.
show_popup
(
"alert"
,
{
'title'
:
_t
(
"Montant MonA incorrect"
),
'body'
:
_t
(
"Le montant saisi est supérieur au maximum éligible/au montant restant dû de "
)
+
this
.
format_currency
(
current_max
),
});
const
max_current_amount
=
current_max
-
total_received
+
order
.
selected_paymentline
.
get_amount
()
;
order
.
selected_paymentline
.
set_amount
(
max_current_amount
);
this
.
order_changes
();
this
.
render_paymentlines
();
this
.
$
(
'.paymentline.selected .edit'
).
text
(
this
.
format_currency_no_symbol
(
max_current_amount
));
this
.
inputbuffer
=
""
;
}
}
},
});
});
});
});
lacagette_addons/pos_meal_voucher/i18n/fr.po
View file @
b58475ef
...
@@ -318,7 +318,7 @@ msgstr " ) est inférieur à la valeur du/des ticket(s)( "
...
@@ -318,7 +318,7 @@ msgstr " ) est inférieur à la valeur du/des ticket(s)( "
#: code:addons/pos_meal_voucher/static/src/js/screens.js:110
#: code:addons/pos_meal_voucher/static/src/js/screens.js:110
#, python-format
#, python-format
msgid "Warning, the input amount of meal voucher is above the maximum amount of "
msgid "Warning, the input amount of meal voucher is above the maximum amount of "
msgstr "Le montant saisi est supérieur au montant maximum/au maximum éligible de "
msgstr "Le montant saisi est supérieur au montant maximum/au maximum éligible
/au montant restant dû
de "
#. module: pos_meal_voucher
#. module: pos_meal_voucher
#. openerp-web
#. openerp-web
...
...
lacagette_addons/pos_meal_voucher/static/src/js/screens.js
View file @
b58475ef
...
@@ -12,6 +12,8 @@ odoo.define("pos_meal_voucher.screens", function (require) {
...
@@ -12,6 +12,8 @@ odoo.define("pos_meal_voucher.screens", function (require) {
var
QWeb
=
core
.
qweb
;
var
QWeb
=
core
.
qweb
;
var
Model
=
require
(
'web.DataModel'
);
var
Model
=
require
(
'web.DataModel'
);
var
config_parameter
=
new
Model
(
'ir.config_parameter'
);
var
config_parameter
=
new
Model
(
'ir.config_parameter'
);
var
utils
=
require
(
"web.utils"
);
var
round_pr
=
utils
.
round_precision
;
screens
.
ScreenWidget
.
include
({
screens
.
ScreenWidget
.
include
({
barcode_meal_voucher_payment_action
:
function
(
code
)
{
barcode_meal_voucher_payment_action
:
function
(
code
)
{
...
@@ -28,8 +30,16 @@ odoo.define("pos_meal_voucher.screens", function (require) {
...
@@ -28,8 +30,16 @@ odoo.define("pos_meal_voucher.screens", function (require) {
var
total_eligible
=
order
.
get_total_meal_voucher_eligible
();
var
total_eligible
=
order
.
get_total_meal_voucher_eligible
();
var
max_amount
=
this
.
pos
.
config
.
max_meal_voucher_amount
;
var
max_amount
=
this
.
pos
.
config
.
max_meal_voucher_amount
;
var
total_received
=
order
.
get_total_meal_voucher_received
()
+
amount
;
var
total_received
=
order
.
get_total_meal_voucher_received
()
+
amount
;
let
order_due
=
order
.
get_due
();
// Display info popup if amount is too high
// Display info popup if amount is too high
if
(
total_received
>
order_due
)
{
this
.
gui
.
show_popup
(
"alert"
,
{
'title'
:
_t
(
"Impossible d'utiliser ce Titre Restaurant"
),
'body'
:
_t
(
"Vous ne pouvez pas ajouter ce ticket restaurant car le montant total est supérieur au montant restant dû de la commande"
)
});
return
;
}
if
(
total_received
>
total_eligible
)
{
if
(
total_received
>
total_eligible
)
{
this
.
gui
.
show_popup
(
"alert"
,
{
this
.
gui
.
show_popup
(
"alert"
,
{
'title'
:
_t
(
"Impossible d'utiliser ce Titre Restaurant"
),
'title'
:
_t
(
"Impossible d'utiliser ce Titre Restaurant"
),
...
@@ -243,18 +253,26 @@ odoo.define("pos_meal_voucher.screens", function (require) {
...
@@ -243,18 +253,26 @@ odoo.define("pos_meal_voucher.screens", function (require) {
if
(
max_amount
)
{
if
(
max_amount
)
{
current_max
=
Math
.
min
(
total_eligible
,
max_amount
);
current_max
=
Math
.
min
(
total_eligible
,
max_amount
);
}
}
// If there is change -> the amount of last payment line was above the order remaining due amount
let
order_change
=
order
.
get_change
();
if
(
order_change
>
0
)
{
let
last_line_amount
=
order
.
selected_paymentline
.
get_amount
();
let
limit_amount
=
round_pr
(
last_line_amount
-
order_change
,
this
.
pos
.
currency
.
rounding
)
current_max
=
Math
.
min
(
current_max
,
limit_amount
);
}
if
(
total_received
>
current_max
){
if
(
total_received
>
current_max
){
this
.
gui
.
show_popup
(
"alert"
,
{
this
.
gui
.
show_popup
(
"alert"
,
{
'title'
:
_t
(
"Meal Voucher Amount incorrect"
),
'title'
:
_t
(
"Meal Voucher Amount incorrect"
),
'body'
:
_t
(
"
Warning, the input amount of meal voucher is above the maximum amount of
"
)
+
'body'
:
_t
(
"
Le montant saisi est supérieur au maximum éligible/au montant restant dû de
"
)
+
this
.
format_currency
(
current_max
),
this
.
format_currency
(
current_max
),
});
});
const
max_curent_amount
=
current_max
-
total_received
+
order
.
selected_paymentline
.
get_amount
()
;
const
max_cur
r
ent_amount
=
current_max
-
total_received
+
order
.
selected_paymentline
.
get_amount
()
;
order
.
selected_paymentline
.
set_amount
(
max_curent_amount
);
order
.
selected_paymentline
.
set_amount
(
max_cur
r
ent_amount
);
this
.
order_changes
();
this
.
order_changes
();
this
.
render_paymentlines
();
this
.
render_paymentlines
();
this
.
$
(
'.paymentline.selected .edit'
).
text
(
this
.
format_currency_no_symbol
(
max_curent_amount
));
this
.
$
(
'.paymentline.selected .edit'
).
text
(
this
.
format_currency_no_symbol
(
max_cur
r
ent_amount
));
this
.
inputbuffer
=
""
;
this
.
inputbuffer
=
""
;
}
}
...
@@ -326,14 +344,18 @@ odoo.define("pos_meal_voucher.screens", function (require) {
...
@@ -326,14 +344,18 @@ odoo.define("pos_meal_voucher.screens", function (require) {
// Check how much is still possible to pay with meal voucher
// Check how much is still possible to pay with meal voucher
// The selected line is "by default" set to the rest to pay of the order
// The selected line is "by default" set to the rest to pay of the order
const
max_curent_amount
=
current_max
-
total_received
+
order
.
selected_paymentline
.
get_amount
();
let
max_current_amount
=
current_max
-
total_received
+
order
.
selected_paymentline
.
get_amount
();
// Limit the amount paid to the remaining due amount
const
order_due_amount
=
order
.
get_due
();
max_current_amount
=
Math
.
min
(
max_current_amount
,
order_due_amount
);
order
.
selected_paymentline
.
set_amount
(
max_curent_amount
);
order
.
selected_paymentline
.
set_amount
(
max_cur
r
ent_amount
);
order
.
selected_paymentline
.
set_meal_voucher_issuer
(
issuer
);
order
.
selected_paymentline
.
set_meal_voucher_issuer
(
issuer
);
paymentScreen
.
order_changes
();
paymentScreen
.
order_changes
();
paymentScreen
.
render_paymentlines
();
paymentScreen
.
render_paymentlines
();
paymentScreen
.
$
(
".paymentline.selected .edit"
).
text
(
paymentScreen
.
format_currency_no_symbol
(
max_curent_amount
));
paymentScreen
.
$
(
".paymentline.selected .edit"
).
text
(
paymentScreen
.
format_currency_no_symbol
(
max_cur
r
ent_amount
));
}
}
// If required by the config, ask for the meal voucher issuer
// If required by the config, ask for the meal voucher issuer
...
...
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