validate with prevdoc

This commit is contained in:
Nabin Hait 2013-07-08 19:00:29 +05:30
parent 11eda08cd5
commit 2bd37771ca
21 changed files with 174 additions and 225 deletions

View File

@ -69,16 +69,7 @@ class DocType(BuyingController):
self.clear_unallocated_advances("Purchase Invoice Advance", "advance_allocation_details")
self.check_for_acc_head_of_supplier()
self.check_for_stopped_status()
self.po_list, self.pr_list = [], []
for d in getlist(self.doclist, 'entries'):
self.validate_supplier(d)
self.validate_po_pr(d)
if not d.purchase_order in self.po_list:
self.po_list.append(d.purchase_order)
if not d.purhcase_receipt in self.pr_list:
self.pr_list.append(d.purchase_receipt)
self.validate_with_previous_doc()
if not self.doc.is_opening:
self.doc.is_opening = 'No'
@ -167,10 +158,7 @@ class DocType(BuyingController):
if (self.doc.currency == default_currency and flt(self.doc.conversion_rate) != 1.00) or not self.doc.conversion_rate or (self.doc.currency != default_currency and flt(self.doc.conversion_rate) == 1.00):
msgprint("Message: Please Enter Appropriate Conversion Rate.")
raise Exception
# 1. Check whether bill is already booked against this bill no. or not
# 2. Add Remarks
# ---------------------------------------------------------------------
def validate_bill_no(self):
if self.doc.bill_no and self.doc.bill_no.lower().strip() not in ['na', 'not applicable', 'none']:
b_no = sql("select bill_no, name, ifnull(is_opening,'') from `tabPurchase Invoice` where bill_no = '%s' and credit_to = '%s' and docstatus = 1 and name != '%s' " % (self.doc.bill_no, self.doc.credit_to, self.doc.name))
@ -183,16 +171,10 @@ class DocType(BuyingController):
if not self.doc.remarks:
self.doc.remarks = "No Remarks"
# Validate Bill No Date
# ---------------------
def validate_bill_no_date(self):
if self.doc.bill_no and not self.doc.bill_date and self.doc.bill_no.lower().strip() not in ['na', 'not applicable', 'none']:
msgprint(_("Please enter Bill Date"), raise_exception=1)
# 1. Credit To Account Exists
# 2. Is a Credit Account
# 3. Is not a PL Account
# ----------------------------
def validate_credit_acc(self):
acc = sql("select debit_or_credit, is_pl_account from tabAccount where name = %s",
self.doc.credit_to)
@ -226,50 +208,30 @@ class DocType(BuyingController):
if stopped:
msgprint("One cannot do any transaction against 'Purchase Order' : %s, it's status is 'Stopped'" % (d.purhcase_order))
raise Exception
# Validate Supplier
# -----------------
def validate_supplier(self, d):
supplier = ''
if d.purchase_order and not d.purchase_order in self.po_list:
supplier = sql("select supplier from `tabPurchase Order` where name = '%s'" % d.purchase_order)[0][0]
if supplier and not cstr(self.doc.supplier) == cstr(supplier):
msgprint("Supplier name %s do not match with supplier name of purhase order: %s." %(self.doc.supplier,cstr(d.purchase_order)))
raise Exception , " Validation Error "
if d.purchase_receipt and not d.purchase_receipt in self.pr_list:
supplier = sql("select supplier from `tabPurchase Receipt` where name = '%s'" % d.purchase_receipt)[0][0]
if supplier and not cstr(self.doc.supplier) == cstr(supplier):
msgprint("Supplier name %s do not match with supplier name of %s %s." %(self.doc.supplier,cstr(d.purchase_receipt)))
raise Exception , " Validation Error "
def validate_reference_value(self):
pass
# Validate PO and PR
# -------------------
def validate_po_pr(self, d):
# check po / pr for qty and rates and currency and conversion rate
# currency, import_rate must be equal to currency, import_rate of purchase order
if d.purchase_order and not d.purchase_order in self.po_list:
# currency
currency = cstr(sql("select currency from `tabPurchase Order` where name = '%s'" % d.purchase_order)[0][0])
if not cstr(currency) == cstr(self.doc.currency):
msgprint("Purchase Order: " + cstr(d.purchase_order) + " currency : " + cstr(currency) + " does not match with currency of current document.")
raise Exception
# import_rate
rate = flt(sql('select import_rate from `tabPurchase Order Item` where item_code=%s and parent=%s and name = %s', (d.item_code, d.purchase_order, d.po_detail))[0][0])
if abs(rate - flt(d.import_rate)) > 1 and cint(webnotes.defaults.get_global_default('maintain_same_rate')):
msgprint("Import Rate for %s in the Purchase Order is %s. Rate must be same as Purchase Order Rate" % (d.item_code,rate))
raise Exception
if d.purchase_receipt and not d.purchase_receipt in self.pr_list:
# currency , conversion_rate
data = sql("select currency, conversion_rate from `tabPurchase Receipt` where name = '%s'" % d.purchase_receipt, as_dict = 1)
if not cstr(data[0]['currency']) == cstr(self.doc.currency):
msgprint("Purchase Receipt: " + cstr(d.purchase_receipt) + " currency : " + cstr(data[0]['currency']) + " does not match with currency of current document.")
raise Exception
def validate_with_previous_doc(self):
super(DocType, self).validate_with_previous_doc(self.tname, {
"Purchase Order": {
"ref_dn_field": "purchase_order",
"compare_fields": [["supplier", "="], ["company", "="], ["currency", "="]],
},
"Purchase Order Item": {
"ref_dn_field": "po_detail",
"compare_fields": [["export_rate", "="], ["project_name", "="], ["item_code", "="],
["uom", "="]],
"is_child_table": True
},
"Purchase Receipt": {
"ref_dn_field": "purchase_receipt",
"compare_fields": [["customer", "="], ["company", "="], ["currency", "="]],
},
"Purchase Receipt Item": {
"ref_dn_field": "pr_detail",
"compare_fields": [["export_rate", "="], ["project_name", "="], ["item_code", "="],
["uom", "="]],
"is_child_table": True
}
})
def set_aging_date(self):
if self.doc.is_opening != 'Yes':

View File

@ -73,6 +73,7 @@ class DocType(SellingController):
self.validate_posting_time()
self.so_dn_required()
self.validate_proj_cust()
self.validate_with_previous_doc()
sales_com_obj = get_obj('Sales Common')
sales_com_obj.check_stop_sales_order(self)
sales_com_obj.check_active_sales_items(self)
@ -80,7 +81,6 @@ class DocType(SellingController):
sales_com_obj.validate_max_discount(self, 'entries')
sales_com_obj.validate_fiscal_year(self.doc.fiscal_year,
self.doc.posting_date,'Posting Date')
self.validate_customer()
self.validate_customer_account()
self.validate_debit_acc()
self.validate_fixed_asset_account()
@ -105,11 +105,9 @@ class DocType(SellingController):
self.set_aging_date()
self.set_against_income_account()
self.validate_c_form()
self.validate_rate_with_refdoc()
self.validate_time_logs_are_submitted()
self.validate_recurring_invoice()
def on_submit(self):
if cint(self.doc.update_stock) == 1:
sl_obj = get_obj("Stock Ledger")
@ -375,19 +373,6 @@ class DocType(SellingController):
(not acc_head and (self.doc.debit_to != cstr(self.doc.customer) + " - " + self.get_company_abbr())):
msgprint("Debit To: %s do not match with Customer: %s for Company: %s.\n If both correctly entered, please select Master Type \
and Master Name in account master." %(self.doc.debit_to, self.doc.customer,self.doc.company), raise_exception=1)
def validate_customer(self):
""" Validate customer name with SO and DN"""
if self.doc.customer:
for d in getlist(self.doclist,'entries'):
dt = d.delivery_note and 'Delivery Note' or d.sales_order and 'Sales Order' or ''
if dt:
dt_no = d.delivery_note or d.sales_order
cust = webnotes.conn.get_value(dt, dt_no, "customer")
if cust and cstr(cust) != cstr(self.doc.customer):
msgprint("Customer %s does not match with customer of %s: %s."
%(self.doc.customer, dt, dt_no), raise_exception=1)
def validate_debit_acc(self):
@ -414,6 +399,31 @@ class DocType(SellingController):
elif item and item[0][1] == 'Yes' and not acc[0][0] == 'Fixed Asset Account':
msgprint("Please select income head with account type 'Fixed Asset Account' as Item %s is an asset item" % d.item_code)
raise Exception
def validate_with_previous_doc(self):
super(DocType, self).validate_with_previous_doc(self.tname, {
"Sales Order": {
"ref_dn_field": "sales_order",
"compare_fields": [["customer", "="], ["company", "="], ["project_name", "="],
["currency", "="]],
},
"Sales Order Item": {
"ref_dn_field": "so_detail",
"compare_fields": [["export_rate", "="]],
"is_child_table": True
},
"Delivery Note": {
"ref_dn_field": "delivery_note",
"compare_fields": [["customer", "="], ["company", "="], ["project_name", "="],
["currency", "="]],
},
"Delivery Note Item": {
"ref_dn_field": "dn_detail",
"compare_fields": [["export_rate", "="]],
"is_child_table": True
}
})
def set_aging_date(self):
if self.doc.is_opening != 'Yes':
@ -489,22 +499,6 @@ class DocType(SellingController):
webnotes.conn.set(self.doc, 'c_form_no', '')
def validate_rate_with_refdoc(self):
"""Validate values with reference document with previous document"""
for d in self.doclist.get({"parentfield": "entries"}):
if d.so_detail:
self.check_value("Sales Order", d.sales_order, d.so_detail,
d.export_rate, d.item_code)
if d.dn_detail:
self.check_value("Delivery Note", d.delivery_note, d.dn_detail,
d.export_rate, d.item_code)
def check_value(self, ref_dt, ref_dn, ref_item_dn, val, item_code):
ref_val = webnotes.conn.get_value(ref_dt + " Item", ref_item_dn, "export_rate")
if flt(ref_val, 2) != flt(val, 2):
msgprint(_("Rate is not matching with ") + ref_dt + ": " + ref_dn +
_(" for item: ") + item_code, raise_exception=True)
def update_current_stock(self):
for d in getlist(self.doclist, 'entries'):
if d.item_code and d.warehouse:

View File

@ -204,16 +204,6 @@ wn.module_page["Accounts"] = [
route: "query-report/Bank Reconciliation Statement",
doctype: "Journal Voucher"
},
{
"label":wn._("Delivered Items To Be Billed"),
route: "query-report/Delivered Items To Be Billed",
doctype: "Sales Invoice"
},
{
"label":wn._("Received Items To Be Billed"),
route: "query-report/Received Items To Be Billed",
doctype: "Purchase Invoice"
},
{
"label":wn._("Ordered Items To Be Billed"),
route: "query-report/Ordered Items To Be Billed",

View File

@ -1,22 +0,0 @@
[
{
"creation": "2013-05-02 15:20:25",
"docstatus": 0,
"modified": "2013-07-08 11:08:23",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Report",
"is_standard": "Yes",
"name": "__common__",
"query": "select \n `tabDelivery Note`.`name` as \"Delivery Note:Link/Delivery Note:120\",\n`tabDelivery Note`.`customer` as \"Customer:Link/Customer:120\",\n`tabDelivery Note`.`status` as \"Status\",\n `tabDelivery Note`.`posting_date` as \"Date:Date\",\n `tabDelivery Note`.`project_name` as \"Project\",\n `tabDelivery Note Item`.item_code as \"Item:Link/Item:120\",\n `tabDelivery Note Item`.amount as \"Amount:Currency:110\",\n (`tabDelivery Note Item`.billed_amt * ifnull(`tabDelivery Note`.conversion_rate, 1)) as \"Billed Amount:Currency:110\",\n (ifnull(`tabDelivery Note Item`.amount,0) - (ifnull(`tabDelivery Note Item`.billed_amt,0) * ifnull(`tabDelivery Note`.conversion_rate, 1))) as \"Pending Amount:Currency:120\",\n `tabDelivery Note Item`.item_name as \"Item Name::150\",\n `tabDelivery Note Item`.description as \"Description:Data:200\",\n `tabDelivery Note Item`.prevdoc_docname as \"Sales Order:Link/Sales Order:120\",\n `tabDelivery Note Item`.prevdoc_date as \"SO Date:Date:100\",\n `tabDelivery Note`.address_display as \"Customer Address::150\"\nfrom\n `tabDelivery Note`, `tabDelivery Note Item`\nwhere\n `tabDelivery Note Item`.`parent` = `tabDelivery Note`.`name`\n and `tabDelivery Note`.docstatus = 1\n and `tabDelivery Note`.status != \"Stopped\"\n and ifnull(`tabDelivery Note Item`.billed_amt,0) < ifnull(`tabDelivery Note Item`.export_amount,0)\norder by `tabDelivery Note`.posting_date asc",
"ref_doctype": "Sales Invoice",
"report_name": "Delivered Items To Be Billed",
"report_type": "Query Report"
},
{
"doctype": "Report",
"name": "Delivered Items To Be Billed"
}
]

View File

@ -1,23 +0,0 @@
[
{
"creation": "2013-05-28 15:57:59",
"docstatus": 0,
"modified": "2013-06-05 12:59:17",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"add_total_row": 1,
"doctype": "Report",
"is_standard": "Yes",
"name": "__common__",
"query": "select \n `tabPurchase Receipt`.`name` as \"Purchase Receipt:Link/Purchase Receipt:120\",\n `tabPurchase Receipt`.`posting_date` as \"Date:Date:100\",\n `tabPurchase Receipt`.`supplier` as \"Supplier:Link/Supplier:120\",\n `tabPurchase Receipt Item`.`project_name` as \"Project\",\n\t`tabPurchase Receipt Item`.item_code as \"Item Code:Link/Item:120\",\n\t`tabPurchase Receipt Item`.amount as \"Amount:Currency:100\",\n\t`tabPurchase Receipt Item`.billed_amt as \"Billed Amount:Currency:100\", \n\t(`tabPurchase Receipt Item`.amount - ifnull(`tabPurchase Receipt Item`.billed_amt, 0)) as \"Amount to Bill:Currency:100\",\n\t`tabPurchase Receipt Item`.item_name as \"Item Name::150\",\n\t`tabPurchase Receipt Item`.description as \"Description::200\"\nfrom\n\t`tabPurchase Receipt`, `tabPurchase Receipt Item`\nwhere\n\t`tabPurchase Receipt Item`.`parent` = `tabPurchase Receipt`.`name`\n\tand `tabPurchase Receipt`.docstatus = 1\n\tand `tabPurchase Receipt`.status != \"Stopped\"\n\tand ifnull(`tabPurchase Receipt Item`.billed_amt, 0) < ifnull(`tabPurchase Receipt Item`.amount, 0)\norder by `tabPurchase Receipt`.posting_date asc",
"ref_doctype": "Purchase Invoice",
"report_name": "Received Items To Be Billed",
"report_type": "Query Report"
},
{
"doctype": "Report",
"name": "Received Items To Be Billed"
}
]

View File

@ -17,8 +17,7 @@
from __future__ import unicode_literals
import webnotes
from webnotes.utils import add_days, cint, cstr, flt
from webnotes.model.doc import addchild
from webnotes.utils import add_days, cstr, flt
from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint, _
@ -184,29 +183,6 @@ class DocType(BuyingController):
if item[0][1] != 'Yes' and item[0][2] != 'Yes':
msgprint("Item %s is not a purchase item or sub-contracted item. Please check" % (d.item_code), raise_exception=True)
if d.fields.has_key('prevdoc_docname') and d.prevdoc_docname:
# check warehouse, uom in previous doc and in current doc are same.
data = sql("select item_code, warehouse, uom from `tab%s` where name = '%s'" % ( self.doctype_dict[d.prevdoc_doctype], d.prevdoc_detail_docname), as_dict = 1)
if not data:
msgprint("Please fetch data in Row " + cstr(d.idx) + " once again or please contact Administrator.")
raise Exception
# Check if Item Code has been modified.
if not cstr(data[0]['item_code']) == cstr(d.item_code):
msgprint("Please check Item %s is not present in %s %s ." % (d.item_code, d.prevdoc_doctype, d.prevdoc_docname))
raise Exception
if cstr(data[0]['warehouse']) and \
not cstr(data[0]['warehouse']) == cstr(d.warehouse):
msgprint("""Please check warehouse %s of Item %s
which is not present in %s %s""" % (d.warehouse, d.item_code,
d.prevdoc_doctype, d.prevdoc_docname), raise_exception=1)
# Check if UOM has been modified.
if not cstr(data[0]['uom']) == cstr(d.uom) and not cstr(d.prevdoc_doctype) == 'Material Request':
msgprint("Please check UOM %s of Item %s which is not present in %s %s ." % \
(d.uom, d.item_code, d.prevdoc_doctype, d.prevdoc_docname), raise_exception=True)
# list criteria that should not repeat if item is stock item
e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom, d.fields.has_key('prevdoc_docname') and d.prevdoc_docname or '', d.fields.has_key('prevdoc_detail_docname') and d.prevdoc_detail_docname or '', d.fields.has_key('batch_no') and d.batch_no or '']
@ -215,7 +191,7 @@ class DocType(BuyingController):
ch = sql("select is_stock_item from `tabItem` where name = '%s'"%d.item_code)
if ch and ch[0][0] == 'Yes':
if ch and ch[0][0] == 'Yes':
# check for same items
if e in check_list:
msgprint("""Item %s has been entered more than once with same description, schedule date, warehouse and uom.\n
@ -239,8 +215,6 @@ class DocType(BuyingController):
msgprint("One cannot do any transaction against %s : %s, it's status is 'Stopped'" %
( doctype, docname), raise_exception=1)
def validate_reference_value(self, obj=None):
pass
# Check Docstatus of Next DocType on Cancel AND of Previous DocType on Submit
def check_docstatus(self, check, doctype, docname , detail_doctype = ''):

View File

@ -47,15 +47,28 @@ class DocType(BuyingController):
pc_obj = get_obj(dt='Purchase Common')
pc_obj.validate_for_items(self)
pc_obj.get_prevdoc_date(self)
self.validate_doc(pc_obj)
self.check_for_stopped_status(pc_obj)
self.validate_with_previous_doc()
self.validate_for_subcontracting()
self.update_raw_materials_supplied("po_raw_material_details")
def validate_fiscal_year(self):
get_obj(dt = 'Purchase Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.transaction_date,'PO Date')
def validate_with_previous_doc(self):
super(DocType, self).validate_with_previous_doc(self.tname, {
"Supplier Quotation": {
"ref_dn_field": "supplier_quotation",
"compare_fields": [["supplier", "="], ["company", "="], ["currency", "="]],
},
"Supplier Quotation Item": {
"ref_dn_field": "supplier_quotation_item",
"compare_fields": [["export_rate", "="], ["project_name", "="], ["item_code", "="],
["uom", "="]],
"is_child_table": True
}
})
# get available qty at warehouse
def get_bin_details(self, arg = ''):
@ -69,10 +82,6 @@ class DocType(BuyingController):
def get_last_purchase_rate(self):
get_obj('Purchase Common').get_last_purchase_rate(self)
def validate_doc(self,pc_obj):
# Validate values with reference document
pc_obj.validate_reference_value(obj = self)
# Check for Stopped status
def check_for_stopped_status(self, pc_obj):

View File

@ -36,6 +36,7 @@ class DocType(BuyingController):
self.validate_fiscal_year()
self.validate_common()
self.validate_with_previous_doc()
def on_submit(self):
purchase_controller = webnotes.get_obj("Purchase Common")
@ -53,11 +54,24 @@ class DocType(BuyingController):
get_obj(dt = 'Purchase Common').validate_fiscal_year( \
self.doc.fiscal_year, self.doc.transaction_date, 'Quotation Date')
def validate_with_previous_doc(self):
super(DocType, self).validate_with_previous_doc(self.tname, {
"Material Request": {
"ref_dn_field": "prevdoc_docname",
"compare_fields": [["company", "="]],
},
"Material Request Item": {
"ref_dn_field": "prevdoc_detail_docname",
"compare_fields": [["item_code", "="], ["uom", "="]],
"is_child_table": True
}
})
def validate_common(self):
pc = get_obj('Purchase Common')
pc.validate_for_items(self)
pc.get_prevdoc_date(self)
pc.validate_reference_value(self)
@webnotes.whitelist()
def make_purchase_order(source_name, target_doclist=None):

View File

@ -358,6 +358,7 @@ class AccountsController(TransactionBase):
def get_company_default(self, fieldname):
from accounts.utils import get_company_default
return get_company_default(self.doc.company, fieldname)
@property
def stock_items(self):

View File

@ -55,7 +55,7 @@ class SellingController(StockController):
def set_price_list_and_item_details(self):
self.set_price_list_currency("Selling")
self.set_missing_item_details(get_item_details)
def get_other_charges(self):
self.doclist = self.doc.clear_table(self.doclist, "other_charges")
self.set_taxes("other_charges", "charge")

View File

@ -19,7 +19,7 @@ patch_list = [
"execute:webnotes.reload_doc('core', 'doctype', 'docfield')",
"execute:webnotes.reload_doc('core', 'doctype', 'docperm') # 2013-04-07",
"execute:webnotes.reload_doc('core', 'doctype', 'report')",
"execute:webnotes.reload_doc('core', 'doctype', 'doctype') # 2013-07-04",
"execute:webnotes.reload_doc('core', 'doctype', 'doctype') # 2013-07-08",
"patches.mar_2012.clean_property_setter",
"patches.april_2012.naming_series_patch",
"patches.mar_2012.cleanup_control_panel",
@ -246,4 +246,6 @@ patch_list = [
"patches.june_2013.p09_update_global_defaults",
"patches.june_2013.p10_lead_address",
"patches.july_2013.p01_remove_doctype_mappers",
"execute:webnotes.delete_doc('Report', 'Delivered Items To Be Billed')",
"execute:webnotes.delete_doc('Report', 'Received Items To Be Billed')",
]

View File

@ -52,7 +52,6 @@ class DocType(TransactionBase):
sales_com_obj = get_obj(dt = 'Sales Common')
sales_com_obj.check_active_sales_items(self)
sales_com_obj.get_prevdoc_date(self)
self.validate_reference_value()
def validate_prev_docname(self):
for d in getlist(self.doclist, 'installed_item_details'):
@ -63,9 +62,6 @@ class DocType(TransactionBase):
def validate_fiscal_year(self):
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year, self.doc.inst_date,
'Installation Date')
def validate_reference_value(self):
pass
def is_serial_no_added(self, item_code, serial_no):
ar_required = webnotes.conn.get_value("Item", item_code, "has_serial_no")

View File

@ -173,6 +173,8 @@ class DocType(SellingController):
sales_com_obj.validate_max_discount(self,'sales_order_details')
self.doclist = sales_com_obj.make_packing_list(self,'sales_order_details')
self.validate_with_previous_doc()
if not self.doc.status:
self.doc.status = "Draft"
@ -183,6 +185,15 @@ class DocType(SellingController):
if not self.doc.billing_status: self.doc.billing_status = 'Not Billed'
if not self.doc.delivery_status: self.doc.delivery_status = 'Not Delivered'
def validate_with_previous_doc(self):
super(DocType, self).validate_with_previous_doc(self.tname, {
"Quotation": {
"ref_dn_field": "prevdoc_docname",
"compare_fields": [["customer", "="], ["company", "="], ["currency", "="]]
}
})
def check_prev_docstatus(self):
for d in getlist(self.doclist, 'sales_order_details'):
cancel_quo = sql("select name from `tabQuotation` where docstatus = 2 and name = '%s'" % d.prevdoc_docname)

View File

@ -118,11 +118,26 @@ class DocType(SellingController):
# Set actual qty for each item in selected warehouse
self.update_current_stock()
self.validate_with_previous_doc()
self.doc.status = 'Draft'
if not self.doc.billing_status: self.doc.billing_status = 'Not Billed'
if not self.doc.installation_status: self.doc.installation_status = 'Not Installed'
if not self.doc.installation_status: self.doc.installation_status = 'Not Installed'
def validate_with_previous_doc(self):
super(DocType, self).validate_with_previous_doc(self.tname, {
"Sales Order": {
"ref_dn_field": "prevdoc_docname",
"compare_fields": [["customer", "="], ["company", "="], ["project_name", "="],
["currency", "="]],
},
"Sales Order Item": {
"ref_dn_field": "prevdoc_detail_docname",
"compare_fields": [["export_rate", "="]],
"is_child_table": True
}
})
def validate_proj_cust(self):
"""check for does customer belong to same project as entered.."""

View File

@ -2,7 +2,7 @@
{
"creation": "2013-05-24 19:29:09",
"docstatus": 0,
"modified": "2013-07-06 19:04:46",
"modified": "2013-07-08 13:17:51",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -101,7 +101,7 @@
"fieldname": "customer_address",
"fieldtype": "Link",
"in_filter": 1,
"label": "Select Shipping Address",
"label": "Billing Address Name",
"options": "Address",
"print_hide": 1,
"read_only": 1
@ -111,6 +111,22 @@
"fieldname": "address_display",
"fieldtype": "Small Text",
"hidden": 1,
"label": "Billing Address",
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "shipping_address_name",
"fieldtype": "Link",
"label": "Shipping Address Name",
"options": "Address",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "shipping_address",
"fieldtype": "Small Text",
"hidden": 1,
"label": "Shipping Address",
"read_only": 1
},

View File

@ -91,6 +91,20 @@ class DocType(BuyingController):
if exists:
webnotes.msgprint("Another Purchase Receipt using the same Challan No. already exists.\
Please enter a valid Challan No.", raise_exception=1)
def validate_with_previous_doc(self):
super(DocType, self).validate_with_previous_doc(self.tname, {
"Purchase Order": {
"ref_dn_field": "prevdoc_docname",
"compare_fields": [["supplier", "="], ["company", "="], ["currency", "="]],
},
"Purchase Order Item": {
"ref_dn_field": "prevdoc_detail_docname",
"compare_fields": [["export_rate", "="], ["project_name", "="], ["warehouse", "="],
["uom", "="], ["item_code", "="]],
"is_child_table": True
}
})
def po_required(self):
if webnotes.conn.get_single_value("Buying Settings", "po_required") == 'Yes':
@ -111,6 +125,7 @@ class DocType(BuyingController):
import utilities
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Cancelled"])
self.validate_with_previous_doc()
self.validate_accepted_rejected_qty()
self.validate_inspection() # Validate Inspection
get_obj('Stock Ledger').validate_serial_no(self, 'purchase_receipt_details')
@ -119,7 +134,6 @@ class DocType(BuyingController):
pc_obj = get_obj(dt='Purchase Common')
pc_obj.validate_for_items(self)
pc_obj.get_prevdoc_date(self)
pc_obj.validate_reference_value(self)
self.check_for_stopped_status(pc_obj)
# sub-contracting

View File

@ -20,7 +20,6 @@ import webnotes
from webnotes.utils import add_days, cstr, getdate
from webnotes.model.doc import addchild
from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint
sql = webnotes.conn.sql
@ -191,11 +190,7 @@ class DocType(TransactionBase):
msgprint("Maintenance Schedule against "+d.prevdoc_docname+" already exist")
raise Exception
# Validate values with reference document
#----------------------------------------
def validate_reference_value(self):
pass
def validate_serial_no(self):
for d in getlist(self.doclist, 'item_maintenance_detail'):
cur_s_no=[]
@ -219,8 +214,6 @@ class DocType(TransactionBase):
def validate(self):
self.validate_maintenance_detail()
self.validate_sales_order()
if self.doc.sales_order_no:
self.validate_reference_value()
self.validate_serial_no()
self.validate_start_date()

View File

@ -19,7 +19,6 @@ import webnotes
from webnotes.utils import cstr
from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint
sql = webnotes.conn.sql
@ -38,13 +37,7 @@ class DocType(TransactionBase):
'item_name' : item and item[0]['item_name'] or '',
'description' : item and item[0]['description'] or ''
}
return ret
def validate_reference_value(self, check_for):
if check_for == 'Sales Order':
pass
elif check_for == 'Customer Issue':
pass
return ret
def validate_serial_no(self):
for d in getlist(self.doclist, 'maintenance_visit_details'):
@ -57,16 +50,6 @@ class DocType(TransactionBase):
if not getlist(self.doclist, 'maintenance_visit_details'):
msgprint("Please enter maintenance details")
raise Exception
check_for = ''
for d in getlist(self.doclist, 'maintenance_visit_details'):
if d.prevdoc_doctype == 'Sales Order':
check_for = 'Sales Order'
elif d.prevdoc_doctype == 'Customer Issue':
check_for = 'Customer Issue'
if check_for:
self.validate_reference_value(check_for)
self.validate_serial_no()

View File

@ -298,6 +298,26 @@ class TransactionBase(StatusUpdater):
})
webnotes.bean(event_doclist).insert()
def validate_with_previous_doc(self, source_dt, ref):
for key, val in ref.items():
ref_doc = {}
for d in self.doclist.get({"doctype": source_dt}):
if d.fields[val["ref_dn_field"]]:
ref_doc.setdefault(key, d.fields[val["ref_dn_field"]])
if val.get("is_child_table"):
self.compare_values(ref_doc, val["compare_fields"], d)
else:
self.compare_values(ref_doc, val["compare_fields"])
def compare_values(self, ref_doc, fields, doc=None):
for ref_doctype, ref_docname in ref_doc.items():
prevdoc_values = webnotes.conn.get_value(ref_doctype, ref_docname,
[d[0] for d in fields], as_dict=1)
for field, condition in fields:
self.validate_value(field, condition, prevdoc_values[field], doc)
def get_default_address_and_contact(party_field, party_name, fetch_shipping_address=False):
out = {}