Commit e0176a59 by Damien Moulard

create module for mona & set eligible amount to payment line at mona payment & security checks

parent 9153baf5
# -*- coding: utf-8 -*-
{
"name": "La Cagette - MonA",
"summary": "Handle the relation with MonA (Caisse Alimentaire Commune / Common Food Fund). "
"This module changes information handled by the Pos Meal Voucher module (eg meal voucher eligible amount).",
"version": "1.0.0",
"category": "Point of Sale",
"author": "Damien Moulard",
"website": "https://lacagette-coop.fr",
"depends": [
"base",
"point_of_sale",
"pos_meal_voucher"
],
"data": [
"views/templates.xml",
"views/view_pos_config.xml",
"views/view_account_journal.xml",
#"data/barcode_rule.xml",
#"data/ir_config_parameter_data.xml",
#"views/view_product_category.xml",
#"views/view_product_template.xml",
],
"qweb": [
"static/src/xml/lacagette_mona.xml",
],
"installable": True,
}
from . import pos_config
from . import account_journal
from openerp import fields, models
class AccountJournal(models.Model):
_inherit = 'account.journal'
mona_used = fields.Boolean(
string="Paiement en MonA",
default=False
)
from openerp import fields, models
class PosConfig(models.Model):
_inherit = 'pos.config'
enable_mona = fields.Boolean(
string="Activer le paiement MonA",
default=False)
.payment-screen div.monA-summary{
border-top: dashed 1px gainsboro;
}
.payment-screen div.monA-summary table{
width: 100%;
}
.payment-screen div.monA-summary tbody{
background: white;
}
.payment-screen div.monA-summary th{
font-size: 16px;
padding: 8px;
text-align: center;
}
.payment-screen div.monA-summary td{
font-size: 22px;
padding: 8px 12px;
}
\ No newline at end of file
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({
get_total_mona_received: function(){
return round_pr(this.paymentlines.reduce((function(sum, paymentLine) {
if (paymentLine.is_mona()) {
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;
});
odoo.define("lacagette_mona.screens", function (require) {
"use strict";
var screens = require("point_of_sale.screens");
var core = require('web.core');
var formats = require('web.formats');
var _t = core._t;
var QWeb = core.qweb;
var Model = require('web.DataModel');
var config_parameter = new Model('ir.config_parameter');
screens.PaymentScreenWidget.include({
click_paymentmethods: function(id) {
var self = this;
var methods = this._super.apply(this, arguments);
var paymentScreen = this.pos.gui.current_screen;
var order = this.pos.get_order();
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();
order.selected_paymentline.set_amount(total_mona_eligible);
paymentScreen.order_changes();
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", {
'title': _t("Impossible de rajouter un paiement MonA"),
'body': _t("Le montant éligible a déjà été payé."),
cancel: function() {
self.remove_selected_paymentline(order);
}
});
}
} else if (order.selected_paymentline.is_meal_voucher() && order.get_total_meal_vouchers_eligible_including_mona() == 0) {
this.gui.show_popup("alert", {
'title': _t("Impossible de payer en titre restaurant"),
'body': _t("Le montant éligible a déjà été payé en MonA."),
cancel: function() {
self.remove_selected_paymentline(order);
}
});
}
},
render_paymentlines: function() {
var self = this;
this._super.apply(this, arguments);
var order = this.pos.get_order();
if (!order) {
return;
}
// Update MonA summary
if (this.pos.config.enable_mona) {
let total_mona_received = order.get_total_mona_received();
let total_mona_eligible = order.get_total_mona_eligible_including_meal_vouchers();
let total_meal_vouchers_eligible = order.get_total_meal_vouchers_eligible_including_mona();
this.el.querySelector("#monA-eligible-amount").textContent = this.format_currency(total_mona_eligible);
this.el.querySelector("#meal-voucher-eligible-amount").textContent = this.format_currency(total_meal_vouchers_eligible);
this.el.querySelector("#monA-received-amount").textContent = this.format_currency(total_mona_received);
}
},
});
});
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="PaymentScreen-Paymentmethods">
<t t-jquery="div.paymentmethods" t-operation="after">
<div t-if="widget.pos.config.enable_mona" class="monA-summary">
<table class="monA-summary">
<thead>
<tr>
<th colspan="2">MonA</th>
</tr>
</thead>
<tbody>
<tr>
<td>Total Eligible</td>
<td>
<span id="monA-eligible-amount">0.00 €</span>
</td>
</tr>
<tr>
<td>Total Received</td>
<td>
<span id="monA-received-amount">0.00 €</span>
</td>
</tr>
</tbody>
</table>
</div>
</t>
</t>
</templates>
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/lacagette_mona/static/src/css/lacagette_mona.css"/>
<script type="text/javascript" src="/lacagette_mona/static/src/js/models.js"></script>
<script type="text/javascript" src="/lacagette_mona/static/src/js/screens.js"></script>
</xpath>
</template>
</openerp>
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<record id="view_account_journal" model="ir.ui.view">
<field name="model">account.journal</field>
<field name="inherit_id" ref="point_of_sale.view_account_journal_pos_user_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='amount_authorized_diff']/.." position="after">
<group name="mona_section" string="Caisse Alimentaire Commune">
<field name="mona_used"/>
</group>
</xpath>
</field>
</record>
</openerp>
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<record id="view_pos_config_form" model="ir.ui.view">
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.view_pos_config_form"/>
<field name="arch" type="xml">
<field name="journal_ids" position="after">
<group string="Caisse Alimentaire Commune">
<field name="enable_mona"/>
</group>
</field>
</field>
</record>
</openerp>
# Copyright (C) 2020 - Today: GRAP (http://www.grap.coop) # Copyright (C) 2020 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# TODO: Rendre l'affichage MonA paramétrable
{ {
"name": "Point Of Sale - Meal Voucher", "name": "Point Of Sale - Meal Voucher",
"summary": "Handle meal vouchers in Point of Sale" "summary": "Handle meal vouchers in Point of Sale"
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
background: rgba(255,255,255,0.4); background: rgba(255,255,255,0.4);
} }
.payment-screen div.meal-voucher-summary, .payment-screen div.monA-summary{ .payment-screen div.meal-voucher-summary {
border-top: dashed 1px gainsboro; border-top: dashed 1px gainsboro;
} }
...@@ -45,20 +45,20 @@ ...@@ -45,20 +45,20 @@
color: red; color: red;
} }
.payment-screen div.meal-voucher-summary table, .payment-screen div.monA-summary table{ .payment-screen div.meal-voucher-summary table{
width: 100%; width: 100%;
} }
.payment-screen div.meal-voucher-summary tbody, .payment-screen div.monA-summary tbody{ .payment-screen div.meal-voucher-summary tbody{
background: white; background: white;
} }
.payment-screen div.meal-voucher-summary th , .payment-screen div.monA-summary th{ .payment-screen div.meal-voucher-summary th {
font-size: 16px; font-size: 16px;
padding: 8px; padding: 8px;
text-align: center; text-align: center;
} }
.payment-screen div.meal-voucher-summary td, .payment-screen div.monA-summary td{ .payment-screen div.meal-voucher-summary td {
font-size: 22px; font-size: 22px;
padding: 8px 12px; padding: 8px 12px;
} }
......
...@@ -423,10 +423,6 @@ odoo.define("pos_meal_voucher.screens", function (require) { ...@@ -423,10 +423,6 @@ odoo.define("pos_meal_voucher.screens", function (require) {
if (!this.meal_voucher_activated()) { if (!this.meal_voucher_activated()) {
this.$(".meal-voucher-summary").addClass("oe_hidden"); this.$(".meal-voucher-summary").addClass("oe_hidden");
} }
// Update MonA summary
this.el.querySelector("#monA-eligible-amount").textContent = this.format_currency(total_eligible)
}, },
order_is_valid: function(force_validation) { order_is_valid: function(force_validation) {
......
...@@ -56,23 +56,6 @@ ...@@ -56,23 +56,6 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="monA-summary">
<table class="monA-summary">
<thead>
<tr>
<th colspan="2">MonA</th>
</tr>
</thead>
<tbody>
<tr>
<td>Total Eligible</td>
<td>
<span id="monA-eligible-amount">0.00 €</span>
</td>
</tr>
</tbody>
</table>
</div>
</t> </t>
</t> </t>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment