diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index b241ef78bbd..451c9368816 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -1222,7 +1222,9 @@ "fieldname": "inter_company_invoice_reference", "fieldtype": "Link", "label": "Inter Company Invoice Reference", + "no_copy": 1, "options": "Sales Invoice", + "print_hide": 1, "read_only": 1 }, { @@ -1364,7 +1366,7 @@ "idx": 204, "is_submittable": 1, "links": [], - "modified": "2020-12-25 23:44:48.551116", + "modified": "2020-12-26 20:49:03.305063", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 17c6ee29651..d1eb5ed4037 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -591,16 +591,17 @@ class PurchaseInvoice(BuyingController): ) else: - gl_entries.append( - self.get_gl_dict({ - "account": item.expense_account, - "against": self.supplier, - "debit": warehouse_debit_amount, - "remarks": self.get("remarks") or _("Accounting Entry for Stock"), - "cost_center": item.cost_center, - "project": item.project or self.project - }, account_currency, item=item) - ) + if not self.is_internal_transfer(): + gl_entries.append( + self.get_gl_dict({ + "account": item.expense_account, + "against": self.supplier, + "debit": warehouse_debit_amount, + "remarks": self.get("remarks") or _("Accounting Entry for Stock"), + "cost_center": item.cost_center, + "project": item.project or self.project + }, account_currency, item=item) + ) # Amount added through landed-cost-voucher if landed_cost_entries: @@ -652,13 +653,14 @@ class PurchaseInvoice(BuyingController): if expense_booked_in_pr: expense_account = service_received_but_not_billed_account - gl_entries.append(self.get_gl_dict({ - "account": expense_account, - "against": self.supplier, - "debit": amount, - "cost_center": item.cost_center, - "project": item.project or self.project - }, account_currency, item=item)) + if not self.is_internal_transfer(): + gl_entries.append(self.get_gl_dict({ + "account": expense_account, + "against": self.supplier, + "debit": amount, + "cost_center": item.cost_center, + "project": item.project or self.project + }, account_currency, item=item)) # If asset is bought through this document and not linked to PR if self.update_stock and item.landed_cost_voucher_amount: diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 3cff0ed7c32..5b1d5e1de7c 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1600,6 +1600,8 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None): currency = frappe.db.get_value('Supplier', details.get('party'), 'default_currency') target_doc.company = details.get("company") target_doc.supplier = details.get("party") + target_doc.is_internal_supplier = 1 + target_doc.ignore_pricing_rule = 1 target_doc.buying_price_list = source_doc.selling_price_list if currency: @@ -1620,7 +1622,11 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None): "expense_account", "cost_center", "warehouse" - ] + ], + "field_map": { + 'rate': 'rate', + 'name': 'sales_invoice_item' + } } if source_doc.get('update_stock'): @@ -1629,7 +1635,6 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None): source_document_warehouse_field: target_document_warehouse_field, 'batch_no': 'batch_no', 'serial_no': 'serial_no', - 'name': 'sales_invoice_item' } }) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 89497c21191..283f6c8d38f 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -965,7 +965,7 @@ class AccountsController(TransactionBase): """ if self.doctype in ('Sales Invoice', 'Delivery Note'): internal_party_field = 'is_internal_customer' - elif self.doctype in ('Purchase Invoice', 'Purchase Invoice Item'): + elif self.doctype in ('Purchase Invoice', 'Purchase Receipt'): internal_party_field = 'is_internal_supplier' if self.get(internal_party_field) and (self.represents_company == self.company): diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index f8aaf95d080..296928974a0 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -243,7 +243,7 @@ class BuyingController(StockController): "allow_zero_valuation": d.get("allow_zero_valuation") }, raise_error_if_no_rate=False) - rate = flt(outgoing_rate * d.conversion_factor) + rate = flt(outgoing_rate * d.conversion_factor, d.precision('rate')) else: rate = frappe.db.get_value(ref_doctype, d.get(frappe.scrub(ref_doctype)), 'rate') diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index d052d8ec901..3b60d1830d4 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -333,9 +333,11 @@ class SellingController(StockController): # For internal transfers use incoming rate as the valuation rate if self.get('is_internal_customer') and d.get('target_warehouse'): - d.rate = flt(d.incoming_rate * d.conversion_factor) - frappe.msgprint(_("Row {0}: Item rate has been updated as per valuation rate since its an internal stock transfer") - .format(d.idx), alert=1) + rate = flt(d.incoming_rate * d.conversion_factor, d.precision('rate')) + if d.rate != rate: + d.rate = rate + frappe.msgprint(_("Row {0}: Item rate has been updated as per valuation rate since its an internal stock transfer") + .format(d.idx), alert=1) elif self.get("return_against"): # Get incoming rate of return entry from reference document diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 1b8a5d892f2..cb61b794ca8 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -407,15 +407,15 @@ class StockController(AccountsController): self.validate_inter_company_reference() def validate_in_transit_warehouses(self): - if self.doctype in ('Sales Invoice', 'Delivery Note'): + if (self.doctype == 'Sales Invoice' and self.get('update_stock')) or self.doctype == 'Delivery Note': for item in self.get('items'): if not item.target_warehouse: - frappe.throw(_("Row {0}: Target Warehouse is mandatory for internal transfers")) + frappe.throw(_("Row {0}: Target Warehouse is mandatory for internal transfers").format(item.idx)) - if self.doctype in ('Purchase Invoice', 'Purchase Receipt'): + if (self.doctype == 'Purchase Invoice' and self.get('update_stock')) or self.doctype == 'Purchase Receipt': for item in self.get('items'): if not item.from_warehouse: - frappe.throw(_("Row {0}: From Warehouse is mandatory for internal transfers")) + frappe.throw(_("Row {0}: From Warehouse is mandatory for internal transfers").format(item.idx)) def validate_multi_currency(self): if self.currency != self.company_currency: @@ -428,9 +428,9 @@ class StockController(AccountsController): def validate_inter_company_reference(self): if self.doctype in ('Purchase Invoice', 'Purchase Receipt'): if not (self.get('inter_company_reference') or self.get('inter_company_invoice_reference')): - msg = _("Internal Sale or Delivery Reference needed for internal purchase") - msg += _("Please create purchase from the internal sale or delivery document itself") - frappe.throw(msg) + msg = _("Internal Sale or Delivery Reference missing. ") + msg += _("Please create purchase from internal sale or delivery document itself") + frappe.throw(msg, title=_("Internal Sales Reference Missing")) def repost_future_sle_and_gle(self): args = frappe._dict({ diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 8916776a36a..26c20e353a8 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -655,7 +655,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ args: item_args }, callback: function(r) { - frappe.model.set_value(item.doctype, item.name, 'rate', r.message); + frappe.model.set_value(item.doctype, item.name, 'rate', r.message * item.conversion_factor); } }); }, diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index 711e603c9fe..cd75d51f0c1 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -723,7 +723,9 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None): "doctype": target_doctype + " Item", "field_map": { source_document_warehouse_field: target_document_warehouse_field, - 'name': 'delivery_note_item' + 'name': 'delivery_note_item', + 'batch_no': 'batch_no', + 'serial_no': 'serial_no' }, "field_no_map": [ "warehouse" diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json index f5581c1f98a..8b104dbb22b 100755 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json @@ -1088,7 +1088,9 @@ "fieldname": "inter_company_reference", "fieldtype": "Link", "label": "Inter Company Reference", + "no_copy": 1, "options": "Delivery Note", + "print_hide": 1, "read_only": 1 }, { @@ -1138,7 +1140,7 @@ "idx": 261, "is_submittable": 1, "links": [], - "modified": "2020-12-26 17:10:00.798835", + "modified": "2020-12-26 20:49:39.106049", "modified_by": "Administrator", "module": "Stock", "name": "Purchase Receipt", diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 779581779df..85f6efc3509 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -381,13 +381,13 @@ class update_entries_after(object): update_taxes_and_totals(sle.voucher_type, sle.voucher_no, outgoing_rate) purchase_doctype = 'Purchase Invoice' if sle.voucher_type == 'Sales Invoice' else 'Purchase Receipt' - ref_field = frappe.scrub(sle.voucher_type + ' Item') + ref_doc_field = frappe.scrub(sle.voucher_type + ' Item') - purchase_document_list = frappe.db.get_all(purchase_doctype, {'inter_company_invoice_reference': - sle.voucher_no}, ['name']) + reference_field = 'inter_company_invoice_reference' if purchase_doctype == 'Purchase Invoice' else 'inter_company_reference' + purchase_document_list = frappe.db.get_all(purchase_doctype, {reference_field: sle.voucher_no}, ['name']) for d in purchase_document_list: - frappe.db.set_value(purchase_doctype + ' Item', {ref_field: sle.voucher_detail_no}, 'rate', outgoing_rate) + frappe.db.set_value(purchase_doctype + ' Item', {ref_doc_field: sle.voucher_detail_no}, 'rate', outgoing_rate) update_taxes_and_totals(purchase_doctype, d.name, outgoing_rate) # Update item's incoming rate on transaction