[Fix] Timesheet Company Issue
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py
index 9533613..022e9f3 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/production_order.py
@@ -273,7 +273,7 @@
timesheets = []
plan_days = frappe.db.get_single_value("Manufacturing Settings", "capacity_planning_for_days") or 30
- timesheet = make_timesheet(self.name)
+ timesheet = make_timesheet(self.name, self.company)
timesheet.set('time_logs', [])
for i, d in enumerate(self.operations):
@@ -575,10 +575,11 @@
return data
@frappe.whitelist()
-def make_timesheet(production_order):
+def make_timesheet(production_order, company):
timesheet = frappe.new_doc("Timesheet")
timesheet.employee = ""
timesheet.production_order = production_order
+ timesheet.company = company
return timesheet
@frappe.whitelist()
diff --git a/erpnext/manufacturing/doctype/production_order/test_production_order.py b/erpnext/manufacturing/doctype/production_order/test_production_order.py
index 18aa51d..1d555f7 100644
--- a/erpnext/manufacturing/doctype/production_order/test_production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/test_production_order.py
@@ -87,6 +87,7 @@
name = frappe.db.get_value('Timesheet', {'production_order': prod_order.name}, 'name')
time_sheet_doc = frappe.get_doc('Timesheet', name)
+ self.assertEqual(prod_order.company, time_sheet_doc.company)
time_sheet_doc.submit()
@@ -107,7 +108,7 @@
self.assertEqual(prod_order.operations[0].actual_operation_time, 60)
self.assertEqual(prod_order.operations[0].actual_operating_cost, 100)
- time_sheet_doc1 = make_timesheet(prod_order.name)
+ time_sheet_doc1 = make_timesheet(prod_order.name, prod_order.company)
self.assertEqual(len(time_sheet_doc1.get('time_logs')), 0)
time_sheet_doc.cancel()
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index e3a2e58..6e2284f 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -424,4 +424,5 @@
erpnext.patches.v8_3.update_company_total_sales
erpnext.patches.v8_1.set_delivery_date_in_so_item
erpnext.patches.v8_5.fix_tax_breakup_for_non_invoice_docs
-erpnext.patches.v8_5.update_customer_group_in_POS_profile
\ No newline at end of file
+erpnext.patches.v8_5.update_customer_group_in_POS_profile
+erpnext.patches.v8_6.update_timesheet_company_from_PO
\ No newline at end of file
diff --git a/erpnext/patches/v8_6/__init__.py b/erpnext/patches/v8_6/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/patches/v8_6/__init__.py
diff --git a/erpnext/patches/v8_6/update_timesheet_company_from_PO.py b/erpnext/patches/v8_6/update_timesheet_company_from_PO.py
new file mode 100644
index 0000000..5bab961
--- /dev/null
+++ b/erpnext/patches/v8_6/update_timesheet_company_from_PO.py
@@ -0,0 +1,15 @@
+# Copyright (c) 2017, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+ frappe.reload_doctype('Timesheet')
+ company = frappe.get_all('Company')
+
+ #Check more than one company exists
+ if len(company) > 1:
+ frappe.db.sql(""" update `tabTimesheet` set `tabTimesheet`.company =
+ (select company from `tabProduction Order` where name = `tabTimesheet`.production_order)
+ where production_order is not null and production_order !=''""")
\ No newline at end of file