From f57f4af1d95a3cec186793f6b27462d469a511ae Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 24 Mar 2022 12:31:37 +0530 Subject: [PATCH 01/11] fix: Write off amount wrongly calculated in POS Invoice (cherry picked from commit ee4258e42c33899fae7b7add8a676274259a40e0) --- erpnext/controllers/taxes_and_totals.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 29da5f11ab..884deb302c 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -581,6 +581,7 @@ class calculate_taxes_and_totals(object): if self.doc.docstatus == 0: self.calculate_outstanding_amount() + self.calculate_write_off_amount() def is_internal_invoice(self): """ @@ -621,7 +622,6 @@ class calculate_taxes_and_totals(object): change_amount = 0 if self.doc.doctype == "Sales Invoice" and not self.doc.get('is_return'): - self.calculate_write_off_amount() self.calculate_change_amount() change_amount = self.doc.change_amount \ if self.doc.party_account_currency == self.doc.currency else self.doc.base_change_amount @@ -671,19 +671,20 @@ class calculate_taxes_and_totals(object): and self.doc.paid_amount > grand_total and not self.doc.is_return \ and any(d.type == "Cash" for d in self.doc.payments): - self.doc.change_amount = flt(self.doc.paid_amount - grand_total + - self.doc.write_off_amount, self.doc.precision("change_amount")) + self.doc.change_amount = flt(self.doc.paid_amount - grand_total, + self.doc.precision("change_amount")) - self.doc.base_change_amount = flt(self.doc.base_paid_amount - base_grand_total + - self.doc.base_write_off_amount, self.doc.precision("base_change_amount")) + self.doc.base_change_amount = flt(self.doc.base_paid_amount - base_grand_total, + self.doc.precision("base_change_amount")) def calculate_write_off_amount(self): - if flt(self.doc.change_amount) > 0: - self.doc.write_off_amount = flt(self.doc.grand_total - self.doc.paid_amount - + self.doc.change_amount, self.doc.precision("write_off_amount")) + if self.doc.write_off_outstanding_amount_automatically: + self.doc.write_off_amount = flt(self.doc.outstanding_amount, self.doc.precision("write_off_amount")) self.doc.base_write_off_amount = flt(self.doc.write_off_amount * self.doc.conversion_rate, self.doc.precision("base_write_off_amount")) + self.calculate_outstanding_amount() + def calculate_margin(self, item): rate_with_margin = 0.0 base_rate_with_margin = 0.0 From d04d3038f5764e6eb228aea3cad7e9f3b98848ab Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 24 Mar 2022 12:56:22 +0530 Subject: [PATCH 02/11] fix: Client side changes for POS Write off amount (cherry picked from commit 2e33e748ea248acface128f759d3982635024399) # Conflicts: # erpnext/public/js/controllers/taxes_and_totals.js --- .../public/js/controllers/taxes_and_totals.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 9fec43b74e..56454c8942 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -690,7 +690,12 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { this.frm.doc.total_advance = flt(total_allocated_amount, precision("total_advance")); this.calculate_outstanding_amount(update_paid_amount); +<<<<<<< HEAD } +======= + this.calculate_write_off_amount(); + }, +>>>>>>> 2e33e748ea (fix: Client side changes for POS Write off amount) is_internal_invoice() { if (['Sales Invoice', 'Purchase Invoice'].includes(this.frm.doc.doctype)) { @@ -825,26 +830,28 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { var grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total; var base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total; - this.frm.doc.change_amount = flt(this.frm.doc.paid_amount - grand_total + - this.frm.doc.write_off_amount, precision("change_amount")); + this.frm.doc.change_amount = flt(this.frm.doc.paid_amount - grand_total, + precision("change_amount")); this.frm.doc.base_change_amount = flt(this.frm.doc.base_paid_amount - - base_grand_total + this.frm.doc.base_write_off_amount, - precision("base_change_amount")); + base_grand_total, precision("base_change_amount")); } } } +<<<<<<< HEAD calculate_write_off_amount(){ if(this.frm.doc.paid_amount > this.frm.doc.grand_total){ +======= + calculate_write_off_amount: function() { + if (this.frm.doc.write_off_outstanding_amount_automatically) { +>>>>>>> 2e33e748ea (fix: Client side changes for POS Write off amount) this.frm.doc.write_off_amount = flt(this.frm.doc.grand_total - this.frm.doc.paid_amount + this.frm.doc.change_amount, precision("write_off_amount")); - this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate, precision("base_write_off_amount")); - }else{ - this.frm.doc.paid_amount = 0.0; } + this.calculate_outstanding_amount(false); } }; From 8cfa3a9ece1ce4607a4a69b35713ae2336196cc0 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 24 Mar 2022 13:09:55 +0530 Subject: [PATCH 03/11] fix: Ignore for Purchase Invoices (cherry picked from commit ed38679d222e12709396fbb8dacbe9e25ea38ed7) # Conflicts: # erpnext/public/js/controllers/taxes_and_totals.js --- erpnext/public/js/controllers/taxes_and_totals.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 56454c8942..593ee79e28 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -819,7 +819,11 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { this.frm.set_value('base_paid_amount', flt(base_paid_amount, precision("base_paid_amount"))); } +<<<<<<< HEAD calculate_change_amount(){ +======= + calculate_change_amount: function() { +>>>>>>> ed38679d22 (fix: Ignore for Purchase Invoices) this.frm.doc.change_amount = 0.0; this.frm.doc.base_change_amount = 0.0; if(in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype) From b2ac773ccaed48debc724beadb40843e7e471461 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 24 Mar 2022 13:35:32 +0530 Subject: [PATCH 04/11] fix: Ignore for Purchase Invoices (cherry picked from commit d3fd2fd2c535733939ed69439301033052f45712) --- erpnext/controllers/taxes_and_totals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 884deb302c..22aa6677b6 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -678,7 +678,7 @@ class calculate_taxes_and_totals(object): self.doc.precision("base_change_amount")) def calculate_write_off_amount(self): - if self.doc.write_off_outstanding_amount_automatically: + if self.doc.get('write_off_outstanding_amount_automatically'): self.doc.write_off_amount = flt(self.doc.outstanding_amount, self.doc.precision("write_off_amount")) self.doc.base_write_off_amount = flt(self.doc.write_off_amount * self.doc.conversion_rate, self.doc.precision("base_write_off_amount")) From 19b1b1f4babe244b60961bef940f9ec689d736fc Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Fri, 25 Mar 2022 18:02:14 +0530 Subject: [PATCH 05/11] test: test for auto write-off amount (cherry picked from commit 6a50f36b3167d43b1e964d4f0cf96af587f1a4a2) # Conflicts: # erpnext/public/js/controllers/taxes_and_totals.js --- .../sales_invoice/test_sales_invoice.py | 29 +++++++++++++++++-- erpnext/controllers/taxes_and_totals.py | 3 ++ .../public/js/controllers/taxes_and_totals.js | 11 ++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 62c3508ab0..164c1f8a10 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -813,12 +813,37 @@ class TestSalesInvoice(unittest.TestCase): pos.append("payments", {'mode_of_payment': 'Bank Draft', 'account': '_Test Bank - TCP1', 'amount': 50}) pos.append("payments", {'mode_of_payment': 'Cash', 'account': 'Cash - TCP1', 'amount': 60}) - pos.change_amount = 5.0 + pos.write_off_outstanding_amount_automatically = 1 pos.insert() pos.submit() self.assertEqual(pos.grand_total, 100.0) - self.assertEqual(pos.write_off_amount, -5) + self.assertEqual(pos.write_off_amount, 0) + + def test_auto_write_off_amount(self): + make_pos_profile(company="_Test Company with perpetual inventory", income_account = "Sales - TCP1", + expense_account = "Cost of Goods Sold - TCP1", warehouse="Stores - TCP1", cost_center = "Main - TCP1", write_off_account="_Test Write Off - TCP1") + + make_purchase_receipt(company= "_Test Company with perpetual inventory", + item_code= "_Test FG Item",warehouse= "Stores - TCP1", cost_center= "Main - TCP1") + + pos = create_sales_invoice(company= "_Test Company with perpetual inventory", + debit_to="Debtors - TCP1", item_code= "_Test FG Item", warehouse="Stores - TCP1", + income_account = "Sales - TCP1", expense_account = "Cost of Goods Sold - TCP1", + cost_center = "Main - TCP1", do_not_save=True) + + pos.is_pos = 1 + pos.update_stock = 1 + + pos.append("payments", {'mode_of_payment': 'Bank Draft', 'account': '_Test Bank - TCP1', 'amount': 50}) + pos.append("payments", {'mode_of_payment': 'Cash', 'account': 'Cash - TCP1', 'amount': 40}) + + pos.write_off_outstanding_amount_automatically = 1 + pos.insert() + pos.submit() + + self.assertEqual(pos.grand_total, 100.0) + self.assertEqual(pos.write_off_amount, 10) def test_pos_with_no_gl_entry_for_change_amount(self): frappe.db.set_value('Accounts Settings', None, 'post_change_gl_entries', 0) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 22aa6677b6..dd28dedf6d 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -580,6 +580,9 @@ class calculate_taxes_and_totals(object): .format(self.doc.party_account_currency, invoice_total)) if self.doc.docstatus == 0: + if self.doc.get('write_off_outstanding_amount_automatically'): + self.doc.write_off_amount = 0 + self.calculate_outstanding_amount() self.calculate_write_off_amount() diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 593ee79e28..734f98722c 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -689,6 +689,10 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { })); this.frm.doc.total_advance = flt(total_allocated_amount, precision("total_advance")); + if (this.frm.doc.write_off_outstanding_amount_automatically) { + this.frm.doc.write_off_amount = 0; + } + this.calculate_outstanding_amount(update_paid_amount); <<<<<<< HEAD } @@ -849,13 +853,18 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { ======= calculate_write_off_amount: function() { if (this.frm.doc.write_off_outstanding_amount_automatically) { +<<<<<<< HEAD >>>>>>> 2e33e748ea (fix: Client side changes for POS Write off amount) this.frm.doc.write_off_amount = flt(this.frm.doc.grand_total - this.frm.doc.paid_amount + this.frm.doc.change_amount, precision("write_off_amount")); +======= + this.frm.doc.write_off_amount = flt(this.frm.doc.outstanding_amount, precision("write_off_amount")); +>>>>>>> 6a50f36b31 (test: test for auto write-off amount) this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate, precision("base_write_off_amount")); + + this.calculate_outstanding_amount(false); } - this.calculate_outstanding_amount(false); } }; From fc09377de25dc08a6eea1ac009dc55c04663ea36 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 27 Mar 2022 19:18:32 +0530 Subject: [PATCH 06/11] fix: Resolve conflicts --- .../public/js/controllers/taxes_and_totals.js | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 734f98722c..15d62cd3cb 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -694,12 +694,8 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { } this.calculate_outstanding_amount(update_paid_amount); -<<<<<<< HEAD - } -======= this.calculate_write_off_amount(); - }, ->>>>>>> 2e33e748ea (fix: Client side changes for POS Write off amount) + } is_internal_invoice() { if (['Sales Invoice', 'Purchase Invoice'].includes(this.frm.doc.doctype)) { @@ -823,11 +819,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { this.frm.set_value('base_paid_amount', flt(base_paid_amount, precision("base_paid_amount"))); } -<<<<<<< HEAD calculate_change_amount(){ -======= - calculate_change_amount: function() { ->>>>>>> ed38679d22 (fix: Ignore for Purchase Invoices) this.frm.doc.change_amount = 0.0; this.frm.doc.base_change_amount = 0.0; if(in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype) @@ -847,19 +839,9 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { } } -<<<<<<< HEAD - calculate_write_off_amount(){ - if(this.frm.doc.paid_amount > this.frm.doc.grand_total){ -======= - calculate_write_off_amount: function() { - if (this.frm.doc.write_off_outstanding_amount_automatically) { -<<<<<<< HEAD ->>>>>>> 2e33e748ea (fix: Client side changes for POS Write off amount) - this.frm.doc.write_off_amount = flt(this.frm.doc.grand_total - this.frm.doc.paid_amount - + this.frm.doc.change_amount, precision("write_off_amount")); -======= + calculate_write_off_amount() { + if(this.frm.doc.paid_amount > this.frm.doc.grand_total) { this.frm.doc.write_off_amount = flt(this.frm.doc.outstanding_amount, precision("write_off_amount")); ->>>>>>> 6a50f36b31 (test: test for auto write-off amount) this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate, precision("base_write_off_amount")); From 18c5b24ac12204e5d7ce47e767f39386fd42808c Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 27 Mar 2022 19:20:37 +0530 Subject: [PATCH 07/11] fix: Update condition --- erpnext/public/js/controllers/taxes_and_totals.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 15d62cd3cb..047ec814b6 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -840,7 +840,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { } calculate_write_off_amount() { - if(this.frm.doc.paid_amount > this.frm.doc.grand_total) { + if(this.frm.doc.write_off_outstanding_amount_automatically) { this.frm.doc.write_off_amount = flt(this.frm.doc.outstanding_amount, precision("write_off_amount")); this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate, precision("base_write_off_amount")); From 76dce2eddc69a1df8277028510a9dbe6ab4acd7d Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 29 Mar 2022 11:21:03 +0530 Subject: [PATCH 08/11] fix: use `name` for links not `item_code` (#30462) --- .../report/item_wise_sales_history/item_wise_sales_history.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.py b/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.py index da0098409b..12ca7b3ff8 100644 --- a/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.py +++ b/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.py @@ -177,11 +177,11 @@ def get_customer_details(): def get_item_details(): - details = frappe.db.get_all("Item", fields=["item_code", "item_name", "item_group"]) + details = frappe.db.get_all("Item", fields=["name", "item_name", "item_group"]) item_details = {} for d in details: item_details.setdefault( - d.item_code, frappe._dict({"item_name": d.item_name, "item_group": d.item_group}) + d.name, frappe._dict({"item_name": d.item_name, "item_group": d.item_group}) ) return item_details From d29e314c812e89fbb68090b5eca8fba1229af687 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 29 Mar 2022 11:47:28 +0530 Subject: [PATCH 09/11] ci: pin click for black (#30464) [skip ci] --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cba6759f61..dc3011f050 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,6 +30,7 @@ repos: rev: 9cb0a69f4d0030cdf687eddf314468b39ed54119 hooks: - id: black + additional_dependencies: ['click==8.0.4'] - repo: https://github.com/timothycrosley/isort rev: 5.9.1 From b12fe0f15bcc5d71c16d5bebc4d494518b6220b4 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 29 Mar 2022 13:54:26 +0530 Subject: [PATCH 10/11] fix: dont check for failed repost while freezing (#30472) [skip ci] --- erpnext/stock/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index 741646dfff..4f1891fd75 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -526,7 +526,7 @@ def check_pending_reposting(posting_date: str, throw_error: bool = True) -> bool filters = { "docstatus": 1, - "status": ["in", ["Queued", "In Progress", "Failed"]], + "status": ["in", ["Queued", "In Progress"]], "posting_date": ["<=", posting_date], } From b80fac03afe99d3c0b9c0f09d6eb34573c5692cf Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 29 Mar 2022 17:19:22 +0530 Subject: [PATCH 11/11] fix: validate 0 transfer qty in stock entry (#30476) --- .../stock/doctype/stock_entry/stock_entry.py | 6 ++- .../doctype/stock_entry/test_stock_entry.py | 48 ++++--------------- 2 files changed, 13 insertions(+), 41 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index bc54f7f84e..c0a8e14dbf 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -225,12 +225,16 @@ class StockEntry(StockController): def set_transfer_qty(self): for item in self.get("items"): if not flt(item.qty): - frappe.throw(_("Row {0}: Qty is mandatory").format(item.idx)) + frappe.throw(_("Row {0}: Qty is mandatory").format(item.idx), title=_("Zero quantity")) if not flt(item.conversion_factor): frappe.throw(_("Row {0}: UOM Conversion Factor is mandatory").format(item.idx)) item.transfer_qty = flt( flt(item.qty) * flt(item.conversion_factor), self.precision("transfer_qty", item) ) + if not flt(item.transfer_qty): + frappe.throw( + _("Row {0}: Qty in Stock UOM can not be zero.").format(item.idx), title=_("Zero quantity") + ) def update_cost_in_project(self): if self.work_order and not frappe.db.get_value( diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index aeedcd1847..3ccd3420e3 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -51,7 +51,6 @@ class TestStockEntry(FrappeTestCase): def tearDown(self): frappe.db.rollback() frappe.set_user("Administrator") - frappe.db.set_value("Manufacturing Settings", None, "material_consumption", "0") def test_fifo(self): frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) @@ -767,13 +766,12 @@ class TestStockEntry(FrappeTestCase): fg_cost, flt(rm_cost + bom_operation_cost + work_order.additional_operating_cost, 2) ) + @change_settings("Manufacturing Settings", {"material_consumption": 1}) def test_work_order_manufacture_with_material_consumption(self): from erpnext.manufacturing.doctype.work_order.work_order import ( make_stock_entry as _make_stock_entry, ) - frappe.db.set_value("Manufacturing Settings", None, "material_consumption", "1") - bom_no = frappe.db.get_value("BOM", {"item": "_Test FG Item", "is_default": 1, "docstatus": 1}) work_order = frappe.new_doc("Work Order") @@ -983,43 +981,6 @@ class TestStockEntry(FrappeTestCase): repack.insert() self.assertRaises(frappe.ValidationError, repack.submit) - # def test_material_consumption(self): - # frappe.db.set_value("Manufacturing Settings", None, "backflush_raw_materials_based_on", "BOM") - # frappe.db.set_value("Manufacturing Settings", None, "material_consumption", "0") - - # from erpnext.manufacturing.doctype.work_order.work_order \ - # import make_stock_entry as _make_stock_entry - # bom_no = frappe.db.get_value("BOM", {"item": "_Test FG Item 2", - # "is_default": 1, "docstatus": 1}) - - # work_order = frappe.new_doc("Work Order") - # work_order.update({ - # "company": "_Test Company", - # "fg_warehouse": "_Test Warehouse 1 - _TC", - # "production_item": "_Test FG Item 2", - # "bom_no": bom_no, - # "qty": 4.0, - # "stock_uom": "_Test UOM", - # "wip_warehouse": "_Test Warehouse - _TC", - # "additional_operating_cost": 1000, - # "use_multi_level_bom": 1 - # }) - # work_order.insert() - # work_order.submit() - - # make_stock_entry(item_code="_Test Serialized Item With Series", target="_Test Warehouse - _TC", qty=50, basic_rate=100) - # make_stock_entry(item_code="_Test Item 2", target="_Test Warehouse - _TC", qty=50, basic_rate=20) - - # item_quantity = { - # '_Test Item': 2.0, - # '_Test Item 2': 12.0, - # '_Test Serialized Item With Series': 6.0 - # } - - # stock_entry = frappe.get_doc(_make_stock_entry(work_order.name, "Material Consumption for Manufacture", 2)) - # for d in stock_entry.get('items'): - # self.assertEqual(item_quantity.get(d.item_code), d.qty) - def test_customer_provided_parts_se(self): create_item( "CUST-0987", is_customer_provided_item=1, customer="_Test Customer", is_purchase_item=0 @@ -1358,6 +1319,13 @@ class TestStockEntry(FrappeTestCase): issue.reload() # reload because reposting current voucher updates rate self.assertEqual(issue.value_difference, -30) + def test_transfer_qty_validation(self): + se = make_stock_entry(item_code="_Test Item", do_not_save=True, qty=0.001, rate=100) + se.items[0].uom = "Kg" + se.items[0].conversion_factor = 0.002 + + self.assertRaises(frappe.ValidationError, se.save) + def make_serialized_item(**args): args = frappe._dict(args)