Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async downPaymentSO(sale_order, isPercentage) {
- if (!this.config.down_payment_product_id && this.config.raw.down_payment_product_id) {
- await this.data.read("product.product", [this.config.raw.down_payment_product_id]);
- }
- if (!this.config.down_payment_product_id) {
- this.dialog.add(AlertDialog, {
- title: _t("No down payment product"),
- body: _t(
- "It seems that you didn't configure a down payment product in your point of sale. You can go to your point of sale configuration to choose one."
- ),
- });
- return;
- }
- const payload = await makeAwaitable(this.dialog, NumberPopup, {
- title: _t("Down Payment"),
- subtitle: sprintf(
- _t("Due balance: %s | Total Amount: %s"),
- this.env.utils.formatCurrency(sale_order.amount_unpaid),
- this.env.utils.formatCurrency(sale_order.amount_total)
- ),
- buttons: enhancedButtons(),
- formatDisplayedValue: (x) => (isPercentage ? `% ${x}` : x),
- feedback: (buffer) =>
- isPercentage && buffer
- ? `(${this.env.utils.formatCurrency(
- (sale_order.amount_total * parseFloat(buffer)) / 100
- )})`
- : "",
- });
- if (!payload) {
- return;
- }
- const userValue = parseFloat(payload);
- let proposed_down_payment = userValue;
- if (isPercentage) {
- const down_payment_tax = this.models["account.tax"].get(
- this.config.down_payment_product_id.taxes_id
- );
- const percentageBase =
- !down_payment_tax || down_payment_tax.price_include
- ? sale_order.amount_total
- : sale_order.amount_total;
- proposed_down_payment = (percentageBase * userValue) / 100;
- }
- if (proposed_down_payment > sale_order.amount_unpaid) {
- this.dialog.add(AlertDialog, {
- title: _t("Error amount too high"),
- body: _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.utils.formatCurrency(proposed_down_payment),
- this.env.utils.formatCurrency(sale_order.amount_unpaid),
- this.env.utils.formatCurrency(sale_order.amount_unpaid || 0)
- ),
- });
- proposed_down_payment = sale_order.amount_unpaid || 0;
- }
- this._createDownpaymentLines(sale_order, proposed_down_payment);
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement