From 4d987a95108ca0c9c7371827155434fcc29a84a5 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 29 Jun 2022 14:58:03 +0530 Subject: [PATCH 01/12] fix: Modify opts parameter misspell (backport #31476) (#31477) fix: Modify opts parameter misspell (#31476) Modify opts parameter misspell closes #31474 (cherry picked from commit 2a619fd7890d542f9c6fa28594c0dae97cfb683a) Co-authored-by: gn306029 --- erpnext/buying/doctype/purchase_order/purchase_order.js | 2 +- erpnext/public/js/utils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index ed0f9002a21..b6f5ff92191 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -425,7 +425,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend( company: me.frm.doc.company }, allow_child_item_selection: true, - child_fielname: "items", + child_fieldname: "items", child_columns: ["item_code", "qty"] }) }, __("Get Items From")); diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index ab218a76d55..396ade0ef13 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -713,7 +713,7 @@ erpnext.utils.map_current_doc = function(opts) { get_query: opts.get_query, add_filters_group: 1, allow_child_item_selection: opts.allow_child_item_selection, - child_fieldname: opts.child_fielname, + child_fieldname: opts.child_fieldname, child_columns: opts.child_columns, size: opts.size, action: function(selections, args) { From b1c6d789a9c6412f69655e5cff482ddf8a466337 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 30 Jun 2022 11:35:01 +0530 Subject: [PATCH 02/12] fix: offset some scheduled jobs to avoid locks (backport #31466) (#31489) fix: offset some scheduled jobs to avoid locks (#31466) If your site has multiple background workers then there's possibility that two jobs will execute in parallal, this creates problem when both are on operating on same data. This PR adds a separate section for hourly and daily jobs which have frequency offset from default frequency to avoid such conflicts. (cherry picked from commit 5d73697c647d5aeadd1b0738c1be8409a3ef7337) Co-authored-by: Ankush Menat --- erpnext/hooks.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 20b84b5cb90..386ac0a2888 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -461,6 +461,14 @@ scheduler_events = { "0/30 * * * *": [ "erpnext.utilities.doctype.video.video.update_youtube_data", ], + # Hourly but offset by 30 minutes + "30 * * * *": [ + "erpnext.accounts.doctype.gl_entry.gl_entry.rename_gle_sle_docs", + ], + # Daily but offset by 45 minutes + "45 0 * * *": [ + "erpnext.stock.reorder_item.reorder_item", + ], }, "all": [ "erpnext.projects.doctype.project.project.project_status_update_reminder", @@ -472,7 +480,6 @@ scheduler_events = { "erpnext.hr.doctype.daily_work_summary_group.daily_work_summary_group.trigger_emails", "erpnext.accounts.doctype.subscription.subscription.process_all", "erpnext.erpnext_integrations.doctype.amazon_mws_settings.amazon_mws_settings.schedule_get_order_details", - "erpnext.accounts.doctype.gl_entry.gl_entry.rename_gle_sle_docs", "erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings.automatic_synchronization", "erpnext.projects.doctype.project.project.hourly_reminder", "erpnext.projects.doctype.project.project.collect_project_status", @@ -484,7 +491,6 @@ scheduler_events = { "erpnext.stock.doctype.repost_item_valuation.repost_item_valuation.repost_entries" ], "daily": [ - "erpnext.stock.reorder_item.reorder_item", "erpnext.support.doctype.issue.issue.auto_close_tickets", "erpnext.crm.doctype.opportunity.opportunity.auto_close_opportunity", "erpnext.controllers.accounts_controller.update_invoice_status", From 2e130c335a3d791ffc73e70bbd1cfb9714b458c4 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 30 Jun 2022 11:37:36 +0530 Subject: [PATCH 03/12] ci: reduce container count on v13 --- .github/workflows/server-tests.yml | 2 +- .github/workflows/ui-tests.yml | 117 ----------------------------- 2 files changed, 1 insertion(+), 118 deletions(-) delete mode 100644 .github/workflows/ui-tests.yml diff --git a/.github/workflows/server-tests.yml b/.github/workflows/server-tests.yml index c62622eecec..5ec90df78ca 100644 --- a/.github/workflows/server-tests.yml +++ b/.github/workflows/server-tests.yml @@ -25,7 +25,7 @@ jobs: fail-fast: false matrix: - container: [1, 2, 3] + container: [1, 2] name: Python Unit Tests diff --git a/.github/workflows/ui-tests.yml b/.github/workflows/ui-tests.yml deleted file mode 100644 index 9f142bd2c2f..00000000000 --- a/.github/workflows/ui-tests.yml +++ /dev/null @@ -1,117 +0,0 @@ -name: UI - -on: - pull_request: - paths-ignore: - - '**.md' - workflow_dispatch: - -concurrency: - group: ui-v13-${{ github.event.number }} - cancel-in-progress: true - -jobs: - test: - runs-on: ubuntu-18.04 - timeout-minutes: 60 - - strategy: - fail-fast: false - - name: UI Tests (Cypress) - - services: - mysql: - image: mariadb:10.3 - env: - MYSQL_ALLOW_EMPTY_PASSWORD: YES - ports: - - 3306:3306 - options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 - - steps: - - name: Clone - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: 3.7 - - - uses: actions/setup-node@v2 - with: - node-version: 14 - check-latest: true - - - name: Add to Hosts - run: | - echo "127.0.0.1 test_site" | sudo tee -a /etc/hosts - - - name: Cache pip - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - ${{ runner.os }}- - - - name: Cache node modules - uses: actions/cache@v2 - env: - cache-name: cache-node-modules - with: - path: ~/.npm - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - - uses: actions/cache@v2 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Cache cypress binary - uses: actions/cache@v2 - with: - path: ~/.cache - key: ${{ runner.os }}-cypress- - restore-keys: | - ${{ runner.os }}-cypress- - ${{ runner.os }}- - - - name: Install - run: bash ${GITHUB_WORKSPACE}/.github/helper/install.sh - env: - DB: mariadb - TYPE: ui - - - name: Site Setup - run: cd ~/frappe-bench/ && bench --site test_site execute erpnext.setup.utils.before_tests - - - name: cypress pre-requisites - run: cd ~/frappe-bench/apps/frappe && yarn add cypress-file-upload@^5 @testing-library/cypress@^8 --no-lockfile - - - - name: Build Assets - run: cd ~/frappe-bench/ && bench build - env: - CI: Yes - - - name: UI Tests - run: cd ~/frappe-bench/ && bench --site test_site run-ui-tests erpnext --headless - env: - CYPRESS_RECORD_KEY: 60a8e3bf-08f5-45b1-9269-2b207d7d30cd - - - name: Show bench console if tests failed - if: ${{ failure() }} - run: cat ~/frappe-bench/bench_run_logs.txt From 1b9a4483d419217d964f3b3ec9ef6281ffa25422 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 1 Jul 2022 15:44:18 +0530 Subject: [PATCH 04/12] chore(meta): update CODEOWNERS --- CODEOWNERS | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index a4a14de1b8e..b52062d2371 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -3,33 +3,35 @@ # These owners will be the default owners for everything in # the repo. Unless a later match takes precedence, -erpnext/accounts/ @nextchamp-saqib @deepeshgarg007 -erpnext/assets/ @nextchamp-saqib @deepeshgarg007 +erpnext/accounts/ @nextchamp-saqib @deepeshgarg007 @ruthra-kumar +erpnext/assets/ @nextchamp-saqib @deepeshgarg007 @ruthra-kumar erpnext/erpnext_integrations/ @nextchamp-saqib erpnext/loan_management/ @nextchamp-saqib @deepeshgarg007 -erpnext/regional @nextchamp-saqib @deepeshgarg007 -erpnext/selling @nextchamp-saqib @deepeshgarg007 +erpnext/regional @nextchamp-saqib @deepeshgarg007 @ruthra-kumar +erpnext/selling @nextchamp-saqib @deepeshgarg007 @ruthra-kumar erpnext/support/ @nextchamp-saqib @deepeshgarg007 pos* @nextchamp-saqib -erpnext/buying/ @marination @rohitwaghchaure @ankush +erpnext/buying/ @marination @rohitwaghchaure @s-aga-r erpnext/e_commerce/ @marination -erpnext/maintenance/ @marination @rohitwaghchaure -erpnext/manufacturing/ @marination @rohitwaghchaure @ankush +erpnext/maintenance/ @marination @rohitwaghchaure @s-aga-r +erpnext/manufacturing/ @marination @rohitwaghchaure @s-aga-r erpnext/portal/ @marination -erpnext/quality_management/ @marination @rohitwaghchaure +erpnext/quality_management/ @marination @rohitwaghchaure @s-aga-r erpnext/shopping_cart/ @marination -erpnext/stock/ @marination @rohitwaghchaure @ankush +erpnext/stock/ @marination @rohitwaghchaure @s-aga-r -erpnext/crm/ @ruchamahabal @pateljannat -erpnext/education/ @ruchamahabal @pateljannat -erpnext/healthcare/ @ruchamahabal @pateljannat @chillaranand -erpnext/hr/ @ruchamahabal @pateljannat +erpnext/crm/ @NagariaHussain +erpnext/education/ @rutwikhdev +erpnext/healthcare/ @chillaranand +erpnext/hr/ @ruchamahabal erpnext/non_profit/ @ruchamahabal -erpnext/payroll @ruchamahabal @pateljannat -erpnext/projects/ @ruchamahabal @pateljannat +erpnext/payroll @ruchamahabal +erpnext/projects/ @ruchamahabal erpnext/controllers @deepeshgarg007 @nextchamp-saqib @rohitwaghchaure @marination +erpnext/patches/ @deepeshgarg007 @nextchamp-saqib @marination rohitwaghchaure +erpnext/public/ @nextchamp-saqib @marination -.github/ @surajshetty3416 @ankush -requirements.txt @gavindsouza +.github/ @ankush +requirements.txt @gavindsouza @ankush From 8727a6c5da9a37ac2ec1d8b4c7c9c074ecf04b6d Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 30 Jun 2022 21:29:54 +0530 Subject: [PATCH 05/12] fix: Internal PI link in Sales Invoice (cherry picked from commit 536e768ba96a20c519f19dfd4c6b65acedd03aef) --- .../doctype/sales_invoice/sales_invoice.py | 29 +++++++++++++++++++ .../sales_invoice/sales_invoice_dashboard.py | 2 ++ 2 files changed, 31 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 069148c1199..ba15523c87a 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -2163,6 +2163,8 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None): source_document_warehouse_field = "from_warehouse" target_document_warehouse_field = "target_warehouse" + received_items = get_received_items(source_name, target_doctype, target_detail_field) + validate_inter_company_transaction(source_doc, doctype) details = get_inter_company_details(source_doc, doctype) @@ -2227,12 +2229,17 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None): shipping_address_name=target_doc.shipping_address_name, ) + def update_item(source, target, source_parent): + target.qty = flt(source.qty) - received_items.get(source.name, 0.0) + item_field_map = { "doctype": target_doctype + " Item", "field_no_map": ["income_account", "expense_account", "cost_center", "warehouse"], "field_map": { "rate": "rate", }, + "postprocess": update_item, + "condition": lambda doc: doc.qty > 0, } if doctype in ["Sales Invoice", "Sales Order"]: @@ -2270,6 +2277,28 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None): return doclist +def get_received_items(reference_name, doctype, reference_fieldname): + target_doctypes = frappe.get_all( + doctype, + filters={"inter_company_invoice_reference": reference_name, "docstatus": 1}, + as_list=True, + ) + + if target_doctypes: + target_doctypes = list(target_doctypes[0]) + + received_items_map = frappe._dict( + frappe.get_all( + doctype + " Item", + filters={"parent": ("in", target_doctypes)}, + fields=[reference_fieldname, "qty"], + as_list=1, + ) + ) + + return received_items_map + + def set_purchase_references(doc): # add internal PO or PR links if any if doc.is_internal_transfer(): diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py index c0005f78cfd..0a765f3f46f 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice_dashboard.py @@ -11,6 +11,7 @@ def get_data(): "Payment Request": "reference_name", "Sales Invoice": "return_against", "Auto Repeat": "reference_document", + "Purchase Invoice": "inter_company_invoice_reference", }, "internal_links": { "Sales Order": ["items", "sales_order"], @@ -30,5 +31,6 @@ def get_data(): {"label": _("Reference"), "items": ["Timesheet", "Delivery Note", "Sales Order"]}, {"label": _("Returns"), "items": ["Sales Invoice"]}, {"label": _("Subscription"), "items": ["Auto Repeat"]}, + {"label": _("Internal Transfers"), "items": ["Purchase Invoice"]}, ], } From fd2ec25588d1c9dbfcda37c07ddbcd01f9d4b6cc Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 19 Jun 2022 21:18:12 +0530 Subject: [PATCH 06/12] feat: Cash and Non trade discounts in Sales Invoice (cherry picked from commit 169ff5a0dd074bc197376d94a977a9ab3f4bb495) # Conflicts: # erpnext/accounts/doctype/sales_invoice/sales_invoice.js --- .../doctype/sales_invoice/sales_invoice.js | 11 +++++++++++ .../doctype/sales_invoice/sales_invoice.json | 14 ++++++++++---- .../doctype/sales_invoice/sales_invoice.py | 18 +++++++++++++++++- erpnext/controllers/taxes_and_totals.py | 7 +++++++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index a36872fb234..cdfb631284c 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -477,7 +477,18 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte this.frm.trigger("calculate_timesheet_totals"); } } +<<<<<<< HEAD }); +======= + + is_cash_or_non_trade_discount() { + this.frm.set_df_property("additional_discount_account", "hidden", 1 - this.frm.doc.is_cash_or_non_trade_discount); + if (!this.frm.doc.is_cash_or_non_trade_discount) { + this.frm.set_value("additional_discount_account", ""); + } + } +}; +>>>>>>> 169ff5a0dd (feat: Cash and Non trade discounts in Sales Invoice) // for backward compatibility: combine new and previous states $.extend(cur_frm.cscript, new erpnext.accounts.SalesInvoiceController({frm: cur_frm})); diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index 327545aa54e..499377d4263 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -106,6 +106,7 @@ "loyalty_redemption_cost_center", "section_break_49", "apply_discount_on", + "is_cash_or_non_trade_discount", "base_discount_amount", "additional_discount_account", "column_break_51", @@ -1790,8 +1791,6 @@ "width": "50%" }, { - "fetch_from": "sales_partner.commission_rate", - "fetch_if_empty": 1, "fieldname": "commission_rate", "fieldtype": "Float", "hide_days": 1, @@ -1990,7 +1989,7 @@ { "fieldname": "additional_discount_account", "fieldtype": "Link", - "label": "Additional Discount Account", + "label": "Discount Account", "options": "Account" }, { @@ -2028,6 +2027,13 @@ "fieldtype": "Currency", "label": "Amount Eligible for Commission", "read_only": 1 + }, + { + "default": "0", + "depends_on": "eval: doc.apply_discount_on == \"Grand Total\"", + "fieldname": "is_cash_or_non_trade_discount", + "fieldtype": "Check", + "label": "Is Cash or Non Trade Discount" } ], "icon": "fa fa-file-text", @@ -2040,7 +2046,7 @@ "link_fieldname": "consolidated_invoice" } ], - "modified": "2022-06-10 03:52:51.409913", + "modified": "2022-06-16 16:22:44.870575", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index ba15523c87a..b8f1e314e82 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1040,7 +1040,7 @@ class SalesInvoice(SellingController): ) if grand_total and not self.is_internal_transfer(): - # Didnot use base_grand_total to book rounding loss gle + # Did not use base_grand_total to book rounding loss gle gl_entries.append( self.get_gl_dict( { @@ -1065,6 +1065,22 @@ class SalesInvoice(SellingController): ) ) + if self.apply_discount_on == "Grand Total" and self.get("is_cash_or_discount_account"): + gl_entries.append( + self.get_gl_dict( + { + "account": self.additional_discount_account, + "against": self.debit_to, + "debit": self.base_discount_amount, + "debit_in_account_currency": self.discount_amount, + "cost_center": self.cost_center, + "project": self.project, + }, + self.currency, + item=self, + ) + ) + def make_tax_gl_entries(self, gl_entries): for tax in self.get("taxes"): amount, base_amount = self.get_tax_amounts(tax, self.enable_discount_accounting) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 2afba91b379..4801315c977 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -500,6 +500,9 @@ class calculate_taxes_and_totals(object): else: self.doc.grand_total = flt(self.doc.net_total) + if self.doc.apply_discount_on == "Grand Total" and self.doc.get("is_cash_or_non_trade_discount"): + self.doc.grand_total -= self.doc.discount_amount + if self.doc.get("taxes"): self.doc.total_taxes_and_charges = flt( self.doc.grand_total - self.doc.net_total - flt(self.doc.rounding_adjustment), @@ -594,6 +597,10 @@ class calculate_taxes_and_totals(object): if not self.doc.apply_discount_on: frappe.throw(_("Please select Apply Discount On")) + if self.doc.apply_discount_on == "Grand Total" and self.doc.is_cash_or_non_trade_discount: + self.discount_amount_applied = True + return + self.doc.base_discount_amount = flt( self.doc.discount_amount * self.doc.conversion_rate, self.doc.precision("base_discount_amount") ) From 9ba7290dc9c4643429c8c435c667f80b714bf3e7 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 19 Jun 2022 21:19:02 +0530 Subject: [PATCH 07/12] fix(India): Discounts in E-Invoicing (cherry picked from commit f337213f33384aea9d80ef97d96d0097d436bd68) --- erpnext/regional/india/e_invoice/utils.py | 27 ++++++++++++++++------- erpnext/regional/india/utils.py | 12 ++++++++-- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 0d53e702d8e..a3abc28104a 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -272,14 +272,18 @@ def get_item_list(invoice): item.description = sanitize_for_json(d.item_name) item.qty = abs(item.qty) - if flt(item.qty) != 0.0: - item.unit_rate = abs(item.taxable_value / item.qty) - else: - item.unit_rate = abs(item.taxable_value) - item.gross_amount = abs(item.taxable_value) - item.taxable_value = abs(item.taxable_value) - item.discount_amount = 0 + if invoice.get("apply_discount_on"): + item.discount_amount = item.base_amount - item.base_net_amount + elif item.discount_amount > 0: + item.discount_amount = item.discount_amount + else: + item.discount_amount = 0 + + item.unit_rate = abs(item.taxable_value - item.discount_amount) / item.qty + + item.gross_amount = abs(item.taxable_value) + item.discount_amount + item.taxable_value = abs(item.taxable_value) item.is_service_item = "Y" if item.gst_hsn_code and item.gst_hsn_code[:2] == "99" else "N" item.serial_no = "" @@ -353,7 +357,14 @@ def update_item_taxes(invoice, item): def get_invoice_value_details(invoice): invoice_value_details = frappe._dict(dict()) invoice_value_details.base_total = abs(sum([i.taxable_value for i in invoice.get("items")])) - invoice_value_details.invoice_discount_amt = 0 + if ( + invoice.apply_discount_on == "Grand Total" + and invoice.discount_amount + and invoice.get("is_cash_or_non_trade_discount") + ): + invoice_value_details.invoice_discount_amt = invoice.base_discount_amount + else: + invoice_value_details.invoice_discount_amt = 0 invoice_value_details.round_off = invoice.base_rounding_adjustment invoice_value_details.base_grand_total = abs(invoice.base_rounded_total) or abs( diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index eb9d6743e13..378f39a7e21 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -1061,8 +1061,16 @@ def update_taxable_values(doc, method): considered_rows.append(prev_row_id) for item in doc.get("items"): - proportionate_value = item.base_net_amount if doc.base_net_total else item.qty - total_value = doc.base_net_total if doc.base_net_total else doc.total_qty + if ( + doc.apply_discount_on == "Grand Total" + and doc.discount_amount + and doc.get("is_cash_or_non_trade_discount") + ): + proportionate_value = item.base_amount if doc.base_total else item.qty + total_value = doc.base_total if doc.base_total else doc.total_qty + else: + proportionate_value = item.base_net_amount if doc.base_net_total else item.qty + total_value = doc.base_net_total if doc.base_net_total else doc.total_qty applicable_charges = flt( flt( From 57dc1026c873099b414e3d5756d8bc94f132dada Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sat, 2 Jul 2022 22:27:20 +0530 Subject: [PATCH 08/12] test: Add test for einvoice discounts (cherry picked from commit 38352b3e46fb18435c780e5775bbc886491eac96) --- .../sales_invoice/test_sales_invoice.py | 57 +++++++++++++++++++ erpnext/regional/india/e_invoice/utils.py | 6 +- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 16210e78bdd..2ff1b34e35e 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -2620,6 +2620,63 @@ class TestSalesInvoice(unittest.TestCase): einvoice = make_einvoice(si) validate_totals(einvoice) + def test_einvoice_discounts(self): + from erpnext.regional.india.e_invoice.utils import make_einvoice, validate_totals + + # Normal Itemized Discount + si = get_sales_invoice_for_e_invoice() + si.apply_discount_on = "" + si.items[0].discount_amount = 4000 + si.items[1].discount_amount = 300 + si.save() + + einvoice = make_einvoice(si) + validate_totals(einvoice) + + self.assertEqual(einvoice["ItemList"][0]["Discount"], 4000) + self.assertEqual(einvoice["ItemList"][1]["Discount"], 300) + self.assertEqual(einvoice["ValDtls"]["Discount"], 0) + + # Invoice Discount on net total + si = get_sales_invoice_for_e_invoice() + si.apply_discount_on = "Net Total" + si.discount_amount = 400 + si.save() + + einvoice = make_einvoice(si) + validate_totals(einvoice) + + self.assertEqual(einvoice["ItemList"][0]["Discount"], 316.83) + self.assertEqual(einvoice["ItemList"][1]["Discount"], 83.17) + self.assertEqual(einvoice["ValDtls"]["Discount"], 0) + + # Invoice Discount on grand total (Itemized Discount) + si = get_sales_invoice_for_e_invoice() + si.apply_discount_on = "Grand Total" + si.discount_amount = 400 + si.save() + + einvoice = make_einvoice(si) + validate_totals(einvoice) + + self.assertEqual(einvoice["ItemList"][0]["Discount"], 268.5) + self.assertEqual(einvoice["ItemList"][1]["Discount"], 70.48) + self.assertEqual(einvoice["ValDtls"]["Discount"], 0) + + # Invoice Discount on grand total (Cash/Non-Trade Discount) + si = get_sales_invoice_for_e_invoice() + si.apply_discount_on = "Grand Total" + si.is_cash_or_non_trade_discount = 1 + si.discount_amount = 400 + si.save() + + einvoice = make_einvoice(si) + validate_totals(einvoice) + + self.assertEqual(einvoice["ItemList"][0]["Discount"], 0) + self.assertEqual(einvoice["ItemList"][1]["Discount"], 0) + self.assertEqual(einvoice["ValDtls"]["Discount"], 400) + def test_item_tax_net_range(self): item = create_item("T Shirt") diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index a3abc28104a..d4a2e026453 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -275,10 +275,6 @@ def get_item_list(invoice): if invoice.get("apply_discount_on"): item.discount_amount = item.base_amount - item.base_net_amount - elif item.discount_amount > 0: - item.discount_amount = item.discount_amount - else: - item.discount_amount = 0 item.unit_rate = abs(item.taxable_value - item.discount_amount) / item.qty @@ -362,7 +358,7 @@ def get_invoice_value_details(invoice): and invoice.discount_amount and invoice.get("is_cash_or_non_trade_discount") ): - invoice_value_details.invoice_discount_amt = invoice.base_discount_amount + invoice_value_details.invoice_discount_amt = invoice.discount_amount else: invoice_value_details.invoice_discount_amt = 0 From 4a5d681c77f2a4c61538146318daffc3562e83ab Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 3 Jul 2022 11:02:21 +0530 Subject: [PATCH 09/12] chore: use get instead of . operator (cherry picked from commit e54ec4b9b6280bf1d12ebd3f0fc8c704551f9652) --- erpnext/controllers/taxes_and_totals.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 4801315c977..589c75783fe 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -597,7 +597,9 @@ class calculate_taxes_and_totals(object): if not self.doc.apply_discount_on: frappe.throw(_("Please select Apply Discount On")) - if self.doc.apply_discount_on == "Grand Total" and self.doc.is_cash_or_non_trade_discount: + if self.doc.apply_discount_on == "Grand Total" and self.doc.get( + "is_cash_or_non_trade_discount" + ): self.discount_amount_applied = True return From c72ae178fa9e0435d97791d027533602abcdf5a0 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 3 Jul 2022 14:05:34 +0530 Subject: [PATCH 10/12] chore: resolve conflicts --- erpnext/accounts/doctype/sales_invoice/sales_invoice.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index cdfb631284c..8f7038df30e 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -476,10 +476,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte }); this.frm.trigger("calculate_timesheet_totals"); } - } -<<<<<<< HEAD -}); -======= + }, is_cash_or_non_trade_discount() { this.frm.set_df_property("additional_discount_account", "hidden", 1 - this.frm.doc.is_cash_or_non_trade_discount); @@ -487,8 +484,8 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte this.frm.set_value("additional_discount_account", ""); } } -}; ->>>>>>> 169ff5a0dd (feat: Cash and Non trade discounts in Sales Invoice) + +}); // for backward compatibility: combine new and previous states $.extend(cur_frm.cscript, new erpnext.accounts.SalesInvoiceController({frm: cur_frm})); From 5fc93076f47cd92f48c10c7cf0e2f62a264959cc Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 4 Jul 2022 13:18:34 +0530 Subject: [PATCH 11/12] chore: ignore late binding warnings Most are false positives [skip ci] --- .github/helper/.flake8_strict | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/helper/.flake8_strict b/.github/helper/.flake8_strict index a79137d7c32..198ec7bfe54 100644 --- a/.github/helper/.flake8_strict +++ b/.github/helper/.flake8_strict @@ -66,6 +66,7 @@ ignore = F841, E713, E712, + B023 max-line-length = 200 From 31fd263825a811942d20e6a48b8d92c07b642f7d Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 4 Jul 2022 17:02:11 +0530 Subject: [PATCH 12/12] fix(UX): dont apply price list when changing batch on mapped docs (backport #31503) (#31504) fix(UX): dont apply price list when changing batch on mapped docs (#31503) fix(UX): dont apply price list batch change on mapped docs (cherry picked from commit 7e40c86c56c81abbbfa23ef79b7e14b9a6a47090) Co-authored-by: Ankush Menat --- erpnext/public/js/controllers/transaction.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 3a51dd1a261..b83d5a8d7ae 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1223,9 +1223,25 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } }, + is_a_mapped_document(item) { + const mapped_item_field_map = { + "Delivery Note Item": ["si_detail", "so_detail", "dn_detail"], + "Sales Invoice Item": ["dn_detail", "so_detail", "sales_invoice_item"], + "Purchase Receipt Item": ["purchase_order_item", "purchase_invoice_item", "purchase_receipt_item"], + "Purchase Invoice Item": ["purchase_order_item", "pr_detail", "po_detail"], + }; + const mappped_fields = mapped_item_field_map[item.doctype] || []; + + return mappped_fields + .map((field) => item[field]) + .filter(Boolean).length > 0; + }, + batch_no: function(doc, cdt, cdn) { let item = frappe.get_doc(cdt, cdn); - this.apply_price_list(item, true); + if (!this.is_a_mapped_document(item)) { + this.apply_price_list(item, true); + } }, toggle_conversion_factor: function(item) {