models.js 2.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
odoo.define("lacagette_mona.models", function (require) {
    "use strict";

    var models = require("point_of_sale.models");
    var utils = require("web.utils");
   
    var round_pr = utils.round_precision;

    models.load_fields("account.journal", ["mona_used"]);

    var OrderSuper = models.Order.prototype;
    var Order = models.Order.extend({
13
        get_total_mona_received: function(ignore_selected_line=false){
14
            return round_pr(this.paymentlines.reduce((function(sum, paymentLine) {
15
                if (paymentLine.is_mona() && (!ignore_selected_line || ignore_selected_line && !paymentLine.selected)) {
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
                    return sum + paymentLine.get_amount();
                } else {
                    return sum;
                }
            }), 0), this.pos.currency.rounding);
        },
        get_total_mona_eligible_including_meal_vouchers: function() {
            let total_meal_voucher_received = this.get_total_meal_voucher_received();
            let mona_eligible = this.get_total_meal_voucher_eligible();  // eligible amount is the same as meal vouchers

            // Since the same products are eligible for mona & meal vouchers, deduce one's eligible amount with the other's received amount
            return round_pr(mona_eligible - total_meal_voucher_received, this.pos.currency.rounding);
        },
        get_total_meal_vouchers_eligible_including_mona: function() {
            let total_mona_received = this.get_total_mona_received();
            let meal_voucher_eligible = this.get_total_meal_voucher_eligible();
            let meal_voucher_max_amount = this.pos.config.max_meal_voucher_amount;

            return round_pr(Math.min(meal_voucher_eligible - total_mona_received, meal_voucher_max_amount), this.pos.currency.rounding);
        },
    });

    models.Order = Order;

    var PaymentlineSuper = models.Paymentline.prototype;
    var Paymentline = models.Paymentline.extend({
        is_mona: function() {
            return this.cashregister.journal.mona_used;
        },
    });

    models.Paymentline = Paymentline;
});