From ad05e6dec24a9cb67cb649aa7e91ca1a03575f4d Mon Sep 17 00:00:00 2001 From: David Date: Wed, 28 Aug 2024 10:28:02 +0200 Subject: [PATCH] fix: distributed discounts on si (cherry picked from commit 0bab6f34c13095d67ffb9e485aebb161980d6da7) # Conflicts: # erpnext/buying/doctype/purchase_order_item/purchase_order_item.json # erpnext/buying/doctype/supplier_quotation_item/supplier_quotation_item.json # erpnext/selling/doctype/quotation_item/quotation_item.json # erpnext/selling/doctype/sales_order_item/sales_order_item.json # erpnext/stock/doctype/delivery_note_item/delivery_note_item.json --- .../pos_invoice_item/pos_invoice_item.json | 7 +++++ .../pos_invoice_item/pos_invoice_item.py | 1 + .../purchase_invoice_item.json | 9 ++++++- .../purchase_invoice_item.py | 1 + .../sales_invoice_item.json | 11 ++++++-- .../sales_invoice_item/sales_invoice_item.py | 1 + .../purchase_order_item.json | 27 ++++++++++++++++++- .../purchase_order_item.py | 1 + .../supplier_quotation_item.json | 11 ++++++++ .../supplier_quotation_item.py | 1 + erpnext/controllers/accounts_controller.py | 7 +++-- erpnext/controllers/taxes_and_totals.py | 7 +++++ .../quotation_item/quotation_item.json | 13 ++++++++- .../doctype/quotation_item/quotation_item.py | 1 + .../sales_order_item/sales_order_item.json | 13 ++++++++- .../sales_order_item/sales_order_item.py | 1 + .../delivery_note_item.json | 13 ++++++++- .../delivery_note_item/delivery_note_item.py | 1 + .../purchase_receipt_item.json | 9 ++++++- .../purchase_receipt_item.py | 1 + 20 files changed, 126 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/doctype/pos_invoice_item/pos_invoice_item.json b/erpnext/accounts/doctype/pos_invoice_item/pos_invoice_item.json index 828fc30db6e..799a112c0c1 100644 --- a/erpnext/accounts/doctype/pos_invoice_item/pos_invoice_item.json +++ b/erpnext/accounts/doctype/pos_invoice_item/pos_invoice_item.json @@ -37,6 +37,7 @@ "column_break_19", "discount_percentage", "discount_amount", + "distributed_discount_amount", "base_rate_with_margin", "section_break1", "rate", @@ -847,6 +848,12 @@ { "fieldname": "column_break_ciit", "fieldtype": "Column Break" + }, + { + "fieldname": "distributed_discount_amount", + "fieldtype": "Currency", + "label": "Distributed Discount Amount", + "options": "currency" } ], "istable": 1, diff --git a/erpnext/accounts/doctype/pos_invoice_item/pos_invoice_item.py b/erpnext/accounts/doctype/pos_invoice_item/pos_invoice_item.py index c24db1d6a03..429f340a4f5 100644 --- a/erpnext/accounts/doctype/pos_invoice_item/pos_invoice_item.py +++ b/erpnext/accounts/doctype/pos_invoice_item/pos_invoice_item.py @@ -39,6 +39,7 @@ class POSInvoiceItem(Document): description: DF.TextEditor discount_amount: DF.Currency discount_percentage: DF.Percent + distributed_discount_amount: DF.Currency dn_detail: DF.Data | None enable_deferred_revenue: DF.Check expense_account: DF.Link | None diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json index 8a2ba36cf62..12ed168875b 100644 --- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json +++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json @@ -38,6 +38,7 @@ "column_break_30", "discount_percentage", "discount_amount", + "distributed_discount_amount", "base_rate_with_margin", "sec_break2", "rate", @@ -838,7 +839,7 @@ }, { "collapsible": 1, - "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount", + "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount || doc.distributed_discount_amount", "fieldname": "section_break_26", "fieldtype": "Section Break", "label": "Discount and Margin" @@ -969,6 +970,12 @@ "no_copy": 1, "options": "Company:company:default_currency", "print_hide": 1 + }, + { + "fieldname": "distributed_discount_amount", + "fieldtype": "Currency", + "label": "Distributed Discount Amount", + "options": "currency" } ], "idx": 1, diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.py b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.py index a8f844c6c1c..96db9d66f05 100644 --- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.py +++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.py @@ -34,6 +34,7 @@ class PurchaseInvoiceItem(Document): description: DF.TextEditor | None discount_amount: DF.Currency discount_percentage: DF.Percent + distributed_discount_amount: DF.Currency enable_deferred_expense: DF.Check expense_account: DF.Link | None from_warehouse: DF.Link | None diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json index 932bc8e49d4..7d1e4abdbc5 100644 --- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json +++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json @@ -37,6 +37,7 @@ "column_break_19", "discount_percentage", "discount_amount", + "distributed_discount_amount", "base_rate_with_margin", "section_break1", "rate", @@ -253,7 +254,7 @@ }, { "collapsible": 1, - "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount", + "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount || doc.distributed_discount_amount", "fieldname": "discount_and_margin", "fieldtype": "Section Break", "label": "Discount and Margin" @@ -922,12 +923,18 @@ { "fieldname": "column_break_ytgd", "fieldtype": "Column Break" + }, + { + "fieldname": "distributed_discount_amount", + "fieldtype": "Currency", + "label": "Distributed Discount Amount", + "options": "currency" } ], "idx": 1, "istable": 1, "links": [], - "modified": "2024-05-23 16:36:18.970862", + "modified": "2024-06-02 06:14:40.009020", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice Item", diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.py b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.py index 9be1b42aab3..28d468ac736 100644 --- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.py +++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.py @@ -39,6 +39,7 @@ class SalesInvoiceItem(Document): discount_account: DF.Link | None discount_amount: DF.Currency discount_percentage: DF.Percent + distributed_discount_amount: DF.Currency dn_detail: DF.Data | None enable_deferred_revenue: DF.Check expense_account: DF.Link | None diff --git a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json index e3e8def7ffd..cb649563fbe 100644 --- a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json +++ b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json @@ -42,6 +42,7 @@ "column_break_28", "discount_percentage", "discount_amount", + "distributed_discount_amount", "base_rate_with_margin", "sec_break2", "rate", @@ -780,7 +781,7 @@ }, { "collapsible": 1, - "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount", + "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount || doc.distributed_discount_amount", "fieldname": "discount_and_margin_section", "fieldtype": "Section Break", "label": "Discount and Margin" @@ -909,13 +910,37 @@ { "fieldname": "column_break_fyqr", "fieldtype": "Column Break" +<<<<<<< HEAD +======= + }, + { + "fieldname": "column_break_pjyo", + "fieldtype": "Column Break" + }, + { + "fieldname": "job_card", + "fieldtype": "Link", + "label": "Job Card", + "options": "Job Card", + "search_index": 1 + }, + { + "fieldname": "distributed_discount_amount", + "fieldtype": "Currency", + "label": "Distributed Discount Amount", + "options": "currency" +>>>>>>> 0bab6f34c1 (fix: distributed discounts on si) } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], +<<<<<<< HEAD "modified": "2024-02-05 11:23:24.859435", +======= + "modified": "2024-06-02 06:20:10.508290", +>>>>>>> 0bab6f34c1 (fix: distributed discounts on si) "modified_by": "Administrator", "module": "Buying", "name": "Purchase Order Item", diff --git a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.py b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.py index e9cc2b4eecf..79c66c3a30e 100644 --- a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.py +++ b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.py @@ -37,6 +37,7 @@ class PurchaseOrderItem(Document): description: DF.TextEditor | None discount_amount: DF.Currency discount_percentage: DF.Percent + distributed_discount_amount: DF.Currency expected_delivery_date: DF.Date | None expense_account: DF.Link | None fg_item: DF.Link | None diff --git a/erpnext/buying/doctype/supplier_quotation_item/supplier_quotation_item.json b/erpnext/buying/doctype/supplier_quotation_item/supplier_quotation_item.json index a6229b5950b..71e8da47340 100644 --- a/erpnext/buying/doctype/supplier_quotation_item/supplier_quotation_item.json +++ b/erpnext/buying/doctype/supplier_quotation_item/supplier_quotation_item.json @@ -32,6 +32,7 @@ "price_list_rate", "discount_percentage", "discount_amount", + "distributed_discount_amount", "col_break_price_list", "base_price_list_rate", "sec_break1", @@ -565,13 +566,23 @@ { "fieldname": "dimension_col_break", "fieldtype": "Column Break" + }, + { + "fieldname": "distributed_discount_amount", + "fieldtype": "Currency", + "label": "Distributed Discount Amount", + "options": "currency" } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], +<<<<<<< HEAD "modified": "2023-11-17 12:25:26.235367", +======= + "modified": "2024-06-02 06:22:17.864822", +>>>>>>> 0bab6f34c1 (fix: distributed discounts on si) "modified_by": "Administrator", "module": "Buying", "name": "Supplier Quotation Item", diff --git a/erpnext/buying/doctype/supplier_quotation_item/supplier_quotation_item.py b/erpnext/buying/doctype/supplier_quotation_item/supplier_quotation_item.py index d2f4a59930b..a51b9500fd8 100644 --- a/erpnext/buying/doctype/supplier_quotation_item/supplier_quotation_item.py +++ b/erpnext/buying/doctype/supplier_quotation_item/supplier_quotation_item.py @@ -26,6 +26,7 @@ class SupplierQuotationItem(Document): description: DF.TextEditor | None discount_amount: DF.Currency discount_percentage: DF.Percent + distributed_discount_amount: DF.Currency expected_delivery_date: DF.Date | None image: DF.Attach | None is_free_item: DF.Check diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index ce5d813b801..32f11804206 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1649,8 +1649,11 @@ class AccountsController(TransactionBase): and self.get("discount_amount") and self.get("additional_discount_account") ): - amount = item.amount - base_amount = item.base_amount + amount += item.distributed_discount_amount + base_amount += flt( + item.distributed_discount_amount * self.get("conversion_rate"), + item.precision("distributed_discount_amount"), + ) return amount, base_amount diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 2d3b224b76f..ebf10977b52 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -674,6 +674,9 @@ class calculate_taxes_and_totals: ) item.net_amount = flt(item.net_amount - distributed_amount, item.precision("net_amount")) + item.distributed_discount_amount = flt( + distributed_amount, item.precision("distributed_discount_amount") + ) net_total += item.net_amount # discount amount rounding loss adjustment if no taxes @@ -690,6 +693,10 @@ class calculate_taxes_and_totals: item.net_amount = flt( item.net_amount + discount_amount_loss, item.precision("net_amount") ) + item.distributed_discount_amount = flt( + distributed_amount + discount_amount_loss, + item.precision("distributed_discount_amount"), + ) item.net_rate = ( flt(item.net_amount / item.qty, item.precision("net_rate")) if item.qty else 0 diff --git a/erpnext/selling/doctype/quotation_item/quotation_item.json b/erpnext/selling/doctype/quotation_item/quotation_item.json index 0e25313f76a..13eda8b4c88 100644 --- a/erpnext/selling/doctype/quotation_item/quotation_item.json +++ b/erpnext/selling/doctype/quotation_item/quotation_item.json @@ -34,6 +34,7 @@ "column_break_18", "discount_percentage", "discount_amount", + "distributed_discount_amount", "base_rate_with_margin", "section_break1", "rate", @@ -235,7 +236,7 @@ }, { "collapsible": 1, - "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount", + "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount || doc.distributed_discount_amount", "fieldname": "discount_and_margin", "fieldtype": "Section Break", "label": "Discount and Margin" @@ -662,12 +663,22 @@ "label": "Has Alternative Item", "print_hide": 1, "read_only": 1 + }, + { + "fieldname": "distributed_discount_amount", + "fieldtype": "Currency", + "label": "Distributed Discount Amount", + "options": "currency" } ], "idx": 1, "istable": 1, "links": [], +<<<<<<< HEAD "modified": "2023-11-14 18:24:24.619832", +======= + "modified": "2024-06-02 06:21:09.508680", +>>>>>>> 0bab6f34c1 (fix: distributed discounts on si) "modified_by": "Administrator", "module": "Selling", "name": "Quotation Item", diff --git a/erpnext/selling/doctype/quotation_item/quotation_item.py b/erpnext/selling/doctype/quotation_item/quotation_item.py index f209762c3ba..4aeb1ba0ec8 100644 --- a/erpnext/selling/doctype/quotation_item/quotation_item.py +++ b/erpnext/selling/doctype/quotation_item/quotation_item.py @@ -32,6 +32,7 @@ class QuotationItem(Document): description: DF.TextEditor | None discount_amount: DF.Currency discount_percentage: DF.Percent + distributed_discount_amount: DF.Currency gross_profit: DF.Currency has_alternative_item: DF.Check image: DF.Attach | None diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.json b/erpnext/selling/doctype/sales_order_item/sales_order_item.json index d451768eaab..ba183586bcd 100644 --- a/erpnext/selling/doctype/sales_order_item/sales_order_item.json +++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.json @@ -40,6 +40,7 @@ "column_break_19", "discount_percentage", "discount_amount", + "distributed_discount_amount", "base_rate_with_margin", "section_break_simple1", "rate", @@ -280,7 +281,7 @@ }, { "collapsible": 1, - "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount", + "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount || doc.distributed_discount_amount", "fieldname": "discount_and_margin", "fieldtype": "Section Break", "label": "Discount and Margin" @@ -905,12 +906,22 @@ "label": "Is Stock Item", "print_hide": 1, "report_hide": 1 + }, + { + "fieldname": "distributed_discount_amount", + "fieldtype": "Currency", + "label": "Distributed Discount Amount", + "options": "currency" } ], "idx": 1, "istable": 1, "links": [], +<<<<<<< HEAD "modified": "2024-03-21 18:15:56.625005", +======= + "modified": "2024-06-02 06:13:40.597947", +>>>>>>> 0bab6f34c1 (fix: distributed discounts on si) "modified_by": "Administrator", "module": "Selling", "name": "Sales Order Item", diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.py b/erpnext/selling/doctype/sales_order_item/sales_order_item.py index fa7b9b968f3..58be64bce21 100644 --- a/erpnext/selling/doctype/sales_order_item/sales_order_item.py +++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.py @@ -38,6 +38,7 @@ class SalesOrderItem(Document): description: DF.TextEditor | None discount_amount: DF.Currency discount_percentage: DF.Percent + distributed_discount_amount: DF.Currency ensure_delivery_based_on_produced_serial_no: DF.Check grant_commission: DF.Check gross_profit: DF.Currency diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json index b8164b25753..136dd2a7572 100644 --- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json +++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json @@ -40,6 +40,7 @@ "column_break_19", "discount_percentage", "discount_amount", + "distributed_discount_amount", "base_rate_with_margin", "section_break_1", "rate", @@ -274,7 +275,7 @@ }, { "collapsible": 1, - "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount", + "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount || doc.distributed_discount_amount", "fieldname": "discount_and_margin", "fieldtype": "Section Break", "label": "Discount and Margin" @@ -907,13 +908,23 @@ { "fieldname": "column_break_rxvc", "fieldtype": "Column Break" + }, + { + "fieldname": "distributed_discount_amount", + "fieldtype": "Currency", + "label": "Distributed Discount Amount", + "options": "currency" } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], +<<<<<<< HEAD "modified": "2024-03-21 18:15:07.603672", +======= + "modified": "2024-06-02 06:18:38.491763", +>>>>>>> 0bab6f34c1 (fix: distributed discounts on si) "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note Item", diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.py b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.py index b76f7429728..f9597f8b19e 100644 --- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.py +++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.py @@ -36,6 +36,7 @@ class DeliveryNoteItem(Document): description: DF.TextEditor | None discount_amount: DF.Currency discount_percentage: DF.Float + distributed_discount_amount: DF.Currency dn_detail: DF.Data | None expense_account: DF.Link | None grant_commission: DF.Check diff --git a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json index 610bceddf0f..f3e3adee260 100644 --- a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json +++ b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json @@ -48,6 +48,7 @@ "column_break_37", "discount_percentage", "discount_amount", + "distributed_discount_amount", "base_rate_with_margin", "sec_break1", "rate", @@ -911,7 +912,7 @@ }, { "collapsible": 1, - "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount", + "collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount || doc.distributed_discount_amount", "fieldname": "discount_and_margin_section", "fieldtype": "Section Break", "label": "Discount and Margin" @@ -1135,6 +1136,12 @@ "no_copy": 1, "options": "Company:company:default_currency", "print_hide": 1 + }, + { + "fieldname": "distributed_discount_amount", + "fieldtype": "Currency", + "label": "Distributed Discount Amount", + "options": "currency" } ], "idx": 1, diff --git a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.py b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.py index 2154007771d..6581fc00d37 100644 --- a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.py +++ b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.py @@ -36,6 +36,7 @@ class PurchaseReceiptItem(Document): description: DF.TextEditor | None discount_amount: DF.Currency discount_percentage: DF.Percent + distributed_discount_amount: DF.Currency expense_account: DF.Link | None from_warehouse: DF.Link | None has_item_scanned: DF.Check