From 33977827c41a356da3164a9edb2756ae556afbe1 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 28 Jul 2017 17:45:12 +0530 Subject: [PATCH] [Fix] Timesheet Company Issue --- .../doctype/production_order/production_order.py | 5 +++-- .../production_order/test_production_order.py | 3 ++- erpnext/patches.txt | 3 ++- erpnext/patches/v8_6/__init__.py | 0 .../v8_6/update_timesheet_company_from_PO.py | 15 +++++++++++++++ 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 erpnext/patches/v8_6/__init__.py create mode 100644 erpnext/patches/v8_6/update_timesheet_company_from_PO.py diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py index 95336137cb..022e9f3d18 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.py +++ b/erpnext/manufacturing/doctype/production_order/production_order.py @@ -273,7 +273,7 @@ class ProductionOrder(Document): 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 @@ def get_events(start, end, filters=None): 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 18aa51d874..1d555f7c0c 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 @@ class TestProductionOrder(unittest.TestCase): 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 @@ class TestProductionOrder(unittest.TestCase): 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 e3a2e58b27..6e2284f493 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -424,4 +424,5 @@ erpnext.patches.v8_1.update_expense_claim_status 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 0000000000..e69de29bb2 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 0000000000..5bab961c04 --- /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