def update_bin(self, is_submit, is_stopped = 0): pc_obj = get_obj('Purchase Common') for d in getlist(self.doclist, 'po_details'): #1. Check if is_stock_item == 'Yes' if sql("select is_stock_item from tabItem where name=%s", d.item_code)[0][0]=='Yes': ind_qty, po_qty = 0, flt(d.qty) * flt(d.conversion_factor) if is_stopped: po_qty = flt(d.qty) > flt(d.received_qty) and flt( flt(flt(d.qty) - flt(d.received_qty)) * flt(d.conversion_factor))or 0 # No updates in Indent on Stop / Unstop if cstr(d.prevdoc_doctype) == 'Indent' and not is_stopped: # get qty and pending_qty of prevdoc curr_ref_qty = pc_obj.get_qty( d.doctype, 'prevdoc_detail_docname', d.prevdoc_detail_docname, 'Indent Detail', 'Indent - Purchase Order', self.doc.name) max_qty, qty, curr_qty = flt(curr_ref_qty.split('~~~')[1]), flt(curr_ref_qty.split('~~~')[0]), 0 if flt(qty) + flt(po_qty) > flt(max_qty): curr_qty = flt(max_qty) - flt(qty) # special case as there is no restriction for Indent - Purchase Order curr_qty = (curr_qty > 0) and curr_qty or 0 else: curr_qty = flt(po_qty) ind_qty = -flt(curr_qty) #==> Update Bin's Indent Qty by +- ind_qty and Ordered Qty by +- qty get_obj('Warehouse', d.warehouse).update_bin(0, 0, (is_submit and 1 or -1) * flt(po_qty), (is_submit and 1 or -1) * flt(ind_qty), 0, d.item_code, self.doc.transaction_date)
def on_submit(self): if cint(self.doc.is_pos) == 1: if cint(self.doc.update_stock) == 1: sl_obj = get_obj("Stock Ledger") sl_obj.validate_serial_no_warehouse(self, 'entries') sl_obj.validate_serial_no_warehouse(self, 'packing_details') sl_obj.update_serial_record(self, 'entries', is_submit = 1, is_incoming = 0) sl_obj.update_serial_record(self, 'packing_details', is_submit = 1, is_incoming = 0) self.update_stock_ledger(update_stock=1) else: # Check for Approving Authority if not self.doc.recurring_id: get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total, self) self.check_prev_docstatus() get_obj("Sales Common").update_prevdoc_detail(1,self) # this sequence because outstanding may get -ve self.make_gl_entries() if not cint(self.doc.is_pos) == 1: self.update_against_document_in_jv() self.update_c_form() self.convert_to_recurring()
def update_against_document_in_jv(self): """ Links invoice and advance voucher: 1. cancel advance voucher 2. split into multiple rows if partially adjusted, assign against voucher 3. submit advance voucher """ lst = [] for d in getlist(self.doclist, 'advance_adjustment_details'): if flt(d.allocated_amount) > 0: args = { 'voucher_no' : d.journal_voucher, 'voucher_detail_no' : d.jv_detail_no, 'against_voucher_type' : 'Sales Invoice', 'against_voucher' : self.doc.name, 'account' : self.doc.debit_to, 'is_advance' : 'Yes', 'dr_or_cr' : 'credit', 'unadjusted_amt' : flt(d.advance_amount), 'allocated_amt' : flt(d.allocated_amount) } lst.append(args) if lst: get_obj('GL Control').reconcile_against_document(lst)
def make_single_entry(self,parent,d,le_map,cancel, merge_entries): if self.get_val(le_map['account'], d, parent) and \ (self.get_val(le_map['debit'], d, parent) \ or self.get_val(le_map['credit'], d, parent)): flist = ['account', 'cost_center', 'against', 'debit', 'credit', 'remarks', 'voucher_type', 'voucher_no', 'posting_date', 'fiscal_year', 'against_voucher', 'against_voucher_type', 'company', 'is_opening', 'aging_date'] # Check budget before gl entry #check budget only if account is expense account is_expense_acct = webnotes.conn.sql("""select name from tabAccount where is_pl_account='Yes' and debit_or_credit='Debit' and name=%s""",self.get_val(le_map['account'], d, parent)) if is_expense_acct and self.get_val(le_map['cost_center'], d, parent): get_obj('Budget Control').check_budget([self.get_val(le_map[k], d, parent) for k in flist if k in ['account', 'cost_center', 'debit', 'credit', 'posting_date', 'fiscal_year', 'company']],cancel) # Create new GL entry object and map values le = Document('GL Entry') for k in flist: le.fields[k] = self.get_val(le_map[k], d, parent) # if there is already an entry in this account then just add it to that entry same_head = self.check_if_in_list(le) if same_head and merge_entries: same_head = same_head[0] same_head.debit = flt(same_head.debit) + flt(le.debit) same_head.credit = flt(same_head.credit) + flt(le.credit) else: self.entries.append(le)
def validate(self): self.so_dn_required() self.validate_proj_cust() sales_com_obj = get_obj('Sales Common') sales_com_obj.check_stop_sales_order(self) sales_com_obj.check_active_sales_items(self) sales_com_obj.check_conversion_rate(self) sales_com_obj.validate_max_discount(self, 'entries') #verify whether rate is not greater than tolerance sales_com_obj.get_allocated_sum(self) # this is to verify that the allocated % of sales persons is 100% 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() self.add_remarks() if cint(self.doc.is_pos): self.validate_pos() self.validate_write_off_account() if cint(self.doc.update_stock): sl = get_obj('Stock Ledger') sl.validate_serial_no(self, 'entries') sl.validate_serial_no(self, 'packing_details') self.validate_item_code() self.update_current_stock() self.validate_delivery_note() self.set_in_words() if not self.doc.is_opening: self.doc.is_opening = 'No' self.set_aging_date() self.clear_advances() self.set_against_income_account() self.validate_c_form() self.validate_recurring_invoice()
def reconcile(self): """ Links booking and payment voucher 1. cancel payment voucher 2. split into multiple rows if partially adjusted, assign against voucher 3. submit payment voucher """ if not self.doc.voucher_no or not sql("select name from `tab%s` where name = %s" %(self.dt[self.doc.voucher_type], '%s'), self.doc.voucher_no): msgprint("Please select valid Voucher No to proceed", raise_exception=1) lst = [] for d in getlist(self.doclist, 'ir_payment_details'): if flt(d.amt_to_be_reconciled) > 0: args = { 'voucher_no' : d.voucher_no, 'voucher_detail_no' : d.voucher_detail_no, 'against_voucher_type' : self.dt[self.doc.voucher_type], 'against_voucher' : self.doc.voucher_no, 'account' : self.doc.account, 'is_advance' : 'No', 'dr_or_cr' : self.acc_type=='debit' and 'credit' or 'debit', 'unadjusted_amt' : flt(d.amt_due), 'allocated_amt' : flt(d.amt_to_be_reconciled) } lst.append(args) if lst: get_obj('GL Control').reconcile_against_document(lst) msgprint("Successfully allocated.") else: msgprint("No amount allocated.", raise_exception=1)
def on_submit(self): if cint(self.doc.update_stock) == 1: self.update_stock_ledger(update_stock=1) self.update_serial_nos() else: # Check for Approving Authority if not self.doc.recurring_id: get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total, self) self.set_buying_amount() self.check_prev_docstatus() self.update_status_updater_args() self.update_prevdoc_status() # this sequence because outstanding may get -ve self.make_gl_entries() if not cint(self.doc.is_pos) == 1: self.update_against_document_in_jv() self.update_c_form() self.update_time_log_batch(self.doc.name) self.convert_to_recurring()
def create_auto_indent(self, i , doc_type, doc_name, cur_qty): """ Create indent on reaching reorder level """ indent = Document('Purchase Request') indent.transaction_date = nowdate() indent.naming_series = 'IDT' indent.company = get_defaults()['company'] indent.fiscal_year = get_defaults()['fiscal_year'] indent.remark = "This is an auto generated Purchase Request. It was raised because the (actual + ordered + indented - reserved) quantity reaches re-order level when %s %s was created"%(doc_type,doc_name) indent.save(1) indent_obj = get_obj('Purchase Request',indent.name,with_children=1) indent_details_child = addchild(indent_obj.doc,'indent_details','Purchase Request Item',0) indent_details_child.item_code = self.doc.item_code indent_details_child.uom = self.doc.stock_uom indent_details_child.warehouse = self.doc.warehouse indent_details_child.schedule_date= add_days(nowdate(),cint(i['lead_time_days'])) indent_details_child.item_name = i['item_name'] indent_details_child.description = i['description'] indent_details_child.item_group = i['item_group'] indent_details_child.qty = i['re_order_qty'] or (flt(i['re_order_level']) - flt(cur_qty)) indent_details_child.brand = i['brand'] indent_details_child.save() indent_obj = get_obj('Purchase Request',indent.name,with_children=1) indent_obj.validate() set(indent_obj.doc,'docstatus',1) indent_obj.on_submit() msgprint("Item: " + self.doc.item_code + " is to be re-ordered. Purchase Request %s raised. It was generated from %s %s"%(indent.name,doc_type, doc_name )) if(i['email_notify']): send_email_notification(doc_type,doc_name)
def reconcile_against_document(self, args): """ Cancel JV, Update aginst document, split if required and resubmit jv """ for d in args: self.check_if_jv_modified(d) against_fld = { 'Journal Voucher' : 'against_jv', 'Sales Invoice' : 'against_invoice', 'Purchase Invoice' : 'against_voucher' } d['against_fld'] = against_fld[d['against_voucher_type']] # cancel JV jv_obj = get_obj('Journal Voucher', d['voucher_no'], with_children=1) self.make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel =1, adv_adj =1) # update ref in JV Detail self.update_against_doc(d, jv_obj) # re-submit JV jv_obj = get_obj('Journal Voucher', d['voucher_no'], with_children =1) self.make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel = 0, adv_adj =1)
def repost(): """ Repost everything! """ from webnotes.model.code import get_obj for wh in webnotes.conn.sql("select name from tabWarehouse"): get_obj('Warehouse', wh[0]).repost_stock()
def validate_reference_value(self, obj): ref_doc = [] for d in getlist(obj.doclist, obj.fname): if d.prevdoc_doctype and d.prevdoc_docname and d.prevdoc_doctype not in ref_doc: mapper_name = d.prevdoc_doctype + '-' + obj.doc.doctype get_obj('DocType Mapper', mapper_name, with_children = 1).validate_reference_value(obj, obj.doc.name) ref_doc.append(d.prevdoc_doctype)
def get_tds(self): if cstr(self.doc.is_opening) != 'Yes': if not self.doc.credit_to: msgprint("Please Enter Credit To account first") raise Exception else: 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 not self.doc.tds_applicable: msgprint("Please enter whether TDS Applicable or not") raise Exception if self.doc.tds_applicable == 'Yes': if not self.doc.tds_category: msgprint("Please select TDS Category") raise Exception else: get_obj('TDS Control').get_tds_amount(self) 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) - self.doc.write_off_amount self.doc.outstanding_amount = self.doc.total_amount_to_pay - flt(self.doc.total_advance) elif self.doc.tds_applicable == 'No': self.doc.tds_category = '' self.doc.tax_code = '' self.doc.rate = 0 self.doc.ded_amount = 0 self.doc.total_tds_on_voucher = 0
def pull_details(self): """Pull Details of Delivery Note or Sales Order Selected""" if self.doc.delivery_note_main: self.validate_prev_docname("delivery note") self.doclist = self.doc.clear_table(self.doclist, "other_charges") self.doclist = get_obj("DocType Mapper", "Delivery Note-Sales Invoice").dt_map( "Delivery Note", "Sales Invoice", self.doc.delivery_note_main, self.doc, self.doclist, """[['Delivery Note', 'Sales Invoice'], ['Delivery Note Item', 'Sales Invoice Item'], ['Sales Taxes and Charges','Sales Taxes and Charges'], ['Sales Team','Sales Team']]""", ) self.get_income_expense_account("entries") elif self.doc.sales_order_main: self.validate_prev_docname("sales order") self.doclist = self.doc.clear_table(self.doclist, "other_charges") get_obj("DocType Mapper", "Sales Order-Sales Invoice").dt_map( "Sales Order", "Sales Invoice", self.doc.sales_order_main, self.doc, self.doclist, """[['Sales Order', 'Sales Invoice'],['Sales Order Item', 'Sales Invoice Item'], ['Sales Taxes and Charges','Sales Taxes and Charges'], ['Sales Team', 'Sales Team']]""", ) self.get_income_expense_account("entries") ret = self.get_debit_to() self.doc.debit_to = ret.get("debit_to")
def stop_unstop(self, status): """ Called from client side on Stop/Unstop event""" self.update_status(status) # Update Planned Qty of Production Item qty = (flt(self.doc.qty) - flt(self.doc.produced_qty)) * ((status == 'Stopped') and -1 or 1) get_obj('Warehouse', self.doc.fg_warehouse).update_bin(0, 0, 0, 0, flt(qty), self.doc.production_item, now()) msgprint("Production Order has been %s" % status)
def validate(self): self.so_required() self.validate_fiscal_year() self.validate_proj_cust() sales_com_obj = get_obj(dt = 'Sales Common') sales_com_obj.check_stop_sales_order(self) sales_com_obj.check_active_sales_items(self) sales_com_obj.get_prevdoc_date(self) self.validate_mandatory() #self.validate_prevdoc_details() self.validate_reference_value() self.validate_for_items() sales_com_obj.make_packing_list(self,'delivery_note_details') get_obj('Stock Ledger').validate_serial_no(self, 'packing_details') sales_com_obj.validate_max_discount(self, 'delivery_note_details') #verify whether rate is not greater than max discount sales_com_obj.get_allocated_sum(self) # this is to verify that the allocated % of sales persons is 100% sales_com_obj.check_conversion_rate(self) # ::::::: Get total in Words :::::::: dcc = TransactionBase().get_company_currency(self.doc.company) self.doc.in_words = sales_com_obj.get_total_in_words(dcc, self.doc.rounded_total) self.doc.in_words_export = sales_com_obj.get_total_in_words(self.doc.currency, self.doc.rounded_total_export) # ::::::: Set Net Weight of each Packing self.update_pack_nett_weight() self.print_packing_slip() # ::::::: Set actual qty for each item in selected warehouse ::::::: self.update_current_stock() # :::::: set DN status ::::::: 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'
def on_cancel(self): pc_obj = get_obj('Purchase Common') self.check_for_stopped_status(pc_obj) # 1.Check if Purchase Invoice has been submitted against current Purchase Order # pc_obj.check_docstatus(check = 'Next', doctype = 'Purchase Invoice', docname = self.doc.name, detail_doctype = 'Purchase Invoice Item') submitted = sql("select t1.name from `tabPurchase Invoice` t1,`tabPurchase Invoice Item` t2 where t1.name = t2.parent and t2.purchase_receipt = '%s' and t1.docstatus = 1" % self.doc.name) if submitted: msgprint("Purchase Invoice : " + cstr(submitted[0][0]) + " has already been submitted !") raise Exception # 2.Set Status as Cancelled webnotes.conn.set(self.doc,'status','Cancelled') # 3. Cancel Serial No get_obj('Stock Ledger').update_serial_record(self, 'purchase_receipt_details', is_submit = 0, is_incoming = 1) # 4.Update Bin self.update_stock(is_submit = 0) # 5.Update Material Requests Pending Qty and accordingly it's Status pc_obj.update_prevdoc_detail(self, is_submit = 0) # 6. Update last purchase rate pc_obj.update_last_purchase_rate(self, 0) self.make_gl_entries()
def validate(self): super(DocType, self).validate() self.po_required() self.validate_fiscal_year() if not self.doc.status: self.doc.status = "Draft" import utilities utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Cancelled"]) self.validate_accepted_rejected_qty() self.validate_inspection() # Validate Inspection get_obj('Stock Ledger').validate_serial_no(self, 'purchase_receipt_details') self.validate_challan_no() 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 self.validate_for_subcontracting() self.update_raw_materials_supplied("pr_raw_material_details") self.update_valuation_rate("purchase_receipt_details")
def update_stock(self, is_submit): pc_obj = get_obj('Purchase Common') self.values = [] for d in getlist(self.doclist, 'purchase_receipt_details'): # Check if is_stock_item == 'Yes' if sql("select is_stock_item from tabItem where name=%s", d.item_code)[0][0]=='Yes': ord_qty = 0 pr_qty = flt(d.qty) * flt(d.conversion_factor) # Check If Prevdoc Doctype is Purchase Order if cstr(d.prevdoc_doctype) == 'Purchase Order': # get qty and pending_qty of prevdoc curr_ref_qty = pc_obj.get_qty( d.doctype, 'prevdoc_detail_docname', d.prevdoc_detail_docname, 'PO Detail', 'Purchase Order - Purchase Receipt', self.doc.name) max_qty, qty, curr_qty = flt(curr_ref_qty.split('~~~')[1]), flt(curr_ref_qty.split('~~~')[0]), 0 if flt(qty) + flt(pr_qty) > flt(max_qty): curr_qty = (flt(max_qty) - flt(qty)) * flt(d.conversion_factor) else: curr_qty = flt(pr_qty) ord_qty = -flt(curr_qty) # update order qty in bin bin = get_obj('Warehouse', d.warehouse).update_bin(0, 0, (is_submit and 1 or -1) * flt(ord_qty), 0, 0, d.item_code, self.doc.transaction_date) # UPDATE actual qty to warehouse by pr_qty self.make_sl_entry(d, d.warehouse, flt(pr_qty), d.valuation_rate, is_submit) # UPDATE actual to rejected warehouse by rejected qty if flt(d.rejected_qty) > 0: self.make_sl_entry(d, self.doc.rejected_warehouse, flt(d.rejected_qty) * flt(d.conversion_factor), d.valuation_rate, is_submit) self.bk_flush_supp_wh(is_submit) if self.values: get_obj('Stock Ledger', 'Stock Ledger').update_stock(self.values)
def on_update(self): if self.doc.rejected_warehouse: for d in getlist(self.doclist,'purchase_receipt_details'): d.rejected_warehouse = self.doc.rejected_warehouse get_obj('Stock Ledger').scrub_serial_nos(self) self.scrub_rejected_serial_nos()
def pull_so_details(self): self.check_if_already_pulled() if self.doc.sales_order_no: get_obj('DocType Mapper', 'Sales Order-Purchase Request', with_children=1).dt_map('Sales Order', 'Purchase Request', self.doc.sales_order_no, self.doc, self.doclist, "[['Sales Order', 'Purchase Request'],['Sales Order Item', 'Purchase Request Item']]") self.get_item_defaults() else: msgprint("Please select Sales Order whose details need to pull")
def pull_enq_details(self): self.doclist = self.doc.clear_table(self.doclist, 'quotation_details') get_obj('DocType Mapper', 'Opportunity-Quotation').dt_map('Opportunity', 'Quotation', self.doc.enq_no, self.doc, self.doclist, "[['Opportunity', 'Quotation'],['Opportunity Item', 'Quotation Item']]") self.get_adj_percent() return self.doc.quotation_to
def update_stock_ledger(self, update_stock): self.values = [] for d in self.get_item_list(): if webnotes.conn.get_value("Item", d['item_code'], "is_stock_item") == "Yes": # this happens when item is changed from non-stock to stock item if not d["warehouse"]: continue if d['reserved_qty'] < 0 : # Reduce reserved qty from reserved warehouse mentioned in so if not d["reserved_warehouse"]: webnotes.throw(_("Reserved Warehouse is missing in Sales Order")) args = { "item_code": d['item_code'], "voucher_type": self.doc.doctype, "voucher_no": self.doc.name, "reserved_qty": flt(update_stock) * flt(d['reserved_qty']), "posting_date": self.doc.posting_date, "is_amended": self.doc.amended_from and 'Yes' or 'No' } get_obj("Warehouse", d["reserved_warehouse"]).update_bin(args) # Reduce actual qty from warehouse self.make_sl_entry(d, d['warehouse'], - flt(d['qty']) , 0, update_stock) get_obj('Stock Ledger', 'Stock Ledger').update_stock(self.values)
def test_leave_bal(self): leaves.l_all.save(1) leaves.l_app1.save(1) leaves.l_app2.save(1) la1 = get_obj('Leave Application', leaves.l_app1.name, with_children=1) la1.validate() la1.doc.docstatus = 1 la1.doc.save() self.assertTrue(la1.doc.total_leave_days == 2) la1.doc.half_day = 1 la1.validate() la1.doc.save() self.assertTrue(la1.doc.total_leave_days == .5) print "Test case for leave applied no of days" la2 = get_obj('Leave Application', leaves.l_app2.name, with_children=1) la2.validate() bal = la2.get_leave_balance() self.assertTrue(bal, 18) print "Test case for leave balance"
def on_submit(self): self.validate_packed_qty() # Check for Approving Authority get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total, self) # validate serial no for item table (non-sales-bom item) and packing list (sales-bom item) sl_obj = get_obj("Stock Ledger") sl_obj.validate_serial_no(self, 'delivery_note_details') sl_obj.validate_serial_no_warehouse(self, 'delivery_note_details') sl_obj.validate_serial_no(self, 'packing_details') sl_obj.validate_serial_no_warehouse(self, 'packing_details') # update delivery details in serial no sl_obj.update_serial_record(self, 'delivery_note_details', is_submit = 1, is_incoming = 0) sl_obj.update_serial_record(self, 'packing_details', is_submit = 1, is_incoming = 0) # update delivered qty in sales order get_obj("Sales Common").update_prevdoc_detail(1,self) # create stock ledger entry self.update_stock_ledger(update_stock = 1) self.credit_limit() self.set_buying_amount() self.make_gl_entries() # set DN status webnotes.conn.set(self.doc, 'status', 'Submitted')
def calculate_cost(self, bom_no): main_bom_list = get_obj('Production Control').traverse_bom_tree( bom_no = bom_no, qty = 1, calculate_cost = 1) main_bom_list.reverse() for bom in main_bom_list: bom_obj = get_obj('BOM', bom, with_children = 1) bom_obj.calculate_cost() return 'calculated'
def update_against_document_in_jv(self): """ Links invoice and advance voucher: 1. cancel advance voucher 2. split into multiple rows if partially adjusted, assign against voucher 3. submit advance voucher """ lst = [] for d in getlist(self.doclist, "advance_adjustment_details"): if flt(d.allocated_amount) > 0: args = { "voucher_no": d.journal_voucher, "voucher_detail_no": d.jv_detail_no, "against_voucher_type": "Sales Invoice", "against_voucher": self.doc.name, "account": self.doc.debit_to, "is_advance": "Yes", "dr_or_cr": "credit", "unadjusted_amt": flt(d.advance_amount), "allocated_amt": flt(d.allocated_amount), } lst.append(args) if lst: get_obj("GL Control").reconcile_against_document(lst)
def validate(self): self.so_dn_required() # self.dn_required() self.validate_proj_cust() sales_com_obj = get_obj("Sales Common") sales_com_obj.check_stop_sales_order(self) sales_com_obj.check_active_sales_items(self) sales_com_obj.check_conversion_rate(self) sales_com_obj.validate_max_discount(self, "entries") # verify whether rate is not greater than tolerance sales_com_obj.get_allocated_sum(self) # this is to verify that the allocated % of sales persons is 100% sales_com_obj.validate_fiscal_year(self.doc.fiscal_year, self.doc.posting_date, "Posting Date") self.validate_customer() self.validate_debit_to_acc() self.validate_debit_acc() self.validate_fixed_asset_account() self.add_remarks() if cint(self.doc.is_pos): self.validate_pos() self.validate_write_off_account() if cint(self.doc.update_stock): get_obj("Stock Ledger").validate_serial_no(self, "entries") self.validate_item_code() self.update_current_stock() self.set_in_words() if not self.doc.is_opening: self.doc.is_opening = "No" self.set_aging_date() self.clear_advances() # Set against account self.set_against_income_account() self.validate_c_form()
def rewrite_pages(self): """rewrite all web pages""" import webnotes from webnotes.model.doclist import DocList from webnotes.model.code import get_obj # rewrite all web pages for name in webnotes.conn.sql("""select name, modified from `tabWeb Page` where docstatus=0"""): DocList('Web Page', name[0]).save() webnotes.conn.set_value('Web Page', name[0], 'modified', name[1]) # rewrite all blog pages for name in webnotes.conn.sql("""select name, modified from `tabBlog` where docstatus=0 and ifnull(published,0)=1"""): DocList('Blog', name[0]).save() webnotes.conn.set_value('Blog', name[0], 'modified', name[1]) from webnotes.cms.make import make_web_core make_web_core() get_obj('Page', 'blog').write_cms_page(force=True) get_obj('Page', 'Login Page').write_cms_page(force=True) webnotes.msgprint('Rebuilt all blogs and pages')
def update_stock(self, values): for v in values: sle_id, serial_nos = "", "" # get serial nos if v["serial_no"]: serial_nos = self.get_sr_no_list(v["serial_no"], v["actual_qty"]) # reverse quantities for cancel if v["is_cancelled"] == "Yes": v["actual_qty"] = -flt(v["actual_qty"]) # cancel matching entry sql( "update `tabStock Ledger Entry` set is_cancelled='Yes' where voucher_no=%s and voucher_type=%s", (v["voucher_no"], v["voucher_type"]), ) if v["actual_qty"]: sle_id = self.make_entry(v) get_obj("Warehouse", v["warehouse"]).update_bin( flt(v["actual_qty"]), 0, 0, 0, 0, v["item_code"], v["posting_date"], sle_id, v["posting_time"], "", v["is_cancelled"], )
def update_production_order(self, is_submit): if self.doc.production_order: # first perform some validations # (they are here coz this fn is also called during on_cancel) pro_obj = get_obj("Production Order", self.doc.production_order) if flt(pro_obj.doc.docstatus) != 1: msgprint("""You cannot do any transaction against Production Order : %s, as it's not submitted""" % (pro_obj.doc.name), raise_exception=1) if pro_obj.doc.status == 'Stopped': msgprint("""You cannot do any transaction against Production Order : %s, as it's status is 'Stopped'"""% (pro_obj.doc.name), raise_exception=1) # update bin if self.doc.purpose == "Manufacture/Repack": pro_obj.doc.produced_qty = flt(pro_obj.doc.produced_qty) + \ (is_submit and 1 or -1 ) * flt(self.doc.fg_completed_qty) args = { "item_code": pro_obj.doc.production_item, "posting_date": self.doc.posting_date, "planned_qty": (is_submit and -1 or 1 ) * flt(self.doc.fg_completed_qty) } get_obj('Warehouse', pro_obj.doc.fg_warehouse).update_bin(args) # update production order status pro_obj.doc.status = (flt(pro_obj.doc.qty)==flt(pro_obj.doc.produced_qty)) \ and 'Completed' or 'In Process' pro_obj.doc.save()
def get_tc_details(self): return get_obj('Purchase Common').get_tc_details(self)
def get_rate(self,arg): """Get tax rate if account type is tax""" get_obj('Sales Common').get_rate(arg)
def get_adj_percent(self, arg=''): """Fetch ref rate from item master as per selected price list""" get_obj('Sales Common').get_adj_percent(self)
def get_barcode_details(self, barcode): return get_obj('Sales Common').get_barcode_details(barcode)
def update_against_document_in_jv(self, obj, table_field_name, against_document_no, against_document_doctype, account_head, dr_or_cr,doctype): for d in getlist(obj.doclist, table_field_name): self.validate_jv_entry(d, account_head, dr_or_cr) if flt(d.advance_amount) == flt(d.allocated_amount): # cancel JV jv_obj = get_obj('Journal Voucher', d.journal_voucher, with_children=1) get_obj(dt='GL Control').make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel =1, adv_adj =1) # update ref in JV Detail webnotes.conn.sql("update `tabJournal Voucher Detail` set %s = '%s' where name = '%s'" % (doctype=='Purchase Invoice' and 'against_voucher' or 'against_invoice', cstr(against_document_no), d.jv_detail_no)) # re-submit JV jv_obj = get_obj('Journal Voucher', d.journal_voucher, with_children =1) get_obj(dt='GL Control').make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel = 0, adv_adj =1) elif flt(d.advance_amount) > flt(d.allocated_amount): # cancel JV jv_obj = get_obj('Journal Voucher', d.journal_voucher, with_children=1) get_obj(dt='GL Control').make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel =1, adv_adj = 1) # add extra entries self.add_extra_entry(jv_obj, d.journal_voucher, d.jv_detail_no, flt(d.allocated_amount), account_head, doctype, dr_or_cr, against_document_no) # re-submit JV jv_obj = get_obj('Journal Voucher', d.journal_voucher, with_children =1) get_obj(dt='GL Control').make_gl_entries(jv_obj.doc, jv_obj.doclist, cancel = 0, adv_adj = 1) else: msgprint("Allocation amount cannot be greater than advance amount") raise Exception
def get_po_details(self): self.validate_prev_docname() get_obj('DocType Mapper', 'Purchase Order-Purchase Receipt').dt_map('Purchase Order', 'Purchase Receipt', self.doc.purchase_order_no, self.doc, self.doclist, "[['Purchase Order','Purchase Receipt'],['Purchase Order Item', 'Purchase Receipt Item'],['Purchase Taxes and Charges','Purchase Taxes and Charges']]")
def get_bin_details(self, arg = ''): return get_obj(dt='Purchase Common').get_bin_details(arg)
def get_default_schedule_date(self): get_obj(dt = 'Purchase Common').get_default_schedule_date(self)
def load_default_taxes(self): self.doclist = get_obj('Purchase Common').load_default_taxes(self)
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_rate(self,arg): return get_obj('Sales Common').get_rate(arg)
def get_purchase_tax_details(self): self.doclist = get_obj('Purchase Common').get_purchase_tax_details(self)
def get_comm_rate(self, sales_partner): """Get Commission rate of Sales Partner""" return get_obj('Sales Common').get_comm_rate(sales_partner, self)
def get_rate(self,arg): return get_obj('Purchase Common').get_rate(arg,self)
def get_item_list(self): return get_obj('Sales Common').get_item_list(self)
def get_adj_percent(self, arg=''): """Re-calculates Basic Rate & amount based on Price List Selected""" get_obj('Sales Common').get_adj_percent(self)
def get_adj_percent(self, arg=''): get_obj('Sales Common').get_adj_percent(self)
def get_contact_details(self): return get_obj('Sales Common').get_contact_details(self,0)
def get_tc_details(self): return get_obj('Sales Common').get_tc_details(self)
def on_update(self): self.doclist = get_obj('Sales Common').make_packing_list(self,'delivery_note_details')
def load_default_taxes(self): self.doclist = get_obj('Sales Common').load_default_taxes(self)
def validate_fiscal_year(self): get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.transaction_date,'Quotation Date')
def get_formatted_message(self, args): """ get formatted message for auto notification""" return get_obj('Notification Control').get_formatted_message(args)
def get_other_charges(self): self.doclist = get_obj('Sales Common').get_other_charges(self)
def validate_reference_value(self): get_obj('DocType Mapper', 'Purchase Order-Purchase Invoice', with_children = 1).validate_reference_value(self, self.doc.name)
def get_obj(dt = None, dn = None, doc=None, doclist=[], with_children = True): from webnotes.model.code import get_obj return get_obj(dt, dn, doc, doclist, with_children)
def get_advances(self): self.doclist = get_obj('GL Control').get_advances(self, self.doc.credit_to, 'Purchase Invoice Advance','advance_allocation_details','debit')
def make_gl_entries(self, is_cancel = 0): get_obj(dt='GL Control').make_gl_entries(self.doc, self.doclist, cancel = is_cancel, \ use_mapper = (self.doc.write_off_account and self.doc.write_off_amount and 'Purchase Invoice with write off' or ''))
def validate_fiscal_year(self): get_obj(dt = 'Purchase Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.transaction_date,'Purchase Request Date')
def clear_advances(self): get_obj('GL Control').clear_advances( self, 'Purchase Invoice Advance','advance_allocation_details')