company default currency fix

This commit is contained in:
Ravi Dey 2011-07-11 16:40:49 +05:30
parent e079a6eb26
commit 6c174a6e35
4 changed files with 445 additions and 445 deletions

View File

@ -19,489 +19,489 @@ convert_to_lists = webnotes.conn.convert_to_lists
from utilities.transaction_base import TransactionBase from utilities.transaction_base import TransactionBase
class DocType(TransactionBase): class DocType(TransactionBase):
def __init__(self,d,dl): def __init__(self,d,dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
self.tname = 'PV Detail' self.tname = 'PV Detail'
self.fname = 'entries' self.fname = 'entries'
# Autoname # Autoname
# --------- # ---------
def autoname(self): def autoname(self):
self.doc.name = make_autoname(self.doc.naming_series+'.####') self.doc.name = make_autoname(self.doc.naming_series+'.####')
# ************************** Trigger Functions **************************** # ************************** Trigger Functions ****************************
# Credit To # Credit To
# ---------- # ----------
def get_credit_to(self): def get_credit_to(self):
acc_head = sql("select name, credit_days from `tabAccount` where (name = %s or (master_name = %s and master_type = 'supplier')) and docstatus != 2", (cstr(self.doc.supplier) + " - " + self.get_company_abbr(),self.doc.supplier)) acc_head = sql("select name, credit_days from `tabAccount` where (name = %s or (master_name = %s and master_type = 'supplier')) and docstatus != 2", (cstr(self.doc.supplier) + " - " + self.get_company_abbr(),self.doc.supplier))
#supp_detail = sql("select supplier_name,address from `tabSupplier` where name = %s", self.doc.supplier, as_dict =1) #supp_detail = sql("select supplier_name,address from `tabSupplier` where name = %s", self.doc.supplier, as_dict =1)
#ret = { #ret = {
# 'supplier_name' : supp_detail and supp_detail[0]['supplier_name'] or '', # 'supplier_name' : supp_detail and supp_detail[0]['supplier_name'] or '',
# 'supplier_address': supp_detail and supp_detail[0]['address'] or '' # 'supplier_address': supp_detail and supp_detail[0]['address'] or ''
#} #}
ret = {} ret = {}
if acc_head and acc_head[0][0]: if acc_head and acc_head[0][0]:
ret['credit_to'] = acc_head[0][0] ret['credit_to'] = acc_head[0][0]
if not self.doc.due_date: if not self.doc.due_date:
ret['due_date'] = add_days(cstr(self.doc.posting_date), acc_head and cint(acc_head[0][1]) or 0) ret['due_date'] = add_days(cstr(self.doc.posting_date), acc_head and cint(acc_head[0][1]) or 0)
elif not acc_head: elif not acc_head:
msgprint("%s does not have an Account Head in %s. You must first create it from the Supplier Master" % (self.doc.supplier, self.doc.company)) msgprint("%s does not have an Account Head in %s. You must first create it from the Supplier Master" % (self.doc.supplier, self.doc.company))
return cstr(ret) return cstr(ret)
def get_cust(self): def get_cust(self):
ret = {} ret = {}
if self.doc.credit_to: if self.doc.credit_to:
ret['supplier'] = get_value('Account',self.doc.credit_to,'master_name') ret['supplier'] = get_value('Account',self.doc.credit_to,'master_name')
return cstr(ret) return cstr(ret)
# Get Default Cost Center and Expense Head from Item Master # Get Default Cost Center and Expense Head from Item Master
# ---------------------------------------------------------- # ----------------------------------------------------------
def get_default_values(self,args): def get_default_values(self,args):
args = eval(args) args = eval(args)
ret = {} ret = {}
if sql("select name from `tabItem` where name = '%s'" % args['item_code']): if sql("select name from `tabItem` where name = '%s'" % args['item_code']):
if not args['expense_head'] or args['expense_head'] == 'undefined': if not args['expense_head'] or args['expense_head'] == 'undefined':
expense_head = sql("select name from `tabAccount` where account_name in (select purchase_account from `tabItem` where name = '%s')" % args['item_code']) expense_head = sql("select name from `tabAccount` where account_name in (select purchase_account from `tabItem` where name = '%s')" % args['item_code'])
ret['expense_head'] = expense_head and expense_head[0][0] or '' ret['expense_head'] = expense_head and expense_head[0][0] or ''
if not args['cost_center'] or args['cost_center'] == 'undefined': if not args['cost_center'] or args['cost_center'] == 'undefined':
cost_center = sql("select cost_center from `tabItem` where name = '%s'" % args['item_code']) cost_center = sql("select cost_center from `tabItem` where name = '%s'" % args['item_code'])
ret['cost_center'] = cost_center and cost_center[0][0] or '' ret['cost_center'] = cost_center and cost_center[0][0] or ''
return cstr(ret) return cstr(ret)
# Get Items based on PO or PR # Get Items based on PO or PR
# ---------------------------- # ----------------------------
def pull_details(self): def pull_details(self):
if self.doc.purchase_receipt_main: if self.doc.purchase_receipt_main:
self.validate_duplicate_docname('purchase_receipt') self.validate_duplicate_docname('purchase_receipt')
self.doclist = get_obj('DocType Mapper', 'Purchase Receipt-Payable Voucher').dt_map('Purchase Receipt', 'Payable Voucher', self.doc.purchase_receipt_main, self.doc, self.doclist, "[['Purchase Receipt', 'Payable Voucher'],['Purchase Receipt Detail', 'PV Detail']]") self.doclist = get_obj('DocType Mapper', 'Purchase Receipt-Payable Voucher').dt_map('Purchase Receipt', 'Payable Voucher', self.doc.purchase_receipt_main, self.doc, self.doclist, "[['Purchase Receipt', 'Payable Voucher'],['Purchase Receipt Detail', 'PV Detail']]")
elif self.doc.purchase_order_main: elif self.doc.purchase_order_main:
self.validate_duplicate_docname('purchase_order') self.validate_duplicate_docname('purchase_order')
self.doclist = get_obj('DocType Mapper', 'Purchase Order-Payable Voucher').dt_map('Purchase Order', 'Payable Voucher', self.doc.purchase_order_main, self.doc, self.doclist, "[['Purchase Order', 'Payable Voucher'],['PO Detail', 'PV Detail']]") self.doclist = get_obj('DocType Mapper', 'Purchase Order-Payable Voucher').dt_map('Purchase Order', 'Payable Voucher', self.doc.purchase_order_main, self.doc, self.doclist, "[['Purchase Order', 'Payable Voucher'],['PO Detail', 'PV Detail']]")
ret = eval(self.get_credit_to()) ret = eval(self.get_credit_to())
#self.doc.supplier_name = ret['supplier_name'] #self.doc.supplier_name = ret['supplier_name']
#self.doc.supplier_address = ret['supplier_address'] #self.doc.supplier_address = ret['supplier_address']
#self.doc.cst_no =ret['cst_no'] #self.doc.cst_no =ret['cst_no']
#self.doc.bst_no = ret['bst_no'] #self.doc.bst_no = ret['bst_no']
#self.doc.vat_tin_no = ret['vat_tin_no'] #self.doc.vat_tin_no = ret['vat_tin_no']
if ret.has_key('credit_to'): if ret.has_key('credit_to'):
self.doc.credit_to = ret['credit_to'] self.doc.credit_to = ret['credit_to']
# Get Item Details # Get Item Details
# ----------------- # -----------------
def get_item_details(self,arg): def get_item_details(self,arg):
item_det = sql("select item_name, brand, description, item_group,purchase_account,cost_center from tabItem where name=%s",arg,as_dict=1) item_det = sql("select item_name, brand, description, item_group,purchase_account,cost_center from tabItem where name=%s",arg,as_dict=1)
tax = sql("select tax_type, tax_rate from `tabItem Tax` where parent = %s" , arg) tax = sql("select tax_type, tax_rate from `tabItem Tax` where parent = %s" , arg)
t = {} t = {}
for x in tax: t[x[0]] = flt(x[1]) for x in tax: t[x[0]] = flt(x[1])
ret = { ret = {
'item_name' : item_det and item_det[0]['item_name'] or '', 'item_name' : item_det and item_det[0]['item_name'] or '',
'brand' : item_det and item_det[0]['brand'] or '', 'brand' : item_det and item_det[0]['brand'] or '',
'description' : item_det and item_det[0]['description'] or '', 'description' : item_det and item_det[0]['description'] or '',
'item_group' : item_det and item_det[0]['item_group'] or '', 'item_group' : item_det and item_det[0]['item_group'] or '',
'rate' : 0.00, 'rate' : 0.00,
'qty' : 0.00, 'qty' : 0.00,
'amount' : 0.00, 'amount' : 0.00,
'expense_head' : item_det and item_det[0]['purchase_account'] or '', 'expense_head' : item_det and item_det[0]['purchase_account'] or '',
'cost_center' : item_det and item_det[0]['cost_center'] or '', 'cost_center' : item_det and item_det[0]['cost_center'] or '',
'item_tax_rate' : str(t) 'item_tax_rate' : str(t)
} }
return cstr(ret) return cstr(ret)
# Advance Allocation # Advance Allocation
# ------------------- # -------------------
def get_advances(self): def get_advances(self):
get_obj('GL Control').get_advances( self, self.doc.credit_to, 'Advance Allocation Detail','advance_allocation_details','debit') get_obj('GL Control').get_advances( self, self.doc.credit_to, 'Advance Allocation Detail','advance_allocation_details','debit')
# ============= OTHER CHARGES ==================== # ============= OTHER CHARGES ====================
# Get Tax rate if account type is TAX # Get Tax rate if account type is TAX
# ------------------------------------ # ------------------------------------
def get_rate(self,arg): def get_rate(self,arg):
return get_obj('Purchase Common').get_rate(arg,self) return get_obj('Purchase Common').get_rate(arg,self)
# Pull details from other charges master (Get Other Charges) # Pull details from other charges master (Get Other Charges)
# ----------------------------------------------------------- # -----------------------------------------------------------
def get_purchase_tax_details(self): def get_purchase_tax_details(self):
return get_obj('Purchase Common').get_purchase_tax_details(self) return get_obj('Purchase Common').get_purchase_tax_details(self)
def get_rate1(self,acc): def get_rate1(self,acc):
rate = sql("select tax_rate from `tabAccount` where name='%s'"%(acc)) rate = sql("select tax_rate from `tabAccount` where name='%s'"%(acc))
ret={'add_tax_rate' :rate and flt(rate[0][0]) or 0 } ret={'add_tax_rate' :rate and flt(rate[0][0]) or 0 }
return cstr(ret) return cstr(ret)
# *************************** Server Utility Functions ***************************** # *************************** Server Utility Functions *****************************
# Get Company abbr # Get Company abbr
# ----------------- # -----------------
def get_company_abbr(self): def get_company_abbr(self):
return sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0] return sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
# Check whether PO or PR is already fetched # Check whether PO or PR is already fetched
# ------------------------------------------ # ------------------------------------------
def validate_duplicate_docname(self,doctype): def validate_duplicate_docname(self,doctype):
for d in getlist(self.doclist, 'entries'): for d in getlist(self.doclist, 'entries'):
if doctype == 'purchase_receipt' and cstr(self.doc.purchase_receipt_main) == cstr(d.purchase_receipt): if doctype == 'purchase_receipt' and cstr(self.doc.purchase_receipt_main) == cstr(d.purchase_receipt):
msgprint(cstr(self.doc.purchase_receipt_main) + " purchase receipt details have already been pulled.") msgprint(cstr(self.doc.purchase_receipt_main) + " purchase receipt details have already been pulled.")
raise Exception , " Validation Error. " raise Exception , " Validation Error. "
if doctype == 'purchase_order' and cstr(self.doc.purchase_order_main) == cstr(d.purchase_order) and not d.purchase_receipt: if doctype == 'purchase_order' and cstr(self.doc.purchase_order_main) == cstr(d.purchase_order) and not d.purchase_receipt:
msgprint(cstr(self.doc.purchase_order_main) + " purchase order details have already been pulled.") msgprint(cstr(self.doc.purchase_order_main) + " purchase order details have already been pulled.")
raise Exception , " Validation Error. " raise Exception , " Validation Error. "
# **************************** VALIDATE ******************************** # **************************** VALIDATE ********************************
# Check for Item.is_Purchase_item = 'Yes' and Item is active # Check for Item.is_Purchase_item = 'Yes' and Item is active
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def check_active_purchase_items(self): def check_active_purchase_items(self):
for d in getlist(self.doclist, 'entries'): for d in getlist(self.doclist, 'entries'):
if d.item_code: # extra condn coz item_code is not mandatory in PV if d.item_code: # extra condn coz item_code is not mandatory in PV
valid_item = sql("select docstatus,is_purchase_item from tabItem where name = %s",d.item_code) valid_item = sql("select docstatus,is_purchase_item from tabItem where name = %s",d.item_code)
if valid_item[0][0] == 2: if valid_item[0][0] == 2:
msgprint("Item : '%s' is Inactive, you can restore it from Trash" %(d.item_code)) msgprint("Item : '%s' is Inactive, you can restore it from Trash" %(d.item_code))
raise Exception raise Exception
if not valid_item[0][1] == 'Yes': if not valid_item[0][1] == 'Yes':
msgprint("Item : '%s' is not Purchase Item"%(d.item_code)) msgprint("Item : '%s' is not Purchase Item"%(d.item_code))
raise Exception raise Exception
# Check Conversion Rate # Check Conversion Rate
# ---------------------- # ----------------------
def check_conversion_rate(self): def check_conversion_rate(self):
default_currency = get_obj('Manage Account').doc.default_currency default_currency = TransactionBase().get_company_currency(self.doc.company)
if not default_currency: if not default_currency:
msgprint('Message: Please enter default currency in Manage Account') msgprint('Message: Please enter default currency in Company Master')
raise Exception raise Exception
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): 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.") msgprint("Message: Please Enter Appropriate Conversion Rate.")
raise Exception raise Exception
# 1. Check whether bill is already booked against this bill no. or not # 1. Check whether bill is already booked against this bill no. or not
# 2. Add Remarks # 2. Add Remarks
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
def validate_bill_no(self): def validate_bill_no(self):
if self.doc.bill_no and self.doc.bill_no.lower().strip() not in ['na', 'not applicable', 'none']: 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 `tabPayable Voucher` 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)) b_no = sql("select bill_no, name, ifnull(is_opening,'') from `tabPayable Voucher` 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))
if b_no and cstr(b_no[0][2]) == cstr(self.doc.is_opening): if b_no and cstr(b_no[0][2]) == cstr(self.doc.is_opening):
msgprint("Please check you have already booked expense against Bill No. %s in Purchase Invoice %s" % (cstr(b_no[0][0]), cstr(b_no[0][1]))) msgprint("Please check you have already booked expense against Bill No. %s in Purchase Invoice %s" % (cstr(b_no[0][0]), cstr(b_no[0][1])))
raise Exception , "Validation Error" raise Exception , "Validation Error"
if not self.doc.remarks: if not self.doc.remarks:
self.doc.remarks = (self.doc.remarks or '') + "\n" + ("Against Bill %s dated %s" % (self.doc.bill_no, formatdate(self.doc.bill_date))) self.doc.remarks = (self.doc.remarks or '') + "\n" + ("Against Bill %s dated %s" % (self.doc.bill_no, formatdate(self.doc.bill_date)))
if self.doc.ded_amount: if self.doc.ded_amount:
self.doc.remarks = (self.doc.remarks or '') + "\n" + ("Grand Total: %s, Tax Deduction Amount: %s" %(self.doc.grand_total, self.doc.ded_amount)) self.doc.remarks = (self.doc.remarks or '') + "\n" + ("Grand Total: %s, Tax Deduction Amount: %s" %(self.doc.grand_total, self.doc.ded_amount))
else: else:
if not self.doc.remarks: if not self.doc.remarks:
self.doc.remarks = "No Remarks" self.doc.remarks = "No Remarks"
# Validate Bill No Date # Validate Bill No Date
# --------------------- # ---------------------
def validate_bill_no_date(self): 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']: 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") msgprint("Please enter Bill Date")
raise Exception raise Exception
# Clear Advances # Clear Advances
# --------------- # ---------------
def clear_advances(self): def clear_advances(self):
get_obj('GL Control').clear_advances( self, 'Advance Allocation Detail','advance_allocation_details') get_obj('GL Control').clear_advances( self, 'Advance Allocation Detail','advance_allocation_details')
# 1. Credit To Account Exists # 1. Credit To Account Exists
# 2. Is a Credit Account # 2. Is a Credit Account
# 3. Is not a PL Account # 3. Is not a PL Account
# ---------------------------- # ----------------------------
def validate_credit_acc(self): def validate_credit_acc(self):
acc = sql("select debit_or_credit, is_pl_account from tabAccount where name = '%s'" % self.doc.credit_to) acc = sql("select debit_or_credit, is_pl_account from tabAccount where name = '%s'" % self.doc.credit_to)
if not acc: if not acc:
msgprint("Account: "+ self.doc.credit_to + "does not exist") msgprint("Account: "+ self.doc.credit_to + "does not exist")
raise Exception raise Exception
elif acc[0][0] and acc[0][0] != 'Credit': elif acc[0][0] and acc[0][0] != 'Credit':
msgprint("Account: "+ self.doc.credit_to + "is not a credit account") msgprint("Account: "+ self.doc.credit_to + "is not a credit account")
raise Exception raise Exception
elif acc[0][1] and acc[0][1] != 'No': elif acc[0][1] and acc[0][1] != 'No':
msgprint("Account: "+ self.doc.credit_to + "is a pl account") msgprint("Account: "+ self.doc.credit_to + "is a pl account")
raise Exception raise Exception
# Validate Acc Head of Supplier and Credit To Account entered # Validate Acc Head of Supplier and Credit To Account entered
# ------------------------------------------------------------ # ------------------------------------------------------------
def check_for_acc_head_of_supplier(self): def check_for_acc_head_of_supplier(self):
acc_head = sql("select name from `tabAccount` where name = %s", (cstr(self.doc.supplier) + " - " + self.get_company_abbr())) acc_head = sql("select name from `tabAccount` where name = %s", (cstr(self.doc.supplier) + " - " + self.get_company_abbr()))
if self.doc.supplier: if self.doc.supplier:
if acc_head and acc_head[0][0]: if acc_head and acc_head[0][0]:
if not cstr(acc_head[0][0]) == cstr(self.doc.credit_to): if not cstr(acc_head[0][0]) == cstr(self.doc.credit_to):
msgprint("Credit To: %s do not match with Supplier: %s for Company: %s i.e. %s" %(self.doc.credit_to,self.doc.supplier,self.doc.company,cstr(acc_head[0][0]))) msgprint("Credit To: %s do not match with Supplier: %s for Company: %s i.e. %s" %(self.doc.credit_to,self.doc.supplier,self.doc.company,cstr(acc_head[0][0])))
raise Exception, "Validation Error " raise Exception, "Validation Error "
if not acc_head: if not acc_head:
msgprint("Supplier %s does not have an Account Head in %s. You must first create it from the Supplier Master" % (self.doc.supplier, self.doc.company)) msgprint("Supplier %s does not have an Account Head in %s. You must first create it from the Supplier Master" % (self.doc.supplier, self.doc.company))
raise Exception, "Validation Error " raise Exception, "Validation Error "
# Check for Stopped PO # Check for Stopped PO
# --------------------- # ---------------------
def check_for_stopped_status(self): def check_for_stopped_status(self):
check_list = [] check_list = []
for d in getlist(self.doclist,'entries'): for d in getlist(self.doclist,'entries'):
if d.purchase_order and not d.purchase_order in check_list and not d.purchase_receipt: if d.purchase_order and not d.purchase_order in check_list and not d.purchase_receipt:
check_list.append(d.purhcase_order) check_list.append(d.purhcase_order)
stopped = sql("select name from `tabPurchase Order` where status = 'Stopped' and name = '%s'" % d.purchase_order) stopped = sql("select name from `tabPurchase Order` where status = 'Stopped' and name = '%s'" % d.purchase_order)
if stopped: if stopped:
msgprint("One cannot do any transaction against 'Purchase Order' : %s, it's status is 'Stopped'" % (d.purhcase_order)) msgprint("One cannot do any transaction against 'Purchase Order' : %s, it's status is 'Stopped'" % (d.purhcase_order))
raise Exception raise Exception
# Validate Supplier # Validate Supplier
# ----------------- # -----------------
def validate_supplier(self, d): def validate_supplier(self, d):
supplier = '' supplier = ''
if d.purchase_order and not d.purchase_order in self.po_list: 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] supplier = sql("select supplier from `tabPurchase Order` where name = '%s'" % d.purchase_order)[0][0]
doctype = 'purchase order' doctype = 'purchase order'
doctype_no = cstr(d.purchase_order) doctype_no = cstr(d.purchase_order)
if supplier and not cstr(self.doc.supplier) == cstr(supplier): 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,doctype,doctype_no)) msgprint("Supplier name %s do not match with supplier name of %s %s." %(self.doc.supplier,doctype,doctype_no))
raise Exception , " Validation Error " raise Exception , " Validation Error "
if d.purchase_receipt and not d.purchase_receipt in self.pr_list: 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] supplier = sql("select supplier from `tabPurchase Receipt` where name = '%s'" % d.purchase_receipt)[0][0]
doctype = 'purchase receipt' doctype = 'purchase receipt'
doctype_no = cstr(d.purchase_receipt) doctype_no = cstr(d.purchase_receipt)
if supplier and not cstr(self.doc.supplier) == cstr(supplier): 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,doctype,doctype_no)) msgprint("Supplier name %s do not match with supplier name of %s %s." %(self.doc.supplier,doctype,doctype_no))
raise Exception , " Validation Error " raise Exception , " Validation Error "
# Validate values with reference document # Validate values with reference document
#---------------------------------------- #----------------------------------------
def validate_reference_value(self): def validate_reference_value(self):
get_obj('DocType Mapper', 'Purchase Order-Payable Voucher', with_children = 1).validate_reference_value(self, self.doc.name) get_obj('DocType Mapper', 'Purchase Order-Payable Voucher', with_children = 1).validate_reference_value(self, self.doc.name)
# Validate PO and PR # Validate PO and PR
# ------------------- # -------------------
def validate_po_pr(self, d): def validate_po_pr(self, d):
# check po / pr for qty and rates and currency and conversion rate # check po / pr for qty and rates and currency and conversion rate
# always import_rate must be equal to import_rate of purchase order # always import_rate must be equal to import_rate of purchase order
if d.purchase_order and not d.purchase_order in self.po_list: if d.purchase_order and not d.purchase_order in self.po_list:
# currency # currency
currency = cstr(sql("select currency from `tabPurchase Order` where name = '%s'" % d.purchase_order)[0][0]) currency = cstr(sql("select currency from `tabPurchase Order` where name = '%s'" % d.purchase_order)[0][0])
if not cstr(currency) == cstr(self.doc.currency): 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.") msgprint("Purchase Order: " + cstr(d.purchase_order) + " currency : " + cstr(currency) + " does not match with currency of current document.")
raise Exception raise Exception
# import_rate # import_rate
rate = flt(sql('select import_rate from `tabPO Detail` where item_code=%s and parent=%s and name = %s', (d.item_code, d.purchase_order, d.po_detail))[0][0]) rate = flt(sql('select import_rate from `tabPO Detail` 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: if abs(rate - flt(d.import_rate)) > 1:
msgprint("Import Rate for %s in the Purchase Order is %s. Rate must be same as Purchase Order Rate" % (d.item_code,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 raise Exception
if d.purchase_receipt and not d.purchase_receipt in self.pr_list: if d.purchase_receipt and not d.purchase_receipt in self.pr_list:
# currency , conversion_rate # currency , conversion_rate
data = sql("select currency, conversion_rate from `tabPurchase Receipt` where name = '%s'" % d.purchase_receipt, as_dict = 1) 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): 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.") msgprint("Purchase Receipt: " + cstr(d.purchase_receipt) + " currency : " + cstr(data[0]['currency']) + " does not match with currency of current document.")
raise Exception raise Exception
if not flt(data[0]['conversion_rate']) == flt(self.doc.conversion_rate): if not flt(data[0]['conversion_rate']) == flt(self.doc.conversion_rate):
msgprint("Purchase Receipt: " + cstr(d.purchase_receipt) + " conversion_rate : " + cstr(data[0]['conversion_rate']) + " does not match with conversion_rate of current document.") msgprint("Purchase Receipt: " + cstr(d.purchase_receipt) + " conversion_rate : " + cstr(data[0]['conversion_rate']) + " does not match with conversion_rate of current document.")
raise Exception raise Exception
# Build tds table if applicable # Build tds table if applicable
#------------------------------ #------------------------------
def get_tds(self): def get_tds(self):
if cstr(self.doc.is_opening) != 'Yes': if cstr(self.doc.is_opening) != 'Yes':
if not self.doc.credit_to: if not self.doc.credit_to:
msgprint("Please Enter Credit To account first") msgprint("Please Enter Credit To account first")
raise Exception raise Exception
else: else:
tds_applicable = sql("select tds_applicable from tabAccount where name = '%s'" % self.doc.credit_to) tds_applicable = sql("select tds_applicable from tabAccount where name = '%s'" % self.doc.credit_to)
if tds_applicable and cstr(tds_applicable[0][0]) == 'Yes': if tds_applicable and cstr(tds_applicable[0][0]) == 'Yes':
if not self.doc.tds_applicable: if not self.doc.tds_applicable:
msgprint("Please enter whether TDS Applicable or not") msgprint("Please enter whether TDS Applicable or not")
raise Exception raise Exception
if self.doc.tds_applicable == 'Yes': if self.doc.tds_applicable == 'Yes':
if not self.doc.tds_category: if not self.doc.tds_category:
msgprint("Please select TDS Category") msgprint("Please select TDS Category")
raise Exception raise Exception
else: else:
get_obj('TDS Control').get_tds_amount(self) get_obj('TDS Control').get_tds_amount(self)
self.doc.total_tds_on_voucher = self.doc.ded_amount self.doc.total_tds_on_voucher = self.doc.ded_amount
self.doc.total_amount_to_pay=flt(self.doc.grand_total)-flt(self.doc.ded_amount)-flt(self.doc.other_tax_deducted) self.doc.total_amount_to_pay=flt(self.doc.grand_total)-flt(self.doc.ded_amount)-flt(self.doc.other_tax_deducted)
elif self.doc.tds_applicable == 'No': elif self.doc.tds_applicable == 'No':
self.doc.tds_category = '' self.doc.tds_category = ''
self.doc.tax_code = '' self.doc.tax_code = ''
self.doc.rate = 0 self.doc.rate = 0
self.doc.ded_amount = 0 self.doc.ded_amount = 0
self.doc.total_tds_on_voucher = 0 self.doc.total_tds_on_voucher = 0
# get tds rate # get tds rate
# ------------- # -------------
def get_tds_rate(self): def get_tds_rate(self):
return str({'rate' : flt(get_value('Account', self.doc.tax_code, 'tax_rate'))}) return str({'rate' : flt(get_value('Account', self.doc.tax_code, 'tax_rate'))})
# set aging date # set aging date
#------------------- #-------------------
def set_aging_date(self): def set_aging_date(self):
if self.doc.is_opening != 'Yes': if self.doc.is_opening != 'Yes':
self.doc.aging_date = self.doc.posting_date self.doc.aging_date = self.doc.posting_date
elif not self.doc.aging_date: elif not self.doc.aging_date:
msgprint("Aging Date is mandatory for opening entry") msgprint("Aging Date is mandatory for opening entry")
raise Exception raise Exception
# Set against account for debit to account # Set against account for debit to account
#------------------------------------------ #------------------------------------------
def set_against_expense_account(self): def set_against_expense_account(self):
against_acc = [] against_acc = []
for d in getlist(self.doclist, 'entries'): for d in getlist(self.doclist, 'entries'):
if d.expense_account not in against_acc: if d.expense_account not in against_acc:
against_acc.append(d.expense_account) against_acc.append(d.expense_account)
self.doc.against_expense_account = ','.join(against_acc) self.doc.against_expense_account = ','.join(against_acc)
#check in manage account if purchase order required or not. #check in manage account if purchase order required or not.
# ==================================================================================== # ====================================================================================
def po_required(self): def po_required(self):
res = sql("select value from `tabSingles` where doctype = 'Manage Account' and field = 'po_required'") res = sql("select value from `tabSingles` where doctype = 'Manage Account' and field = 'po_required'")
if res and res[0][0] == 'Yes': if res and res[0][0] == 'Yes':
for d in getlist(self.doclist,'entries'): for d in getlist(self.doclist,'entries'):
if not d.purchase_order: if not d.purchase_order:
msgprint("Purchse Order No. required against item %s"%d.item_code) msgprint("Purchse Order No. required against item %s"%d.item_code)
raise Exception raise Exception
#check in manage account if purchase receipt required or not. #check in manage account if purchase receipt required or not.
# ==================================================================================== # ====================================================================================
def pr_required(self): def pr_required(self):
res = sql("select value from `tabSingles` where doctype = 'Manage Account' and field = 'pr_required'") res = sql("select value from `tabSingles` where doctype = 'Manage Account' and field = 'pr_required'")
if res and res[0][0] == 'Yes': if res and res[0][0] == 'Yes':
for d in getlist(self.doclist,'entries'): for d in getlist(self.doclist,'entries'):
if not d.purchase_receipt: if not d.purchase_receipt:
msgprint("Purchase Receipt No. required against item %s"%d.item_code) msgprint("Purchase Receipt No. required against item %s"%d.item_code)
raise Exception raise Exception
# VALIDATE # VALIDATE
# ==================================================================================== # ====================================================================================
def validate(self): def validate(self):
self.po_required() self.po_required()
self.pr_required() self.pr_required()
self.check_active_purchase_items() self.check_active_purchase_items()
self.check_conversion_rate() self.check_conversion_rate()
self.validate_bill_no_date() self.validate_bill_no_date()
self.validate_bill_no() self.validate_bill_no()
self.validate_reference_value() self.validate_reference_value()
self.clear_advances() self.clear_advances()
self.validate_credit_acc() self.validate_credit_acc()
self.check_for_acc_head_of_supplier() self.check_for_acc_head_of_supplier()
self.check_for_stopped_status() self.check_for_stopped_status()
self.po_list, self.pr_list = [], [] self.po_list, self.pr_list = [], []
for d in getlist(self.doclist, 'entries'): for d in getlist(self.doclist, 'entries'):
self.validate_supplier(d) self.validate_supplier(d)
self.validate_po_pr(d) self.validate_po_pr(d)
if not d.purchase_order in self.po_list: if not d.purchase_order in self.po_list:
self.po_list.append(d.purchase_order) self.po_list.append(d.purchase_order)
if not d.purhcase_receipt in self.pr_list: if not d.purhcase_receipt in self.pr_list:
self.pr_list.append(d.purchase_receipt) self.pr_list.append(d.purchase_receipt)
# tds # tds
get_obj('TDS Control').validate_first_entry(self) get_obj('TDS Control').validate_first_entry(self)
if not flt(self.doc.ded_amount): if not flt(self.doc.ded_amount):
self.get_tds() self.get_tds()
self.doc.save() self.doc.save()
if not self.doc.is_opening: if not self.doc.is_opening:
self.doc.is_opening = 'No' self.doc.is_opening = 'No'
self.set_aging_date() self.set_aging_date()
#set against account for credit to #set against account for credit to
self.set_against_expense_account() self.set_against_expense_account()
#FY validation #FY validation
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Posting Date') get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Posting Date')
#get Purchase Common Obj #get Purchase Common Obj
pc_obj = get_obj(dt='Purchase Common') pc_obj = get_obj(dt='Purchase Common')
# get total in words # get total in words
self.doc.in_words = pc_obj.get_total_in_words('Rs', self.doc.grand_total) self.doc.in_words = pc_obj.get_total_in_words('Rs', self.doc.grand_total)
self.doc.in_words_import = pc_obj.get_total_in_words(self.doc.currency, self.doc.grand_total_import) self.doc.in_words_import = pc_obj.get_total_in_words(self.doc.currency, self.doc.grand_total_import)
# ***************************** SUBMIT ***************************** # ***************************** SUBMIT *****************************
# Check Ref Document docstatus # Check Ref Document docstatus
# ----------------------------- # -----------------------------
def check_prev_docstatus(self): def check_prev_docstatus(self):
for d in getlist(self.doclist,'entries'): for d in getlist(self.doclist,'entries'):
if d.purchase_order: if d.purchase_order:
submitted = sql("select name from `tabPurchase Order` where docstatus = 1 and name = '%s'" % d.purchase_order) submitted = sql("select name from `tabPurchase Order` where docstatus = 1 and name = '%s'" % d.purchase_order)
if not submitted: if not submitted:
msgprint("Purchase Order : "+ cstr(d.purchase_order) +" is not submitted") msgprint("Purchase Order : "+ cstr(d.purchase_order) +" is not submitted")
raise Exception , "Validation Error." raise Exception , "Validation Error."
if d.purchase_receipt: if d.purchase_receipt:
submitted = sql("select name from `tabPurchase Receipt` where docstatus = 1 and name = '%s'" % d.purchase_receipt) submitted = sql("select name from `tabPurchase Receipt` where docstatus = 1 and name = '%s'" % d.purchase_receipt)
if not submitted: if not submitted:
msgprint("Purchase Receipt : "+ cstr(d.purchase_receipt) +" is not submitted") msgprint("Purchase Receipt : "+ cstr(d.purchase_receipt) +" is not submitted")
raise Exception , "Validation Error." raise Exception , "Validation Error."
def update_against_document_in_jv(self, against_document_no, against_document_doctype): def update_against_document_in_jv(self, against_document_no, against_document_doctype):
get_obj('GL Control').update_against_document_in_jv( self,'advance_allocation_details', against_document_no, against_document_doctype, self.doc.credit_to, 'debit',self.doc.doctype) get_obj('GL Control').update_against_document_in_jv( self,'advance_allocation_details', against_document_no, against_document_doctype, self.doc.credit_to, 'debit',self.doc.doctype)
# On Submit # On Submit
# ---------- # ----------
def on_submit(self): def on_submit(self):
self.check_prev_docstatus() self.check_prev_docstatus()
# Check for Approving Authority # Check for Approving Authority
get_obj('Authorization Control').validate_approving_authority(self.doc.doctype,self.doc.company, self.doc.grand_total) get_obj('Authorization Control').validate_approving_authority(self.doc.doctype,self.doc.company, self.doc.grand_total)
# this sequence because outstanding may get -negative # this sequence because outstanding may get -negative
get_obj(dt='GL Control').make_gl_entries(self.doc, self.doclist) get_obj(dt='GL Control').make_gl_entries(self.doc, self.doclist)
self.update_against_document_in_jv(self.doc.name, self.doc.doctype) self.update_against_document_in_jv(self.doc.name, self.doc.doctype)
get_obj(dt = 'Purchase Common').update_prevdoc_detail(self, is_submit = 1) get_obj(dt = 'Purchase Common').update_prevdoc_detail(self, is_submit = 1)
# ********************************* CANCEL ********************************* # ********************************* CANCEL *********************************
# Check Next Document's docstatus # Check Next Document's docstatus
# -------------------------------- # --------------------------------
def check_next_docstatus(self): def check_next_docstatus(self):
submit_jv = sql("select t1.name from `tabJournal Voucher` t1,`tabJournal Voucher Detail` t2 where t1.name = t2.parent and t2.against_voucher = '%s' and t1.docstatus = 1" % (self.doc.name)) submit_jv = sql("select t1.name from `tabJournal Voucher` t1,`tabJournal Voucher Detail` t2 where t1.name = t2.parent and t2.against_voucher = '%s' and t1.docstatus = 1" % (self.doc.name))
if submit_jv: if submit_jv:
msgprint("Journal Voucher : " + cstr(submit_jv[0][0]) + " has been created against " + cstr(self.doc.doctype) + ". So " + cstr(self.doc.doctype) + " cannot be Cancelled.") msgprint("Journal Voucher : " + cstr(submit_jv[0][0]) + " has been created against " + cstr(self.doc.doctype) + ". So " + cstr(self.doc.doctype) + " cannot be Cancelled.")
raise Exception, "Validation Error." raise Exception, "Validation Error."
# On Cancel # On Cancel
# ---------- # ----------
def on_cancel(self): def on_cancel(self):
self.check_next_docstatus() self.check_next_docstatus()
# Check whether tds payment voucher has been created against this voucher # Check whether tds payment voucher has been created against this voucher
self.check_tds_payment_voucher() self.check_tds_payment_voucher()
get_obj(dt='GL Control').make_gl_entries(self.doc, self.doclist, cancel=1) get_obj(dt='GL Control').make_gl_entries(self.doc, self.doclist, cancel=1)
get_obj(dt = 'Purchase Common').update_prevdoc_detail(self, is_submit = 0) get_obj(dt = 'Purchase Common').update_prevdoc_detail(self, is_submit = 0)
# Check whether tds payment voucher has been created against this voucher # Check whether tds payment voucher has been created against this voucher
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
def check_tds_payment_voucher(self): def check_tds_payment_voucher(self):
tdsp = sql("select parent from `tabTDS Payment Detail` where voucher_no = '%s' and docstatus = 1 and parent not like 'old%'") tdsp = sql("select parent from `tabTDS Payment Detail` where voucher_no = '%s' and docstatus = 1 and parent not like 'old%'")
if tdsp: if tdsp:
msgprint("TDS Payment voucher '%s' has been made against this voucher. Please cancel the payment voucher to proceed." % (tdsp and tdsp[0][0] or '')) msgprint("TDS Payment voucher '%s' has been made against this voucher. Please cancel the payment voucher to proceed." % (tdsp and tdsp[0][0] or ''))
raise Exception raise Exception
# on update # on update
def on_update(self): def on_update(self):
pass pass
######################################################################## ########################################################################
# Repair Outstanding # Repair Outstanding
####################################################################### #######################################################################
def repair_pv_outstanding(self): def repair_pv_outstanding(self):
get_obj(dt = 'GL Control').repair_voucher_outstanding(self) get_obj(dt = 'GL Control').repair_voucher_outstanding(self)

View File

@ -15,9 +15,9 @@ in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists convert_to_lists = webnotes.conn.convert_to_lists
# ----------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------
from utilities.transaction_base import TransactionBase
class DocType(TransactionBase):
class DocType:
def __init__(self, doc, doclist=[]): def __init__(self, doc, doclist=[]):
self.doc = doc self.doc = doc
self.doclist = doclist self.doclist = doclist
@ -268,14 +268,11 @@ class DocType:
# validate conversion rate # validate conversion rate
def validate_conversion_rate(self, obj): def validate_conversion_rate(self, obj):
default_currency = get_obj('Manage Account').doc.default_currency default_currency = TransactionBase().get_company_currency(obj.doc.company)
if not default_currency: if not default_currency:
msgprint('Message: Please enter default currency in Global Defaults') msgprint('Message: Please enter default currency in Company Master')
raise Exception raise Exception
if (obj.doc.currency == default_currency and flt(obj.doc.conversion_rate) != 1.00) or not obj.doc.conversion_rate or (obj.doc.currency != default_currency and flt(obj.doc.conversion_rate) == 1.00):
company_currency = sql("select default_currency from `tabCompany` where name = '%s'" % obj.doc.company)
curr = company_currency and cstr(company_currency[0][0]) or default_currency
if (obj.doc.currency == curr and flt(obj.doc.conversion_rate) != 1.00) or not obj.doc.conversion_rate or (obj.doc.currency != curr and flt(obj.doc.conversion_rate) == 1.00):
msgprint("Message: Please Enter Appropriate Conversion Rate.") msgprint("Message: Please Enter Appropriate Conversion Rate.")
raise Exception raise Exception

View File

@ -15,8 +15,9 @@ convert_to_lists = webnotes.conn.convert_to_lists
# ----------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------
from utilities.transaction_base import TransactionBase
class DocType: class DocType(TransactionBase):
def __init__(self,d,dl): def __init__(self,d,dl):
self.doc, self.doclist = d,dl self.doc, self.doclist = d,dl
@ -262,10 +263,11 @@ class DocType:
# Check Conversion Rate (i.e. it will not allow conversion rate to be 1 for Currency other than default currency set in Global Defaults) # Check Conversion Rate (i.e. it will not allow conversion rate to be 1 for Currency other than default currency set in Global Defaults)
# =========================================================================== # ===========================================================================
def check_conversion_rate(self, obj): def check_conversion_rate(self, obj):
default_currency = get_obj('Manage Account').doc.default_currency default_currency = TransactionBase().get_company_currency(obj.doc.company)
company_currency = sql("select default_currency from `tabCompany` where name = '%s'" % obj.doc.company) if not default_currency:
curr = company_currency and cstr(company_currency[0][0]) or default_currency msgprint('Message: Please enter default currency in Company Master')
if (obj.doc.currency == curr and flt(obj.doc.conversion_rate) != 1.00) or not obj.doc.conversion_rate or (obj.doc.currency != curr and flt(obj.doc.conversion_rate) == 1.00): raise Exception
if (obj.doc.currency == default_currency and flt(obj.doc.conversion_rate) != 1.00) or not obj.doc.conversion_rate or (obj.doc.currency != default_currency and flt(obj.doc.conversion_rate) == 1.00):
msgprint("Please Enter Appropriate Conversion Rate.") msgprint("Please Enter Appropriate Conversion Rate.")
raise Exception raise Exception

View File

@ -140,7 +140,8 @@ class DocType(TransactionBase):
self.check_for_stopped_status(pc_obj) self.check_for_stopped_status(pc_obj)
# get total in words # get total in words
self.doc.in_words = pc_obj.get_total_in_words(get_defaults().get('currency') or 'INR', self.doc.grand_total) dcc = TransactionBase().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) self.doc.in_words_import = pc_obj.get_total_in_words(self.doc.currency, self.doc.grand_total_import)
# update valuation rate # update valuation rate
self.update_valuation_rate() self.update_valuation_rate()