-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from coopiteasy/12.0-mig-pos-round-cash-paymen…
…t-line 12.0 mig pos round cash payment line
- Loading branch information
Showing
9 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2020 Coop IT Easy SCRLfs | ||
# - Robin Keunen <[email protected]> | ||
# - Houssine bakkali <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Pos Round Cash Payment", | ||
"version": "12.0.1.0.0", | ||
"author": "Coop IT Easy SCRLfs", | ||
"license": "AGPL-3", | ||
"category": "Point of Sale", | ||
"website": "www.coopiteasy.be", | ||
"description": """ | ||
Rounds due amount to nearest 5 cents when adding a cash Payment line. | ||
An line is added on the invoice to record the rounding remainder. | ||
A Round Remainder journal must be created and assigned to the POS. | ||
""", | ||
"depends": [ | ||
'point_of_sale', | ||
], | ||
'data': [ | ||
'views/pos_config.xml', | ||
'views/account_journal_view.xml', | ||
'static/src/xml/templates.xml', | ||
], | ||
'qweb': [ | ||
'static/src/xml/pos_round_cash_payment.xml' | ||
], | ||
'installable': True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import pos_config | ||
from . import account_journal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2016 Robin Keunen, Coop IT Easy SCRL fs | ||
# Copyright 2020 Houssine Bakkali, Coop IT Easy SCRL fs | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import models, fields | ||
|
||
|
||
class AccountJournal(models.Model): | ||
_inherit = 'account.journal' | ||
|
||
cash_rounding = fields.Boolean( | ||
string='Cash Rounding Journal', | ||
default=False, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2016 Robin Keunen, Coop IT Easy SCRL fs | ||
# Copyright 2020 Houssine Bakkali, Coop IT Easy SCRL fs | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import models, fields | ||
|
||
|
||
class pos_config(models.Model): | ||
_inherit = 'pos.config' | ||
|
||
cash_rounding_activated = fields.Boolean( | ||
string='Activate Cash Rounding', | ||
default=False, | ||
) |
77 changes: 77 additions & 0 deletions
77
pos_round_cash_payment/static/src/js/pos_round_cash_payment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
POS Round cash Payment for odoo | ||
Copyright (C) 2018 Coop IT Easy SCRLfs | ||
@author: Robin Keunen | ||
@author: Houssine BAKKALI | ||
The licence is in the file __manifest__.py | ||
*/ | ||
|
||
odoo.define( | ||
'pos_round_cash_payment.pos_round_cash_payment_line', | ||
function (require) { | ||
|
||
"use strict"; | ||
var models = require('point_of_sale.models'); | ||
var screens = require('point_of_sale.screens'); | ||
var round_pr = require('web.utils').round_precision; | ||
|
||
var order_prototype = models.Order.prototype; | ||
|
||
models.load_fields('account.journal', 'cash_rounding'); | ||
|
||
models.Order = models.Order.extend({ | ||
|
||
round_5c: function(x) { | ||
return round_pr(x * 20) / 20; | ||
}, | ||
|
||
round_5c_remainder: function(x) { | ||
return x - this.round_5c(x); | ||
}, | ||
|
||
add_remainder_line: function(cashregister) { | ||
this.assert_editable(); | ||
const due = this.get_due(newPaymentline); | ||
const remainder = this.round_5c_remainder(due) | ||
if (remainder !== 0) { | ||
var newPaymentline = new models.Paymentline({}, | ||
{ | ||
order: this, | ||
cashregister:cashregister, pos: this.pos | ||
} | ||
); | ||
|
||
newPaymentline.set_amount(remainder); | ||
this.paymentlines.add(newPaymentline); | ||
this.select_paymentline(newPaymentline); | ||
} | ||
}, | ||
}); | ||
|
||
screens.PaymentScreenWidget.include({ | ||
click_paymentmethods: function(id) { | ||
var cashregister = null; | ||
|
||
for ( var i = 0; i < this.pos.cashregisters.length; i++ ) { | ||
if ( this.pos.cashregisters[i].journal_id[0] === id ){ | ||
cashregister = this.pos.cashregisters[i]; | ||
break; | ||
} | ||
} | ||
|
||
if (cashregister.journal.cash_rounding == false) { | ||
if (this.pos.config.cash_rounding_activated && cashregister.journal.type == 'cash') { | ||
var rounding_cashregister = null; | ||
for ( var i = 0; i < this.pos.cashregisters.length; i++ ) { | ||
if ( this.pos.cashregisters[i].journal.cash_rounding === true ){ | ||
rounding_cashregister = this.pos.cashregisters[i]; | ||
break; | ||
} | ||
} | ||
this.pos.get_order().add_remainder_line(rounding_cashregister); | ||
} | ||
this._super.apply(this, arguments); | ||
} | ||
}, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<template id="assets" name="round_cash_payment_extension_assets" inherit_id="point_of_sale.assets"> | ||
<xpath expr="." position="inside"> | ||
<script type="text/javascript" src="/pos_round_cash_payment/static/src/js/pos_round_cash_payment.js"></script> | ||
</xpath> | ||
</template> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<odoo> | ||
<data> | ||
<record model="ir.ui.view" id="view_account_journal_pos_user_form"> | ||
<field name="name">POS Journal</field> | ||
<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"> | ||
<field name="amount_authorized_diff" position="after"> | ||
<field name="cash_rounding"/> | ||
</field> | ||
</field> | ||
</record> | ||
</data> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0"?> | ||
<odoo> | ||
<record id="view_pos_config_form" model="ir.ui.view"> | ||
<field name="name">pos.config.form.view.inherit</field> | ||
<field name="model">pos.config</field> | ||
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='iface_precompute_cash']/../.." position="after"> | ||
<div class="col-12 col-lg-6 o_setting_box"> | ||
<div class="o_setting_left_pane"> | ||
<field name="cash_rounding_activated"/> | ||
</div> | ||
<div class="o_setting_right_pane"> | ||
<label for="cash_rounding_activated"/> | ||
<div class="text-muted"> | ||
Cash rounding | ||
</div> | ||
</div> | ||
</div> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |