Advertisement
yavy-odoo

Untitled

Jun 12th, 2025
787
0
179 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     async downPaymentSO(sale_order, isPercentage) {
  2.         if (!this.config.down_payment_product_id && this.config.raw.down_payment_product_id) {
  3.             await this.data.read("product.product", [this.config.raw.down_payment_product_id]);
  4.         }
  5.         if (!this.config.down_payment_product_id) {
  6.             this.dialog.add(AlertDialog, {
  7.                 title: _t("No down payment product"),
  8.                 body: _t(
  9.                     "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."
  10.                 ),
  11.             });
  12.             return;
  13.         }
  14.         const payload = await makeAwaitable(this.dialog, NumberPopup, {
  15.             title: _t("Down Payment"),
  16.             subtitle: sprintf(
  17.                 _t("Due balance: %s | Total Amount: %s"),
  18.                 this.env.utils.formatCurrency(sale_order.amount_unpaid),
  19.                 this.env.utils.formatCurrency(sale_order.amount_total)
  20.             ),
  21.             buttons: enhancedButtons(),
  22.             formatDisplayedValue: (x) => (isPercentage ? `% ${x}` : x),
  23.             feedback: (buffer) =>
  24.                 isPercentage && buffer
  25.                     ? `(${this.env.utils.formatCurrency(
  26.                           (sale_order.amount_total * parseFloat(buffer)) / 100
  27.                       )})`
  28.                     : "",
  29.         });
  30.         if (!payload) {
  31.             return;
  32.         }
  33.         const userValue = parseFloat(payload);
  34.         let proposed_down_payment = userValue;
  35.         if (isPercentage) {
  36.             const down_payment_tax = this.models["account.tax"].get(
  37.                 this.config.down_payment_product_id.taxes_id
  38.             );
  39.             const percentageBase =
  40.                 !down_payment_tax || down_payment_tax.price_include
  41.                     ? sale_order.amount_total
  42.                     : sale_order.amount_total;
  43.             proposed_down_payment = (percentageBase * userValue) / 100;
  44.         }
  45.         if (proposed_down_payment > sale_order.amount_unpaid) {
  46.             this.dialog.add(AlertDialog, {
  47.                 title: _t("Error amount too high"),
  48.                 body: _t(
  49.                     "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.",
  50.                     this.env.utils.formatCurrency(proposed_down_payment),
  51.                     this.env.utils.formatCurrency(sale_order.amount_unpaid),
  52.                     this.env.utils.formatCurrency(sale_order.amount_unpaid || 0)
  53.                 ),
  54.             });
  55.             proposed_down_payment = sale_order.amount_unpaid || 0;
  56.         }
  57.         this._createDownpaymentLines(sale_order, proposed_down_payment);
  58.     },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement