Replaced doc, doc.fields frappe/frappe#478

This commit is contained in:
Anand Doshi
2014-03-28 13:55:00 +05:30
parent 67d6a4e3aa
commit f78d1aee28
142 changed files with 2443 additions and 2444 deletions

View File

@@ -14,16 +14,16 @@ class Project(Document):
def get_gross_profit(self):
pft, per_pft =0, 0
pft = flt(self.doc.project_value) - flt(self.doc.est_material_cost)
pft = flt(self.project_value) - flt(self.est_material_cost)
#if pft > 0:
per_pft = (flt(pft) / flt(self.doc.project_value)) * 100
per_pft = (flt(pft) / flt(self.project_value)) * 100
ret = {'gross_margin_value': pft, 'per_gross_margin': per_pft}
return ret
def validate(self):
"""validate start date before end date"""
if self.doc.project_start_date and self.doc.completion_date:
if getdate(self.doc.completion_date) < getdate(self.doc.project_start_date):
if self.project_start_date and self.completion_date:
if getdate(self.completion_date) < getdate(self.project_start_date):
msgprint("Expected Completion Date can not be less than Project Start Date")
raise Exception
@@ -32,31 +32,31 @@ class Project(Document):
def update_percent_complete(self):
total = frappe.db.sql("""select count(*) from tabTask where project=%s""",
self.doc.name)[0][0]
self.name)[0][0]
if total:
completed = frappe.db.sql("""select count(*) from tabTask where
project=%s and status in ('Closed', 'Cancelled')""", self.doc.name)[0][0]
frappe.db.set_value("Project", self.doc.name, "percent_complete",
project=%s and status in ('Closed', 'Cancelled')""", self.name)[0][0]
frappe.db.set_value("Project", self.name, "percent_complete",
int(float(completed) / total * 100))
def add_calendar_event(self):
# delete any earlier event for this project
delete_events(self.doc.doctype, self.doc.name)
delete_events(self.doctype, self.name)
# add events
for milestone in self.get("project_milestones"):
if milestone.milestone_date:
description = (milestone.milestone or "Milestone") + " for " + self.doc.name
description = (milestone.milestone or "Milestone") + " for " + self.name
frappe.bean({
"doctype": "Event",
"owner": self.doc.owner,
"owner": self.owner,
"subject": description,
"description": description,
"starts_on": milestone.milestone_date + " 10:00:00",
"event_type": "Private",
"ref_type": self.doc.doctype,
"ref_name": self.doc.name
"ref_type": self.doctype,
"ref_name": self.name
}).insert()
def on_trash(self):
delete_events(self.doc.doctype, self.doc.name)
delete_events(self.doctype, self.name)

View File

@@ -13,38 +13,38 @@ from frappe.model.document import Document
class Task(Document):
def get_project_details(self):
return {
"project": self.doc.project
"project": self.project
}
def get_customer_details(self):
cust = frappe.db.sql("select customer_name from `tabCustomer` where name=%s", self.doc.customer)
cust = frappe.db.sql("select customer_name from `tabCustomer` where name=%s", self.customer)
if cust:
ret = {'customer_name': cust and cust[0][0] or ''}
return ret
def validate(self):
if self.doc.exp_start_date and self.doc.exp_end_date and getdate(self.doc.exp_start_date) > getdate(self.doc.exp_end_date):
if self.exp_start_date and self.exp_end_date and getdate(self.exp_start_date) > getdate(self.exp_end_date):
msgprint("'Expected Start Date' can not be greater than 'Expected End Date'")
raise Exception
if self.doc.act_start_date and self.doc.act_end_date and getdate(self.doc.act_start_date) > getdate(self.doc.act_end_date):
if self.act_start_date and self.act_end_date and getdate(self.act_start_date) > getdate(self.act_end_date):
msgprint("'Actual Start Date' can not be greater than 'Actual End Date'")
raise Exception
self.update_status()
def update_status(self):
status = frappe.db.get_value("Task", self.doc.name, "status")
if self.doc.status=="Working" and status !="Working" and not self.doc.act_start_date:
self.doc.act_start_date = today()
status = frappe.db.get_value("Task", self.name, "status")
if self.status=="Working" and status !="Working" and not self.act_start_date:
self.act_start_date = today()
if self.doc.status=="Closed" and status != "Closed" and not self.doc.act_end_date:
self.doc.act_end_date = today()
if self.status=="Closed" and status != "Closed" and not self.act_end_date:
self.act_end_date = today()
def on_update(self):
"""update percent complete in project"""
if self.doc.project:
project = frappe.bean("Project", self.doc.project)
if self.project:
project = frappe.bean("Project", self.project)
project.run_method("update_percent_complete")
@frappe.whitelist()

View File

@@ -22,20 +22,20 @@ class TimeLog(Document):
def calculate_total_hours(self):
from frappe.utils import time_diff_in_hours
self.doc.hours = time_diff_in_hours(self.doc.to_time, self.doc.from_time)
self.hours = time_diff_in_hours(self.to_time, self.from_time)
def set_status(self):
self.doc.status = {
self.status = {
0: "Draft",
1: "Submitted",
2: "Cancelled"
}[self.doc.docstatus or 0]
}[self.docstatus or 0]
if self.doc.time_log_batch:
self.doc.status="Batched for Billing"
if self.time_log_batch:
self.status="Batched for Billing"
if self.doc.sales_invoice:
self.doc.status="Billed"
if self.sales_invoice:
self.status="Billed"
def validate_overlap(self):
existing = frappe.db.sql_list("""select name from `tabTime Log` where owner=%s and
@@ -46,9 +46,9 @@ class TimeLog(Document):
and name!=%s
and ifnull(task, "")=%s
and docstatus < 2""",
(self.doc.owner, self.doc.from_time, self.doc.to_time, self.doc.from_time,
self.doc.to_time, self.doc.from_time, self.doc.name or "No Name",
cstr(self.doc.task)))
(self.owner, self.from_time, self.to_time, self.from_time,
self.to_time, self.from_time, self.name or "No Name",
cstr(self.task)))
if existing:
frappe.msgprint(_("This Time Log conflicts with") + ":" + ', '.join(existing),

View File

@@ -7,7 +7,7 @@ class TimeLogBatchTest(unittest.TestCase):
def test_time_log_status(self):
from erpnext.projects.doctype.time_log.test_time_log import test_records as time_log_records
time_log = frappe.bean(copy=time_log_records[0])
time_log.doc.fields.update({
time_log.update({
"from_time": "2013-01-02 10:00:00.000000",
"to_time": "2013-01-02 11:00:00.000000",
"docstatus": 0
@@ -15,15 +15,15 @@ class TimeLogBatchTest(unittest.TestCase):
time_log.insert()
time_log.submit()
self.assertEquals(frappe.db.get_value("Time Log", time_log.doc.name, "status"), "Submitted")
self.assertEquals(frappe.db.get_value("Time Log", time_log.name, "status"), "Submitted")
tlb = frappe.bean(copy=test_records[0])
tlb.doclist[1].time_log = time_log.doc.name
tlb.doclist[1].time_log = time_log.name
tlb.insert()
tlb.submit()
self.assertEquals(frappe.db.get_value("Time Log", time_log.doc.name, "status"), "Batched for Billing")
self.assertEquals(frappe.db.get_value("Time Log", time_log.name, "status"), "Batched for Billing")
tlb.cancel()
self.assertEquals(frappe.db.get_value("Time Log", time_log.doc.name, "status"), "Submitted")
self.assertEquals(frappe.db.get_value("Time Log", time_log.name, "status"), "Submitted")
test_records = [[
{

View File

@@ -13,12 +13,12 @@ class TimeLogBatch(Document):
def validate(self):
self.set_status()
self.doc.total_hours = 0.0
self.total_hours = 0.0
for d in self.doclist.get({"doctype":"Time Log Batch Detail"}):
tl = frappe.doc("Time Log", d.time_log)
self.update_time_log_values(d, tl)
self.validate_time_log_is_submitted(tl)
self.doc.total_hours += float(tl.hours or 0.0)
self.total_hours += float(tl.hours or 0.0)
def update_time_log_values(self, d, tl):
d.fields.update({
@@ -28,33 +28,33 @@ class TimeLogBatch(Document):
})
def validate_time_log_is_submitted(self, tl):
if tl.status != "Submitted" and self.doc.docstatus == 0:
if tl.status != "Submitted" and self.docstatus == 0:
frappe.msgprint(_("Time Log must have status 'Submitted'") + \
" :" + tl.name + " (" + _(tl.status) + ")", raise_exception=True)
def set_status(self):
self.doc.status = {
self.status = {
"0": "Draft",
"1": "Submitted",
"2": "Cancelled"
}[str(self.doc.docstatus or 0)]
}[str(self.docstatus or 0)]
if self.doc.sales_invoice:
self.doc.status = "Billed"
if self.sales_invoice:
self.status = "Billed"
def on_submit(self):
self.update_status(self.doc.name)
self.update_status(self.name)
def before_cancel(self):
self.update_status(None)
def before_update_after_submit(self):
self.update_status(self.doc.name)
self.update_status(self.name)
def update_status(self, time_log_batch):
self.set_status()
for d in self.doclist.get({"doctype":"Time Log Batch Detail"}):
tl = frappe.bean("Time Log", d.time_log)
tl.doc.time_log_batch = time_log_batch
tl.doc.sales_invoice = self.doc.sales_invoice
tl.time_log_batch = time_log_batch
tl.sales_invoice = self.sales_invoice
tl.update_after_submit()