[FIX] pos_sale: add down payment limit

Before:
When taking a SO from the Sales app in the POS, there is no "Down payment limit".
There is either no way to check what has still to be paid. So the POS user can
charge a customer several times for the same down payment because he cannot see
if it has already been paid.

After:
When you click on the Quotation/Order list the amount left to pay is displayed.
When a down payment is chosen and a percentage is entered that is too high and
represents more than the remaining amount to be paid, a warning appears and warns
that the orderline will be adjusted to the remaining price.

closes odoo/odoo#116182

X-original-commit: 185324cc1abf1448d3db976c8e5751196baad3ee
Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
This commit is contained in:
Jacky (trj)
2023-03-24 11:08:19 +01:00
committed by David Monnom (moda)
parent b245b8cb6f
commit 85e9c84dab
5 changed files with 36 additions and 17 deletions
+9
View File
@@ -560,3 +560,12 @@ msgstr ""
#, python-format
msgid "Yes"
msgstr ""
#. module: pos_sale
#. openerp-web
#: code:addons/pos_sale/static/src/js/OrderManagementScreen/SaleOrderManagementScreen.js:0
#, python-format
msgid ""
"You have tried to charge a down payment of %s but only %s remains to be "
"paid, %s will be applied to the purchase order line."
msgstr ""
-1
View File
@@ -34,7 +34,6 @@ class SaleOrder(models.Model):
total_pos_paid = sum(sale_order.order_line.filtered(lambda l: not l.display_type).mapped('pos_order_line_ids.price_subtotal_incl'))
sale_order.amount_unpaid = sale_order.amount_total - (total_invoice_paid + total_pos_paid)
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
@@ -61,12 +61,12 @@ class SaleOrderFetcher extends EventBus {
return sale_orders;
}
async _getOrderIdsForCurrentPage(limit, offset) {
const domain = [["currency_id", "=", this.pos.globalState.currency.id]];
if (this.searchDomain) {
domain.push(...this.searchDomain);
}
const domain = [["currency_id", "=", this.pos.globalState.currency.id]].concat(
this.searchDomain || []
);
this.pos.globalState.set_synch("connecting");
const res = await this.orm.searchRead(
const saleOrders = await this.orm.searchRead(
"sale.order",
domain,
[
@@ -80,8 +80,9 @@ class SaleOrderFetcher extends EventBus {
],
{ offset, limit }
);
this.pos.globalState.set_synch("connected");
return res;
return saleOrders;
}
nextPage() {
@@ -259,6 +259,24 @@ export class SaleOrderManagementScreen extends ControlButtonsMixin(IndependentTo
down_payment = (down_payment * parse.float(payload)) / 100;
}
if (down_payment > sale_order.amount_unpaid) {
const errorBody = sprintf(
this.env._t(
"You have tried to charge a down payment of %s but only %s remains to be paid, %s will be applied to the purchase order line."
),
this.env.pos.format_currency(down_payment),
this.env.pos.format_currency(sale_order.amount_unpaid),
sale_order.amount_unpaid > 0
? this.env.pos.format_currency(sale_order.amount_unpaid)
: this.env.pos.format_currency(0)
);
await this.popup.add(ErrorPopup, {
title: "Error amount too high",
body: errorBody,
});
down_payment = sale_order.amount_unpaid > 0 ? sale_order.amount_unpaid : 0;
}
const new_line = new Orderline(
{},
{
@@ -298,6 +316,7 @@ export class SaleOrderManagementScreen extends ControlButtonsMixin(IndependentTo
"fiscal_position_id",
"amount_total",
"amount_untaxed",
"amount_unpaid",
"picking_ids",
]
);
@@ -1,7 +1,5 @@
/** @odoo-module */
import { Component } from "@odoo/owl";
import utils from "web.utils";
/**
* @props {models.Order} order
@@ -42,14 +40,7 @@ export class SaleOrderRow extends Component {
* @returns {boolean}
*/
get showAmountUnpaid() {
const isFullAmountUnpaid = utils.float_is_zero(
Math.abs(this.order.amount_total - this.order.amount_unpaid),
this.env.pos.currency.decimal_places
);
return (
!isFullAmountUnpaid &&
!utils.float_is_zero(this.order.amount_unpaid, this.env.pos.currency.decimal_places)
);
return this.order.amount_total != this.order.amount_unpaid;
}
get amountUnpaidRepr() {
return this.env.pos.format_currency(this.order.amount_unpaid);