refactored purchase cycle's get item details and update item details functions and started with purchase price list

This commit is contained in:
Anand Doshi
2013-01-15 18:39:21 +05:30
parent 5c03869472
commit 756dca719b
18 changed files with 794 additions and 850 deletions

View File

@@ -18,18 +18,15 @@ from __future__ import unicode_literals
import webnotes
from webnotes.utils import cstr, flt, get_defaults, getdate
from webnotes.model import db_exists
from webnotes.model.doc import addchild, make_autoname
from webnotes.model.wrapper import getlist, copy_doclist
from webnotes.model.doc import addchild
from webnotes.model.wrapper import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint
sql = webnotes.conn.sql
from utilities.transaction_base import TransactionBase
class DocType(TransactionBase):
from controllers.buying_controller import BuyingController
class DocType(BuyingController):
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
@@ -38,32 +35,9 @@ class DocType(TransactionBase):
self.fname = 'purchase_receipt_details'
self.count = 0
# Autoname
# ---------
def autoname(self):
self.doc.name = make_autoname(self.doc.naming_series+'.#####')
def validate_fiscal_year(self):
get_obj(dt = 'Purchase Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Transaction Date')
def get_item_details(self, arg = ''):
if arg:
return get_obj(dt='Purchase Common').get_item_details(self,arg)
else:
import json
obj = get_obj('Purchase Common')
for doc in self.doclist:
if doc.fields.get('item_code'):
temp = {
'item_code': doc.fields.get('item_code'),
'warehouse': doc.fields.get('warehouse')
}
ret = obj.get_item_details(self, json.dumps(temp))
for r in ret:
if not doc.fields.get(r):
doc.fields[r] = ret[r]
# GET TERMS & CONDITIONS
# =====================================================================================
def get_tc_details(self):
@@ -125,14 +99,6 @@ class DocType(TransactionBase):
#d.valuation_rate = (flt(d.purchase_rate) + ((flt(d.amount) * (total_b_cost)) / (self.doc.net_total * flt(d.qty))) + (flt(d.rm_supp_cost) / flt(d.qty))) / flt(d.conversion_factor)
d.valuation_rate = (flt(d.purchase_rate) + ((flt(d.amount) * (total_b_cost)) / (self.doc.net_total * flt(d.qty))) + (flt(d.rm_supp_cost) / flt(d.qty)) + (flt(d.item_tax_amount)/flt(d.qty))) / flt(d.conversion_factor)
# Check for Stopped status
def check_for_stopped_status(self, pc_obj):
check_list =[]
for d in getlist(self.doclist, 'purchase_receipt_details'):
if d.fields.has_key('prevdoc_docname') and d.prevdoc_docname and d.prevdoc_docname not in check_list:
check_list.append(d.prevdoc_docname)
pc_obj.check_for_stopped_status( d.prevdoc_doctype, d.prevdoc_docname)
#check in manage account if purchase order required or not.
# ====================================================================================
def po_required(self):
@@ -146,6 +112,8 @@ class DocType(TransactionBase):
# validate
def validate(self):
super(DocType, self).validate()
self.po_required()
self.validate_fiscal_year()
@@ -169,7 +137,7 @@ class DocType(TransactionBase):
self.check_for_stopped_status(pc_obj)
# get total in words
dcc = TransactionBase().get_company_currency(self.doc.company)
dcc = super(DocType, self).get_company_currency(self.doc.company)
self.doc.in_words = pc_obj.get_total_in_words(dcc, self.doc.grand_total)
self.doc.in_words_import = pc_obj.get_total_in_words(self.doc.currency, self.doc.grand_total_import)
# update valuation rate
@@ -287,7 +255,6 @@ class DocType(TransactionBase):
check_list.append(d.prevdoc_docname)
pc_obj.check_for_stopped_status( d.prevdoc_doctype, d.prevdoc_docname)
# on submit
def on_submit(self):
purchase_controller = webnotes.get_obj("Purchase Common")

View File

@@ -2,13 +2,14 @@
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-07-17 13:24:57",
"creation": "2012-12-03 17:56:26",
"modified_by": "Administrator",
"modified": "2012-12-03 17:10:41"
"modified": "2013-01-15 15:43:07"
},
{
"is_submittable": 1,
"autoname": "naming_series:",
"allow_attach": 1,
"is_submittable": 1,
"search_fields": "status, posting_date, supplier",
"module": "Stock",
"doctype": "DocType",
@@ -29,6 +30,7 @@
"read": 1,
"doctype": "DocPerm",
"parenttype": "DocType",
"report": 1,
"parentfield": "permissions"
},
{
@@ -36,6 +38,7 @@
"doctype": "DocType"
},
{
"print_width": "50%",
"oldfieldtype": "Column Break",
"doctype": "DocField",
"width": "50%",
@@ -48,7 +51,6 @@
"description": "To manage multiple series please go to Setup > Manage Series",
"no_copy": 1,
"oldfieldtype": "Select",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Series",
"oldfieldname": "naming_series",
@@ -60,15 +62,14 @@
},
{
"print_hide": 1,
"print_width": "150px",
"permlevel": 0,
"oldfieldtype": "Link",
"colour": "White:FFF",
"allow_on_submit": 0,
"doctype": "DocField",
"label": "Supplier",
"oldfieldname": "supplier",
"width": "150px",
"trigger": "Client",
"fieldname": "supplier",
"fieldtype": "Link",
"search_index": 1,
@@ -118,6 +119,7 @@
"permlevel": 1
},
{
"print_width": "50%",
"oldfieldtype": "Column Break",
"doctype": "DocField",
"width": "50%",
@@ -128,9 +130,9 @@
{
"print_hide": 1,
"description": "The date at which current entry will get or has actually executed.",
"print_width": "100px",
"no_copy": 1,
"oldfieldtype": "Date",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Posting Date",
"oldfieldname": "posting_date",
@@ -145,9 +147,9 @@
{
"print_hide": 1,
"description": "Time at which materials were received",
"print_width": "100px",
"no_copy": 1,
"oldfieldtype": "Time",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Posting Time",
"oldfieldname": "posting_time",
@@ -161,9 +163,9 @@
},
{
"print_hide": 0,
"print_width": "100px",
"no_copy": 1,
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Challan No",
"oldfieldname": "challan_no",
@@ -176,9 +178,9 @@
},
{
"print_hide": 0,
"print_width": "100px",
"no_copy": 1,
"oldfieldtype": "Date",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Challan Date",
"oldfieldname": "challan_date",
@@ -191,7 +193,6 @@
},
{
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Items",
"fieldname": "items",
@@ -213,7 +214,6 @@
},
{
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"options": "Simple",
"fieldname": "section_break0",
@@ -222,6 +222,7 @@
},
{
"print_hide": 1,
"print_width": "150px",
"oldfieldtype": "Currency",
"doctype": "DocField",
"label": "Net Total",
@@ -246,7 +247,6 @@
"oldfieldtype": "Button",
"doctype": "DocField",
"label": "Re-Calculate Values",
"trigger": "Client",
"fieldname": "recalculate_values",
"fieldtype": "Button",
"permlevel": 0
@@ -262,6 +262,7 @@
"permlevel": 0
},
{
"print_width": "50%",
"oldfieldtype": "Column Break",
"doctype": "DocField",
"width": "50%",
@@ -273,26 +274,23 @@
"print_hide": 1,
"description": "Supplier's currency",
"oldfieldtype": "Select",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Currency",
"oldfieldname": "currency",
"permlevel": 0,
"options": "link:Currency",
"fieldname": "currency",
"fieldtype": "Select",
"reqd": 1,
"options": "link:Currency"
"permlevel": 0
},
{
"print_hide": 1,
"description": "Rate at which supplier's currency is converted to company's base currency",
"default": "1.00",
"oldfieldtype": "Currency",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Conversion Rate",
"oldfieldname": "conversion_rate",
"trigger": "Client",
"fieldname": "conversion_rate",
"fieldtype": "Float",
"reqd": 1,
@@ -303,19 +301,17 @@
"description": "You can make a purchase receipt from multiple purchase orders. Select purchase orders one by one and click on the button below.",
"no_copy": 1,
"oldfieldtype": "Link",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Purchase Order",
"oldfieldname": "purchase_order_no",
"permlevel": 0,
"options": "Purchase Order",
"fieldname": "purchase_order_no",
"fieldtype": "Link",
"options": "Purchase Order"
"permlevel": 0
},
{
"print_hide": 1,
"oldfieldtype": "Button",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Pull Purchase Order Details",
"options": "get_po_details",
@@ -326,7 +322,6 @@
{
"description": "Add / Edit Taxes and Charges",
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Taxes",
"fieldname": "taxes",
@@ -337,7 +332,6 @@
"print_hide": 1,
"description": "If you have created a standard template in Purchase Taxes and Charges Master, select one and click on the button below.",
"oldfieldtype": "Link",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Purchase Taxes and Charges",
"oldfieldname": "purchase_other_charges",
@@ -371,7 +365,6 @@
"oldfieldtype": "Button",
"doctype": "DocField",
"label": "Calculate Tax",
"trigger": "Client",
"fieldname": "calculate_tax",
"fieldtype": "Button",
"permlevel": 0
@@ -398,7 +391,6 @@
{
"description": "Detailed Breakup of the totals",
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Totals",
"fieldname": "totals",
@@ -418,7 +410,6 @@
{
"print_hide": 1,
"oldfieldtype": "Currency",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Rounded Total",
"oldfieldname": "rounded_total",
@@ -430,7 +421,6 @@
"print_hide": 1,
"description": "In Words will be visible once you save the Purchase Receipt.",
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "In Words",
"oldfieldname": "in_words",
@@ -459,6 +449,7 @@
"permlevel": 1
},
{
"print_width": "50%",
"doctype": "DocField",
"width": "50%",
"fieldname": "column_break3",
@@ -478,7 +469,6 @@
{
"print_hide": 1,
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "In Words (Import)",
"oldfieldname": "in_words_import",
@@ -509,7 +499,6 @@
{
"description": "Add Terms and Conditions for the Purchase Receipt. You can also prepare a Terms and Conditions Master and use the Template.",
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Terms and Conditions",
"fieldname": "terms_section_break",
@@ -583,7 +572,6 @@
{
"description": "Filing in Additional Information about the Purchase Receipt will help you analyze your data better.",
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "More Info",
"fieldname": "more_info",
@@ -593,9 +581,9 @@
{
"print_hide": 1,
"permlevel": 1,
"print_width": "150px",
"no_copy": 1,
"oldfieldtype": "Select",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Status",
"oldfieldname": "status",
@@ -612,7 +600,6 @@
"description": "% of materials billed against this Purchase Receipt",
"no_copy": 1,
"oldfieldtype": "Currency",
"colour": "White:FFF",
"doctype": "DocField",
"label": "% Billed",
"oldfieldname": "per_billed",
@@ -626,17 +613,17 @@
"description": "Select \"Yes\" for sub - contracting items",
"default": "No",
"oldfieldtype": "Select",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Is Subcontracted",
"oldfieldname": "is_subcontracted",
"permlevel": 0,
"options": "\nYes\nNo",
"fieldname": "is_subcontracted",
"fieldtype": "Select",
"options": "\nYes\nNo"
"permlevel": 0
},
{
"print_hide": 1,
"print_width": "150px",
"no_copy": 1,
"oldfieldtype": "Data",
"doctype": "DocField",
@@ -651,6 +638,7 @@
{
"print_hide": 1,
"description": "The date at which current entry is corrected in the system.",
"print_width": "100px",
"no_copy": 1,
"oldfieldtype": "Date",
"doctype": "DocField",
@@ -665,7 +653,6 @@
{
"print_hide": 1,
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Range",
"oldfieldname": "range",
@@ -700,13 +687,11 @@
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Link",
"colour": "White:FFF",
"allow_on_submit": 1,
"doctype": "DocField",
"label": "Select Print Heading",
"oldfieldname": "select_print_heading",
"permlevel": 0,
"trigger": "Client",
"fieldname": "select_print_heading",
"fieldtype": "Link",
"options": "Print Heading",
@@ -716,9 +701,9 @@
"print_hide": 1,
"permlevel": 0,
"description": "Select the relevant company name if you have multiple companies",
"print_width": "150px",
"no_copy": 0,
"oldfieldtype": "Link",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Company",
"oldfieldname": "company",
@@ -733,6 +718,7 @@
},
{
"print_hide": 1,
"print_width": "150px",
"permlevel": 0,
"oldfieldtype": "Select",
"doctype": "DocField",
@@ -748,6 +734,7 @@
},
{
"print_hide": 1,
"print_width": "50%",
"oldfieldtype": "Column Break",
"doctype": "DocField",
"width": "50%",
@@ -757,9 +744,9 @@
},
{
"print_hide": 1,
"print_width": "30%",
"permlevel": 0,
"oldfieldtype": "HTML",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Other Details",
"width": "30%",
@@ -774,7 +761,6 @@
"description": "Warehouse where you are maintaining stock of rejected items",
"no_copy": 1,
"oldfieldtype": "Link",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Rejected Warehouse",
"oldfieldname": "rejected_warehouse",
@@ -788,9 +774,9 @@
"print_hide": 1,
"permlevel": 0,
"description": "Supplier warehouse where you have issued raw materials for sub - contracting",
"print_width": "50px",
"no_copy": 1,
"oldfieldtype": "Link",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Supplier Warehouse",
"oldfieldname": "supplier_warehouse",
@@ -803,7 +789,6 @@
"print_hide": 1,
"no_copy": 1,
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Cancel Reason",
"oldfieldname": "cancel_reason",
@@ -849,9 +834,9 @@
{
"print_hide": 0,
"description": "Transporter lorry number",
"print_width": "100px",
"no_copy": 1,
"oldfieldtype": "Data",
"colour": "White:FFF",
"doctype": "DocField",
"label": "LR No",
"oldfieldname": "lr_no",
@@ -863,9 +848,9 @@
{
"print_hide": 0,
"description": "Date on which lorry started from supplier warehouse",
"print_width": "100px",
"no_copy": 1,
"oldfieldtype": "Date",
"colour": "White:FFF",
"doctype": "DocField",
"label": "LR Date",
"oldfieldname": "lr_date",
@@ -875,6 +860,7 @@
"permlevel": 0
},
{
"print_width": "50%",
"doctype": "DocField",
"width": "50%",
"fieldname": "column_break5",
@@ -885,7 +871,6 @@
"print_hide": 1,
"description": "Following table will show values if items are sub - contracted. These values will be fetched from the master of \"Bill of Materials\" of sub - contracted items.",
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Raw Material Details",
"fieldname": "raw_material_details",
@@ -914,72 +899,79 @@
"hidden": 1,
"permlevel": 0
},
{
"amend": 0,
"create": 0,
"doctype": "DocPerm",
"submit": 0,
"write": 0,
"cancel": 0,
"role": "Material Manager",
"permlevel": 1
},
{
"amend": 1,
"create": 1,
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"role": "Purchase User",
"cancel": 1,
"permlevel": 0,
"match": ""
"role": "Material Manager",
"permlevel": 0
},
{
"amend": 0,
"create": 0,
"doctype": "DocPerm",
"submit": 0,
"write": 0,
"cancel": 0,
"role": "Material User",
"permlevel": 1
},
{
"amend": 1,
"create": 1,
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"cancel": 1,
"role": "Material User",
"permlevel": 0
},
{
"amend": 1,
"create": 1,
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"cancel": 1,
"role": "Purchase User",
"permlevel": 0
},
{
"amend": 0,
"create": 0,
"doctype": "DocPerm",
"submit": 0,
"cancel": 0,
"role": "Purchase User",
"permlevel": 1
},
{
"doctype": "DocPerm",
"role": "Supplier",
"match": "supplier",
"permlevel": 0
"permlevel": 0,
"match": "supplier"
},
{
"write": 1,
"amend": 0,
"create": 0,
"doctype": "DocPerm",
"submit": 0,
"write": 1,
"cancel": 0,
"role": "All",
"permlevel": 2
},
{
"amend": 0,
"create": 0,
"doctype": "DocPerm",
"submit": 0,
"write": 0,
"role": "Material Manager",
"cancel": 0,
"permlevel": 1
},
{
"amend": 1,
"create": 1,
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"role": "Material Manager",
"cancel": 1,
"permlevel": 0
},
{
"amend": 0,
"create": 0,
"doctype": "DocPerm",
"submit": 0,
"write": 0,
"role": "Material User",
"cancel": 0,
"permlevel": 1
},
{
"amend": 1,
"create": 1,
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"role": "Material User",
"cancel": 1,
"permlevel": 0
}
]

View File

@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
wn.require("public/app/js/stock_controller.js");
wn.require("public/app/js/controllers/stock_controller.js");
wn.provide("erpnext.stock");
erpnext.stock.StockEntry = erpnext.stock.StockController.extend({

View File

@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
wn.require("public/app/js/stock_controller.js");
wn.require("public/app/js/controllers/stock_controller.js");
wn.provide("erpnext.stock");
erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({