Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subcontracting Order use Default currency instead of Company Currency #41030

Open
NexiaMoe opened this issue Apr 16, 2024 · 1 comment
Open
Labels

Comments

@NexiaMoe
Copy link

Information about bug

When create Subcontracting Order from Purchase Order, Rate on PO is using Company Currency (CNY, or IDR) but when create new Subcontracting Order from PO, it use Company Currency rate to Rate without converting or Missing rate for company currency.

I attach example when create new SO
image

This is from PO
image

This should be CNY instead of Default Currency SGD $

Module

buying

Version

ERPNext: v15.17.1
Frappe Framework: v15.17.3

Installation method

docker

Relevant log output / Stack trace / Full Error Message.

No response

@NexiaMoe NexiaMoe added the bug label Apr 16, 2024
@TurkerTunali
Copy link
Contributor

TurkerTunali commented Jun 4, 2024

I also encounter this on v14 and v15 systems. Solved the issue by this dirty code on my custom app.

@frappe.whitelist()

def make_subcontracting_order(source_name, target_doc=None):

	return get_mapped_subcontracting_order(source_name, target_doc)

def get_mapped_subcontracting_order(source_name, target_doc=None):

	from frappe.model.mapper import get_mapped_doc

	if target_doc and isinstance(target_doc, str):

		target_doc = json.loads(target_doc)

		for key in ["service_items", "items", "supplied_items"]:

			if key in target_doc:

				del target_doc[key]

		target_doc = json.dumps(target_doc)

	target_doc = get_mapped_doc(

		"Purchase Order",

		source_name,

		{

			"Purchase Order": {

				"doctype": "Subcontracting Order",

				"field_map": {},

				"field_no_map": ["total_qty", "total", "net_total"],

				"validation": {

					"docstatus": ["=", 1],

				},

			},

			"Purchase Order Item": {

				"doctype": "Subcontracting Order Service Item",

				"field_map": {

					"material_request": "material_request",

					"material_request_item": "material_request_item",

				},

				"field_no_map": [],

			},

		},

		target_doc,

	)

	# Currency is wrong so we need to reevaluate it. https://github.com/frappe/erpnext/issues/41030

	# We need to check the currency of the company and compare it with the po currency.

	# If they are different we need to convert it to the company currency.

	docPO = frappe.get_doc("Purchase Order", source_name)

	if docPO.currency != frappe.get_cached_value("Company", docPO.company, "default_currency"):

		flConversionFactor = docPO.conversion_rate

		for service_item in target_doc.service_items:

			service_item.rate = service_item.rate * flConversionFactor

			service_item.amount = service_item.rate * service_item.fg_item_qty

	target_doc.populate_items_table()

	if target_doc.set_warehouse:

		for item in target_doc.items:

			item.warehouse = target_doc.set_warehouse

	else:

		source_doc = frappe.get_doc("Purchase Order", source_name)

		if source_doc.set_warehouse:

			for item in target_doc.items:

				item.warehouse = source_doc.set_warehouse

		else:

			for idx, item in enumerate(target_doc.items):

				item.warehouse = source_doc.items[idx].warehouse

	return target_doc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants