summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Masereel <pim@odoo.com>2020-11-03 14:06:16 +0000
committerPierre Masereel <pim@odoo.com>2020-11-04 10:06:30 +0000
commitd48e657ab33d3752f903bd1ee9286bf902ba87af (patch)
tree2160d082530eb31db3b4a87b4b36091a58f16264
parent77ffd6343be21ef188046f138493e1e807090c48 (diff)
[FIX] pos_cash_rounding: allow rounding only cash method
When you enable the cash rounding in POS, all your payment methods are rounded in the POS. In some countries, only the cash methods must be rounded, so we enable here the possibility to activate the rounding only on the cash methods. OPW-2373516 and OPW-2366101 closes odoo/odoo#61310 X-original-commit: 9b03fd67f856ec8e5b37652a5ed551ec159973e5 Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
-rw-r--r--addons/point_of_sale/static/src/js/models.js31
-rw-r--r--addons/point_of_sale/views/pos_config_view.xml4
2 files changed, 23 insertions, 12 deletions
diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js
index 28be287c0df..1d0b6c78d03 100644
--- a/addons/point_of_sale/static/src/js/models.js
+++ b/addons/point_of_sale/static/src/js/models.js
@@ -3291,20 +3291,27 @@ exports.Order = Backbone.Model.extend({
},
get_rounding_applied: function() {
if(this.pos.config.cash_rounding) {
- var total = round_pr(this.get_total_with_tax(), this.pos.cash_rounding[0].rounding);
-
- var rounding_applied = total - (this.pos.config['iface_tax_included'] === "total"? this.get_subtotal(): this.get_total_with_tax());
- // because floor and ceil doesn't include decimals in calculation, we reuse the value of the half-up and adapt it.
- if (utils.float_is_zero(rounding_applied, this.pos.currency.decimals)){
- // https://xkcd.com/217/
- return 0;
- } else if(this.pos.cash_rounding[0].rounding_method === "UP" && rounding_applied < 0) {
- rounding_applied += this.pos.cash_rounding[0].rounding;
+ const only_cash = this.pos.config.only_round_cash_method;
+ const has_cash = _.some(this.get_paymentlines(), function(pl) { return pl.payment_method.is_cash_count == true;});
+ if (!only_cash || (only_cash && has_cash)) {
+ var total = round_pr(this.get_total_with_tax(), this.pos.cash_rounding[0].rounding);
+
+ var rounding_applied = total - (this.pos.config['iface_tax_included'] === "total"? this.get_subtotal(): this.get_total_with_tax());
+ // because floor and ceil doesn't include decimals in calculation, we reuse the value of the half-up and adapt it.
+ if (utils.float_is_zero(rounding_applied, this.pos.currency.decimals)){
+ // https://xkcd.com/217/
+ return 0;
+ } else if(this.pos.cash_rounding[0].rounding_method === "UP" && rounding_applied < 0) {
+ rounding_applied += this.pos.cash_rounding[0].rounding;
+ }
+ else if(this.pos.cash_rounding[0].rounding_method === "DOWN" && rounding_applied > 0){
+ rounding_applied -= this.pos.cash_rounding[0].rounding;
+ }
+ return rounding_applied;
}
- else if(this.pos.cash_rounding[0].rounding_method === "DOWN" && rounding_applied > 0){
- rounding_applied -= this.pos.cash_rounding[0].rounding;
+ else {
+ return 0;
}
- return rounding_applied;
}
return 0;
},
diff --git a/addons/point_of_sale/views/pos_config_view.xml b/addons/point_of_sale/views/pos_config_view.xml
index 376ade5cc50..a6ed0395d91 100644
--- a/addons/point_of_sale/views/pos_config_view.xml
+++ b/addons/point_of_sale/views/pos_config_view.xml
@@ -386,6 +386,10 @@
<label string="Rounding Method" for="rounding_method" class="col-lg-3 o_light_label" />
<field name="rounding_method" attrs="{'required' : [('cash_rounding', '=', True)]}" domain="[('company_id', '=', company_id)]"/>
</div>
+ <div class="row mt16">
+ <label string="Only on cash methods" for="only_round_cash_method" class="col-lg-3 o_light_label" />
+ <field name="only_round_cash_method"/>
+ </div>
</div>
</div>
</div>