From 707b630851659eea04c4c71740689c11ec94247f Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Thu, 19 Nov 2020 18:42:39 +0530 Subject: [PATCH 1/9] fix: add remarks to sales invoice --- .../doctype/sales_invoice/sales_invoice.py | 9 +++-- erpnext/patches.txt | 3 +- .../v12_0/update_sales_invoice_remarks.py | 35 +++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 erpnext/patches/v12_0/update_sales_invoice_remarks.py diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 2f8b782356d..94bc400fe5b 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import frappe, erpnext import frappe.defaults -from frappe.utils import cint, flt, add_months, today, date_diff, getdate, add_days, cstr, nowdate +from frappe.utils import cint, flt, add_months, today, date_diff, getdate, add_days, cstr, nowdate, formatdate from frappe import _, msgprint, throw from erpnext.accounts.party import get_party_account, get_due_date from erpnext.controllers.stock_controller import update_gl_entries_after @@ -530,7 +530,12 @@ class SalesInvoice(SellingController): self.against_income_account = ','.join(against_acc) def add_remarks(self): - if not self.remarks: self.remarks = 'No Remarks' + if not self.remarks: + if self.po_no and self.po_date: + self.remarks = _("Against Customer Order {0} dated {1}").format(self.po_no, + formatdate(self.po_date)) + else: + self.remarks = _("No Remarks") def validate_auto_set_posting_time(self): # Don't auto set the posting date and time if invoice is amended diff --git a/erpnext/patches.txt b/erpnext/patches.txt index b5f31bafa7e..2615830eb0a 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -677,4 +677,5 @@ erpnext.patches.v12_0.set_multi_uom_in_rfq erpnext.patches.v12_0.update_state_code_for_daman_and_diu erpnext.patches.v12_0.rename_lost_reason_detail erpnext.patches.v12_0.update_leave_application_status -erpnext.patches.v12_0.update_payment_entry_status \ No newline at end of file +erpnext.patches.v12_0.update_payment_entry_status +erpnext.patches.v12_0.update_sales_invoice_remarks \ No newline at end of file diff --git a/erpnext/patches/v12_0/update_sales_invoice_remarks.py b/erpnext/patches/v12_0/update_sales_invoice_remarks.py new file mode 100644 index 00000000000..5443d133a2e --- /dev/null +++ b/erpnext/patches/v12_0/update_sales_invoice_remarks.py @@ -0,0 +1,35 @@ +from __future__ import unicode_literals +from mmap import PAGESIZE +import frappe + +from frappe import _ +from frappe.utils import formatdate + +def execute(): + si_list = frappe.db.get_all('Sales Invoice', filters = { + 'docstatus': 1, + 'remarks': 'No Remarks', + 'po_no' : ['!=', ''], + 'po_date' : ['!=', ''] + }, + fields = ['name', 'po_no', 'po_date'] + ) + + for doc in si_list: + remarks = _("Against Customer Order {0} dated {1}").format(doc.po_no, + formatdate(doc.po_date)) + + frappe.db.set_value('Sales Invoice', doc.name, 'remarks', remarks) + + gl_entry_list = frappe.db.get_all('GL Entry', filters = { + 'voucher_type': 'Sales Invoice', + 'remarks': 'No Remarks', + 'voucher_no' : doc.name + }, + fields = ['name'] + ) + + for entry in gl_entry_list: + frappe.db.set_value('GL Entry', entry.name, 'remarks', remarks) + + \ No newline at end of file From 51a153d8c27ef27c8fc965bff7ac413e238c134f Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Thu, 19 Nov 2020 19:03:22 +0530 Subject: [PATCH 2/9] fix: removed unused code --- erpnext/patches/v12_0/update_sales_invoice_remarks.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/erpnext/patches/v12_0/update_sales_invoice_remarks.py b/erpnext/patches/v12_0/update_sales_invoice_remarks.py index 5443d133a2e..ae6443d3171 100644 --- a/erpnext/patches/v12_0/update_sales_invoice_remarks.py +++ b/erpnext/patches/v12_0/update_sales_invoice_remarks.py @@ -1,5 +1,4 @@ from __future__ import unicode_literals -from mmap import PAGESIZE import frappe from frappe import _ @@ -30,6 +29,4 @@ def execute(): ) for entry in gl_entry_list: - frappe.db.set_value('GL Entry', entry.name, 'remarks', remarks) - - \ No newline at end of file + frappe.db.set_value('GL Entry', entry.name, 'remarks', remarks) \ No newline at end of file From c630be6781f571ebda3f29cdd58759f75f73bcf4 Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Thu, 19 Nov 2020 19:13:06 +0530 Subject: [PATCH 3/9] fix: remove unused imports --- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 94bc400fe5b..1b77f1b733b 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import frappe, erpnext import frappe.defaults -from frappe.utils import cint, flt, add_months, today, date_diff, getdate, add_days, cstr, nowdate, formatdate +from frappe.utils import cint, flt, getdate, add_days, cstr, nowdate, formatdate from frappe import _, msgprint, throw from erpnext.accounts.party import get_party_account, get_due_date from erpnext.controllers.stock_controller import update_gl_entries_after From ef06f3288f5475f54daecb281b60065165371ed3 Mon Sep 17 00:00:00 2001 From: vorasmit Date: Fri, 1 Jan 2021 10:48:44 +0530 Subject: [PATCH 4/9] Delete update_sales_invoice_remarks.py --- .../v12_0/update_sales_invoice_remarks.py | 32 ------------------- 1 file changed, 32 deletions(-) delete mode 100644 erpnext/patches/v12_0/update_sales_invoice_remarks.py diff --git a/erpnext/patches/v12_0/update_sales_invoice_remarks.py b/erpnext/patches/v12_0/update_sales_invoice_remarks.py deleted file mode 100644 index ae6443d3171..00000000000 --- a/erpnext/patches/v12_0/update_sales_invoice_remarks.py +++ /dev/null @@ -1,32 +0,0 @@ -from __future__ import unicode_literals -import frappe - -from frappe import _ -from frappe.utils import formatdate - -def execute(): - si_list = frappe.db.get_all('Sales Invoice', filters = { - 'docstatus': 1, - 'remarks': 'No Remarks', - 'po_no' : ['!=', ''], - 'po_date' : ['!=', ''] - }, - fields = ['name', 'po_no', 'po_date'] - ) - - for doc in si_list: - remarks = _("Against Customer Order {0} dated {1}").format(doc.po_no, - formatdate(doc.po_date)) - - frappe.db.set_value('Sales Invoice', doc.name, 'remarks', remarks) - - gl_entry_list = frappe.db.get_all('GL Entry', filters = { - 'voucher_type': 'Sales Invoice', - 'remarks': 'No Remarks', - 'voucher_no' : doc.name - }, - fields = ['name'] - ) - - for entry in gl_entry_list: - frappe.db.set_value('GL Entry', entry.name, 'remarks', remarks) \ No newline at end of file From 82b4749166eaf2970dbf35b98e92237e09df67ca Mon Sep 17 00:00:00 2001 From: vorasmit Date: Fri, 1 Jan 2021 10:49:48 +0530 Subject: [PATCH 5/9] Update patches.txt --- erpnext/patches.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 2615830eb0a..b9d48069238 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -678,4 +678,3 @@ erpnext.patches.v12_0.update_state_code_for_daman_and_diu erpnext.patches.v12_0.rename_lost_reason_detail erpnext.patches.v12_0.update_leave_application_status erpnext.patches.v12_0.update_payment_entry_status -erpnext.patches.v12_0.update_sales_invoice_remarks \ No newline at end of file From 00865b9af302d6e359f0723234cf9d9a4bdd7d9b Mon Sep 17 00:00:00 2001 From: Saqib Date: Tue, 5 Jan 2021 13:32:46 +0530 Subject: [PATCH 7/9] fix(e-invoicing): minor calculation fixes (#24283) --- .../controllers/sales_and_purchase_return.py | 2 + erpnext/public/js/controllers/transaction.js | 1 + erpnext/regional/india/e_invoice/utils.py | 47 +++++++++++++------ erpnext/stock/get_item_details.py | 4 +- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index 18b5daf128a..c3a15c58ce9 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -279,6 +279,7 @@ def make_return_doc(doctype, source_name, target_doc=None): target_doc.po_detail = source_doc.po_detail target_doc.pr_detail = source_doc.pr_detail target_doc.purchase_invoice_item = source_doc.name + target_doc.price_list_rate = 0 elif doctype == "Delivery Note": target_doc.against_sales_order = source_doc.against_sales_order @@ -297,6 +298,7 @@ def make_return_doc(doctype, source_name, target_doc=None): target_doc.dn_detail = source_doc.dn_detail target_doc.expense_account = source_doc.expense_account target_doc.sales_invoice_item = source_doc.name + target_doc.price_list_rate = 0 if default_warehouse_for_sales_return: target_doc.warehouse = default_warehouse_for_sales_return diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 58fb8e17996..665517fd4c7 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -521,6 +521,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ company: me.frm.doc.company, order_type: me.frm.doc.order_type, is_pos: cint(me.frm.doc.is_pos), + is_return: cint(me.frm.doc.is_return), is_subcontracted: me.frm.doc.is_subcontracted, transaction_date: me.frm.doc.transaction_date || me.frm.doc.posting_date, ignore_pricing_rule: me.frm.doc.ignore_pricing_rule, diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 321e807b7f7..14be8296e52 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -92,21 +92,18 @@ def get_party_details(address_name): location = gstin_details.get('AddrLoc') or address.get('city') state_code = gstin_details.get('StateCode') pincode = gstin_details.get('AddrPncd') - address_line1 = '{} {}'.format(gstin_details.get('AddrBno'), gstin_details.get('AddrFlno')) - address_line2 = '{} {}'.format(gstin_details.get('AddrBnm'), gstin_details.get('AddrSt')) - email_id = address.get('email_id') - phone = address.get('phone') - # get last 10 digit - phone = phone.replace(" ", "")[-10:] if phone else '' + address_line1 = '{} {}'.format(gstin_details.get('AddrBno') or "", gstin_details.get('AddrFlno') or "") + address_line2 = '{} {}'.format(gstin_details.get('AddrBnm') or "", gstin_details.get('AddrSt') or "") if state_code == 97: # according to einvoice standard pincode = 999999 return frappe._dict(dict( - gstin=gstin, legal_name=legal_name, location=location, - pincode=pincode, state_code=state_code, address_line1=address_line1, - address_line2=address_line2, email=email_id, phone=phone + gstin=gstin, legal_name=legal_name, + location=location, pincode=pincode, + state_code=state_code, address_line1=address_line1, + address_line2=address_line2 )) def get_gstin_details(gstin): @@ -146,16 +143,18 @@ def get_item_list(invoice): item.update(d.as_dict()) item.sr_no = d.idx - item.discount_amount = abs(item.discount_amount * item.qty) - item.description = d.item_name + item.description = d.item_name.replace('"', '\\"') + item.qty = abs(item.qty) - item.unit_rate = abs(item.base_net_amount / item.qty) - item.gross_amount = abs(item.base_net_amount) - item.taxable_value = abs(item.base_net_amount) + item.discount_amount = abs(item.discount_amount * item.qty) + item.unit_rate = abs(item.base_amount / item.qty) + item.gross_amount = abs(item.base_amount) + item.taxable_value = abs(item.base_amount) item.batch_expiry_date = frappe.db.get_value('Batch', d.batch_no, 'expiry_date') if d.batch_no else None item.batch_expiry_date = format_date(item.batch_expiry_date, 'dd/mm/yyyy') if item.batch_expiry_date else None item.is_service_item = 'N' if frappe.db.get_value('Item', d.item_code, 'is_stock_item') else 'Y' + item.serial_no = "" item = update_item_taxes(invoice, item) @@ -272,7 +271,25 @@ def get_eway_bill_details(invoice): vehicle_type=vehicle_type[invoice.gst_vehicle_type] )) +def validate_mandatory_fields(invoice): + if not invoice.company_address: + frappe.throw(_('Company Address is mandatory to fetch company GSTIN details.'), title=_('Missing Fields')) + if not invoice.customer_address: + frappe.throw(_('Customer Address is mandatory to fetch customer GSTIN details.'), title=_('Missing Fields')) + if not frappe.db.get_value('Address', invoice.company_address, 'gstin'): + frappe.throw( + _('GSTIN is mandatory to fetch company GSTIN details. Please enter GSTIN in selected company address.'), + title=_('Missing Fields') + ) + if not frappe.db.get_value('Address', invoice.customer_address, 'gstin'): + frappe.throw( + _('GSTIN is mandatory to fetch customer GSTIN details. Please enter GSTIN in selected customer address.'), + title=_('Missing Fields') + ) + def make_einvoice(invoice): + validate_mandatory_fields(invoice) + schema = read_json('einv_template') transaction_details = get_transaction_details(invoice) @@ -358,7 +375,7 @@ def validate_einvoice(validations, einvoice, errors=[]): # remove empty dicts einvoice.pop(fieldname, None) continue - + # convert to int or str if value_type == 'string': einvoice[fieldname] = str(value) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 48b4dc858c4..8e61c461d51 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -72,7 +72,9 @@ def get_item_details(args, doc=None, for_validate=False, overwrite_warehouse=Tru update_party_blanket_order(args, out) - get_price_list_rate(args, item, out) + if not doc or cint(doc.get('is_return')) == 0: + # get price list rate only if the invoice is not a credit or debit note + get_price_list_rate(args, item, out) if args.customer and cint(args.is_pos): out.update(get_pos_profile_item_details(args.company, args)) From 4e12c708976bbc54c3e8265dc2a7c576319de172 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 5 Jan 2021 14:54:52 +0530 Subject: [PATCH 8/9] fix: allow to override the basic rate for the finished good --- erpnext/stock/doctype/stock_entry/stock_entry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 1a68b66a396..c5f7f32274a 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -460,7 +460,7 @@ class StockEntry(StockController): scrap_material_cost += flt(d.basic_amount) number_of_fg_items = len([t.t_warehouse for t in self.get("items") if t.t_warehouse]) - if number_of_fg_items == 1 or update_finished_item_rate: + if (fg_basic_rate == 0.0 and number_of_fg_items == 1) or update_finished_item_rate: self.set_basic_rate_for_finished_goods(raw_material_cost, scrap_material_cost) def get_args_for_incoming_rate(self, item): From ff524e676fcbe3097b1a8ff66ae587839ba06e31 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 5 Jan 2021 15:09:54 +0530 Subject: [PATCH 9/9] fix: 'Set Basic Rate Manually' field is now available for Manufacure type stock entry --- erpnext/stock/doctype/stock_entry/stock_entry.py | 6 ++++-- .../doctype/stock_entry_detail/stock_entry_detail.json | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index c5f7f32274a..1a719b2202a 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -460,7 +460,7 @@ class StockEntry(StockController): scrap_material_cost += flt(d.basic_amount) number_of_fg_items = len([t.t_warehouse for t in self.get("items") if t.t_warehouse]) - if (fg_basic_rate == 0.0 and number_of_fg_items == 1) or update_finished_item_rate: + if number_of_fg_items == 1 or update_finished_item_rate: self.set_basic_rate_for_finished_goods(raw_material_cost, scrap_material_cost) def get_args_for_incoming_rate(self, item): @@ -488,6 +488,8 @@ class StockEntry(StockController): if self.purpose in ["Manufacture", "Repack"]: for d in self.get("items"): + if d.set_basic_rate_manually: continue + if (d.transfer_qty and (d.bom_no or d.t_warehouse) and (getattr(self, "pro_doc", frappe._dict()).scrap_warehouse != d.t_warehouse)): @@ -499,7 +501,7 @@ class StockEntry(StockController): if raw_material_cost and self.purpose == "Manufacture": d.basic_rate = flt((raw_material_cost - scrap_material_cost) / flt(d.transfer_qty), d.precision("basic_rate")) d.basic_amount = flt((raw_material_cost - scrap_material_cost), d.precision("basic_amount")) - elif self.purpose == "Repack" and total_fg_qty and not d.set_basic_rate_manually: + elif self.purpose == "Repack" and total_fg_qty: d.basic_rate = flt(raw_material_cost) / flt(total_fg_qty) d.basic_amount = d.basic_rate * flt(d.qty) diff --git a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json index 9d397df8bcd..29869d01968 100644 --- a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json +++ b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json @@ -494,7 +494,7 @@ }, { "default": "0", - "depends_on": "eval:parent.purpose===\"Repack\" && doc.t_warehouse", + "depends_on": "eval:in_list([\"Repack\", \"Manufacture\"], parent.purpose) && doc.t_warehouse", "fieldname": "set_basic_rate_manually", "fieldtype": "Check", "label": "Set Basic Rate Manually" @@ -502,7 +502,7 @@ ], "idx": 1, "istable": 1, - "modified": "2020-09-04 12:12:35.668198", + "modified": "2021-01-05 15:05:04.891447", "modified_by": "Administrator", "module": "Stock", "name": "Stock Entry Detail",