From eace0d76256623352fa2d1c8ec8a723b9a124b12 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Mon, 23 Feb 2026 10:30:47 +0700 Subject: [PATCH] feat: Prevent non-income account overrides and strip taxes from POS down payments applied from sale orders. --- README.md | 2 ++ __manifest__.py | 5 ++++ models/pos_session.py | 22 ++++++++------- .../src/app/sale_order_management_screen.js | 27 +++++++++++++++++++ 4 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 static/src/app/sale_order_management_screen.js diff --git a/README.md b/README.md index dd1250b..d77af60 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ For example, if a session has sales paid with both cash and credit card, instead - Works with all payment methods (cash, bank transfers, credit cards, etc.) - Preserves tax calculations and reporting - Allows linking specific income accounts to payment methods +- Prevents down payments from incorrectly overriding non-income accounts (e.g. liabilities) +- Strips taxes natively when applying down payments directly from a Sales Order in POS ## Configuration diff --git a/__manifest__.py b/__manifest__.py index b316548..6a14d96 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -30,6 +30,11 @@ 'demo': [ # 'demo/demo.xml', ], + 'assets': { + 'point_of_sale._assets_pos': [ + 'split_pendapatan_payment/static/src/app/**/*', + ], + }, 'installable': True, 'application': False, 'auto_install': False, diff --git a/models/pos_session.py b/models/pos_session.py index 87fdca3..617709b 100644 --- a/models/pos_session.py +++ b/models/pos_session.py @@ -191,15 +191,19 @@ class PosSession(models.Model): return target_account_id = sale_key[0] - if is_discount_part: - if payment.payment_method_id.discount_account_id: - target_account_id = payment.payment_method_id.discount_account_id.id - elif payment.payment_method_id.income_account_id: - target_account_id = payment.payment_method_id.income_account_id.id - else: - if payment.payment_method_id.income_account_id: - target_account_id = payment.payment_method_id.income_account_id.id - + original_account = self.env['account.account'].browse(target_account_id) + is_income_account = original_account.account_type in ('income', 'income_other') + + if is_income_account: + if is_discount_part: + if payment.payment_method_id.discount_account_id: + target_account_id = payment.payment_method_id.discount_account_id.id + elif payment.payment_method_id.income_account_id: + target_account_id = payment.payment_method_id.income_account_id.id + else: + if payment.payment_method_id.income_account_id: + target_account_id = payment.payment_method_id.income_account_id.id + if not target_account_id: raise UserError(_( 'No income account found for payment method "%s".\n' diff --git a/static/src/app/sale_order_management_screen.js b/static/src/app/sale_order_management_screen.js new file mode 100644 index 0000000..4d7b060 --- /dev/null +++ b/static/src/app/sale_order_management_screen.js @@ -0,0 +1,27 @@ +/** @odoo-module */ + +import { SaleOrderManagementScreen } from "@pos_sale/app/order_management_screen/sale_order_management_screen/sale_order_management_screen"; +import { patch } from "@web/core/utils/patch"; + +patch(SaleOrderManagementScreen.prototype, { + _createDownpaymentLines(sale_order, total_down_payment, clickedOrder, down_payment_product) { + const order = this.pos.get_order(); + const linesBefore = order.get_orderlines().length; + + // Call the original method to create the lines + super._createDownpaymentLines(sale_order, total_down_payment, clickedOrder, down_payment_product); + + const linesAfter = order.get_orderlines().length; + const orderlines = order.get_orderlines(); + + // Find the down payment lines that were just added and remove their taxes + for (let i = linesBefore; i < linesAfter; i++) { + let line = orderlines[i]; + if (line.get_product().id === down_payment_product.id) { + const priceWithTax = line.get_price_with_tax(); + line.tax_ids = []; + line.set_unit_price(priceWithTax); + } + } + } +});