Example #1
0
	def add_to_stock_entry_detail(self, item_dict, bom_no=None, idx=None):
		if not idx:	idx = 1
		expense_account, cost_center = frappe.db.get_values("Company", self.doc.company, \
			["default_expense_account", "cost_center"])[0]

		for d in item_dict:
			se_child = addchild(self.doc, 'mtn_details', 'Stock Entry Detail', 
				self.doclist)
			se_child.idx = idx
			se_child.s_warehouse = item_dict[d].get("from_warehouse", self.doc.from_warehouse)
			se_child.t_warehouse = item_dict[d].get("to_warehouse", self.doc.to_warehouse)
			se_child.item_code = cstr(d)
			se_child.item_name = item_dict[d]["item_name"]
			se_child.description = item_dict[d]["description"]
			se_child.uom = item_dict[d]["stock_uom"]
			se_child.stock_uom = item_dict[d]["stock_uom"]
			se_child.qty = flt(item_dict[d]["qty"])
			se_child.expense_account = item_dict[d]["expense_account"] or expense_account
			se_child.cost_center = item_dict[d]["cost_center"] or cost_center
			
			# in stock uom
			se_child.transfer_qty = flt(item_dict[d]["qty"])
			se_child.conversion_factor = 1.00
			
			# to be assigned for finished item
			se_child.bom_no = bom_no

			# increment idx by 1
			idx += 1
		return idx
Example #2
0
    def generate_schedule(self):
        self.doclist = self.doc.clear_table(self.doclist,
                                            'maintenance_schedule_detail')
        frappe.db.sql(
            """delete from `tabMaintenance Schedule Detail` 
			where parent=%s""", (self.doc.name))
        count = 1
        for d in getlist(self.doclist, 'item_maintenance_detail'):
            self.validate_maintenance_detail()
            s_list = []
            s_list = self.create_schedule_list(d.start_date, d.end_date,
                                               d.no_of_visits, d.sales_person)
            for i in range(d.no_of_visits):
                child = addchild(self.doc, 'maintenance_schedule_detail',
                                 'Maintenance Schedule Detail', self.doclist)
                child.item_code = d.item_code
                child.item_name = d.item_name
                child.scheduled_date = s_list[i].strftime('%Y-%m-%d')
                if d.serial_no:
                    child.serial_no = d.serial_no
                child.idx = count
                count = count + 1
                child.sales_person = d.sales_person
                child.save(1)

        self.on_update()
Example #3
0
def update_against_doc(d, jv_obj):
	"""
		Updates against document, if partial amount splits into rows
	"""

	frappe.db.sql("""
		update `tabJournal Voucher Detail` t1, `tabJournal Voucher` t2	
		set t1.%(dr_or_cr)s = '%(allocated_amt)s', 
		t1.%(against_fld)s = '%(against_voucher)s', t2.modified = now() 
		where t1.name = '%(voucher_detail_no)s' and t1.parent = t2.name""" % d)
	
	if d['allocated_amt'] < d['unadjusted_amt']:
		jvd = frappe.db.sql("""select cost_center, balance, against_account, is_advance 
			from `tabJournal Voucher Detail` where name = %s""", d['voucher_detail_no'])
		# new entry with balance amount
		ch = addchild(jv_obj.doc, 'entries', 'Journal Voucher Detail')
		ch.account = d['account']
		ch.cost_center = cstr(jvd[0][0])
		ch.balance = cstr(jvd[0][1])
		ch.fields[d['dr_or_cr']] = flt(d['unadjusted_amt']) - flt(d['allocated_amt'])
		ch.fields[d['dr_or_cr']== 'debit' and 'credit' or 'debit'] = 0
		ch.against_account = cstr(jvd[0][2])
		ch.is_advance = cstr(jvd[0][3])
		ch.docstatus = 1
		ch.save(1)
Example #4
0
    def get_balance(self):
        if not getlist(self.doclist, 'entries'):
            msgprint("Please enter atleast 1 entry in 'GL Entries' table")
        else:
            flag, self.doc.total_debit, self.doc.total_credit = 0, 0, 0
            diff = flt(self.doc.difference, 2)

            # If any row without amount, set the diff on that row
            for d in getlist(self.doclist, 'entries'):
                if not d.credit and not d.debit and diff != 0:
                    if diff > 0:
                        d.credit = diff
                    elif diff < 0:
                        d.debit = diff
                    flag = 1

            # Set the diff in a new row
            if flag == 0 and diff != 0:
                jd = addchild(self.doc, 'entries', 'Journal Voucher Detail',
                              self.doclist)
                if diff > 0:
                    jd.credit = abs(diff)
                elif diff < 0:
                    jd.debit = abs(diff)

            # Set the total debit, total credit and difference
            for d in getlist(self.doclist, 'entries'):
                self.doc.total_debit += flt(d.debit, 2)
                self.doc.total_credit += flt(d.credit, 2)

            self.doc.difference = flt(self.doc.total_debit, 2) - flt(
                self.doc.total_credit, 2)
Example #5
0
def update_packing_list_item(obj, packing_item_code, qty, warehouse, line, packing_list_idx):
	bin = get_bin_qty(packing_item_code, warehouse)
	item = get_packing_item_details(packing_item_code)

	# check if exists
	exists = 0
	for d in getlist(obj.doclist, 'packing_details'):
		if d.parent_item == line.item_code and d.item_code == packing_item_code and d.parent_detail_docname == line.name:
			pi, exists = d, 1
			break

	if not exists:
		pi = addchild(obj.doc, 'packing_details', 'Packed Item', obj.doclist)

	pi.parent_item = line.item_code
	pi.item_code = packing_item_code
	pi.item_name = item['item_name']
	pi.parent_detail_docname = line.name
	pi.description = item['description']
	pi.uom = item['stock_uom']
	pi.qty = flt(qty)
	pi.actual_qty = bin and flt(bin['actual_qty']) or 0
	pi.projected_qty = bin and flt(bin['projected_qty']) or 0
	if not pi.warehouse:
		pi.warehouse = warehouse
	if not pi.batch_no:
		pi.batch_no = cstr(line.batch_no)
	pi.idx = packing_list_idx
	
	packing_list_idx += 1
Example #6
0
 def make_table(self, doct_name, tab_fname, tab_name):
     list1 = frappe.db.sql("select name from `tab%s` where docstatus != 2" %
                           doct_name)
     for li in list1:
         child = addchild(self.doc, tab_fname, tab_name, self.doclist)
         if (tab_fname == 'earning_details'):
             child.e_type = cstr(li[0])
             child.modified_value = 0
         elif (tab_fname == 'deduction_details'):
             child.d_type = cstr(li[0])
             child.d_modified_amt = 0
Example #7
0
    def get_item_specification_details(self):
        self.doclist = self.doc.clear_table(self.doclist,
                                            'qa_specification_details')
        specification = frappe.db.sql(
            "select specification, value from `tabItem Quality Inspection Parameter` \
			where parent = '%s' order by idx" % (self.doc.item_code))
        for d in specification:
            child = addchild(self.doc, 'qa_specification_details',
                             'Quality Inspection Reading', self.doclist)
            child.specification = d[0]
            child.value = d[1]
            child.status = 'Accepted'
Example #8
0
 def add_exploded_items(self):
     "Add items to Flat BOM table"
     self.doclist = self.doc.clear_table(self.doclist, 'flat_bom_details',
                                         1)
     for d in self.cur_exploded_items:
         ch = addchild(self.doc, 'flat_bom_details', 'BOM Explosion Item',
                       self.doclist)
         for i in self.cur_exploded_items[d].keys():
             ch.fields[i] = self.cur_exploded_items[d][i]
         ch.amount = flt(ch.qty) * flt(ch.rate)
         ch.qty_consumed_per_unit = flt(ch.qty) / flt(self.doc.quantity)
         ch.docstatus = self.doc.docstatus
         ch.save(1)
Example #9
0
 def get_outstanding_invoices(self):
     self.doclist = self.doc.clear_table(self.doclist, 'entries')
     total = 0
     for d in self.get_values():
         total += flt(d[2])
         jd = addchild(self.doc, 'entries', 'Journal Voucher Detail',
                       self.doclist)
         jd.account = cstr(d[1])
         if self.doc.write_off_based_on == 'Accounts Receivable':
             jd.credit = flt(d[2])
             jd.against_invoice = cstr(d[0])
         elif self.doc.write_off_based_on == 'Accounts Payable':
             jd.debit = flt(d[2])
             jd.against_voucher = cstr(d[0])
         jd.save(1)
     jd = addchild(self.doc, 'entries', 'Journal Voucher Detail',
                   self.doclist)
     if self.doc.write_off_based_on == 'Accounts Receivable':
         jd.debit = total
     elif self.doc.write_off_based_on == 'Accounts Payable':
         jd.credit = total
     jd.save(1)
 def create_payment_table(self, gle):
     for d in gle:
         ch = addchild(self.doc, 'ir_payment_details',
                       'Payment to Invoice Matching Tool Detail',
                       self.doclist)
         ch.voucher_no = d.get('voucher_no')
         ch.posting_date = d.get('posting_date')
         ch.amt_due =  self.doc.account_type == 'debit' and flt(d.get('amt_due')) \
          or -1*flt(d.get('amt_due'))
         ch.total_amt = flt(d.get('total_amt'))
         ch.against_account = d.get('against_account')
         ch.remarks = d.get('remark')
         ch.voucher_detail_no = d.get('voucher_detail_no')
Example #11
0
    def add_default_uom_in_conversion_factor_table(self):
        uom_conv_list = [
            d.uom for d in self.doclist.get(
                {"parentfield": "uom_conversion_details"})
        ]
        if self.doc.stock_uom not in uom_conv_list:
            ch = addchild(self.doc, 'uom_conversion_details',
                          'UOM Conversion Detail', self.doclist)
            ch.uom = self.doc.stock_uom
            ch.conversion_factor = 1

        for d in self.doclist.get({"parentfield": "uom_conversion_details"}):
            if d.conversion_factor == 1 and d.uom != self.doc.stock_uom:
                self.doclist.remove(d)
Example #12
0
    def add_so_in_table(self, open_so):
        """ Add sales orders in the table"""
        self.clear_so_table()

        so_list = [
            d.sales_order for d in getlist(self.doclist, 'pp_so_details')
        ]
        for r in open_so:
            if cstr(r['name']) not in so_list:
                pp_so = addchild(self.doc, 'pp_so_details',
                                 'Production Plan Sales Order', self.doclist)
                pp_so.sales_order = r['name']
                pp_so.sales_order_date = cstr(r['transaction_date'])
                pp_so.customer = cstr(r['customer'])
                pp_so.grand_total = flt(r['grand_total'])
Example #13
0
 def get_weekly_off_dates(self):
     self.validate_values()
     yr_start_date, yr_end_date = self.get_fy_start_end_dates()
     date_list = self.get_weekly_off_date_list(yr_start_date, yr_end_date)
     last_idx = max([
         cint(d.idx)
         for d in self.doclist.get({"parentfield": "holiday_list_details"})
     ] or [
         0,
     ])
     for i, d in enumerate(date_list):
         ch = addchild(self.doc, 'holiday_list_details', 'Holiday',
                       self.doclist)
         ch.description = self.doc.weekly_off
         ch.holiday_date = d
         ch.idx = last_idx + i + 1
Example #14
0
    def add_items(self, items):
        self.clear_item_table()

        for p in items:
            item_details = frappe.db.sql(
                """select description, stock_uom, default_bom 
				from tabItem where name=%s""", p['item_code'])
            pi = addchild(self.doc, 'pp_details', 'Production Plan Item',
                          self.doclist)
            pi.sales_order = p['parent']
            pi.warehouse = p['warehouse']
            pi.item_code = p['item_code']
            pi.description = item_details and item_details[0][0] or ''
            pi.stock_uom = item_details and item_details[0][1] or ''
            pi.bom_no = item_details and item_details[0][2] or ''
            pi.so_pending_qty = flt(p['pending_qty'])
            pi.planned_qty = flt(p['pending_qty'])
Example #15
0
	def get_details(self):
		if not (self.doc.bank_account and self.doc.from_date and self.doc.to_date):
			msgprint("Bank Account, From Date and To Date are Mandatory")
			return
	
		dl = frappe.db.sql("select t1.name, t1.cheque_no, t1.cheque_date, t2.debit, t2.credit, t1.posting_date, t2.against_account from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 where t2.parent = t1.name and t2.account = %s and (clearance_date is null or clearance_date = '0000-00-00' or clearance_date = '') and t1.posting_date >= %s and t1.posting_date <= %s and t1.docstatus=1", (self.doc.bank_account, self.doc.from_date, self.doc.to_date))
		
		self.doclist = self.doc.clear_table(self.doclist, 'entries')
		self.doc.total_amount = 0.0

		for d in dl:
			nl = addchild(self.doc, 'entries', 'Bank Reconciliation Detail', self.doclist)
			nl.posting_date = cstr(d[5])
			nl.voucher_id = cstr(d[0])
			nl.cheque_number = cstr(d[1])
			nl.cheque_date = cstr(d[2])
			nl.debit = flt(d[3])
			nl.credit = flt(d[4])
			nl.against_account = cstr(d[6])
			self.doc.total_amount += flt(flt(d[4]) - flt(d[3]))
Example #16
0
	def add_charges_in_pr(self, purchase_receipts):
		""" Add additional charges in selected pr proportionately"""
		total_amt = self.get_total_pr_amt(purchase_receipts)
		
		for pr in purchase_receipts:
			pr_bean = frappe.bean('Purchase Receipt', pr)
			idx = max([d.idx for d in pr_bean.doclist.get({"parentfield": "other_charges"})])
			
			for lc in self.doclist.get({"parentfield": "landed_cost_details"}):
				amt = flt(lc.amount) * flt(pr_bean.doc.net_total)/ flt(total_amt)
				
				matched_row = pr_bean.doclist.get({
					"parentfield": "other_charges", 
					"category": "Valuation",
					"add_deduct_tax": "Add",
					"charge_type": "Actual",
					"account_head": lc.account_head
				})
				
				if not matched_row:	# add if not exists
					ch = addchild(pr_bean.doc, 'other_charges', 'Purchase Taxes and Charges')
					ch.category = 'Valuation'
					ch.add_deduct_tax = 'Add'
					ch.charge_type = 'Actual'
					ch.description = lc.description
					ch.account_head = lc.account_head
					ch.cost_center = lc.cost_center
					ch.rate = amt
					ch.tax_amount = amt
					ch.docstatus = 1
					ch.idx = idx
					ch.save(1)
					idx += 1
				else:	# overwrite if exists
					matched_row[0].rate = amt
					matched_row[0].tax_amount = amt
					matched_row[0].cost_center = lc.cost_center
					
			pr_bean.run_method("validate")
			for d in pr_bean.doclist:
				d.save()
Example #17
0
	def get(self):
		"""
			Gets DocFields applied with Property Setter customizations via Customize Form Field
		"""
		self.clear()

		if self.doc.doc_type:
			from frappe.model.doc import addchild

			for d in self.get_ref_doclist():
				if d.doctype=='DocField':
					new = addchild(self.doc, 'fields', 'Customize Form Field', 
						self.doclist)
					self.set(
						{
							'list': self.docfield_properties,
							'doc' : d,
							'doc_to_set': new
						}
					)
				elif d.doctype=='DocType':
					self.set({ 'list': self.doctype_properties, 'doc': d })