Hi,
I have created a doctype that runs through some items that will trigger a creation of invoice. My parent is now working fine, but I am having trouble on child: Sales Invoice Items.
I’m getting error as below:
Error: Data missing in table: Items
Here is my code from my doctype’s python.
item = frappe.db.sql("""SELECT * FROM `tabUnit Charge` uc,`tabCharge` c
WHERE uc.charge = c.name
AND c.charge_type = 'Fixed Amount'
AND uc.bill_run_type = %s
AND uc.parent = %s;""", (self.bill_run_type, i.unit), as_dict=1)
for j in item:
c_doc = doc.append('items',{})
c_doc.item_code = j.item
c_doc.item_name = j.description
c_doc.descriptiom = j.description
c_doc.qty = 1
c_doc.rate = j.rate
c_doc.amount = j.rate
c_doc.base_rate = j.rate * doc.conversion_rate
c_doc.base_amount = j.rate * doc.conversion_rate
total = total + j.rate
I have no idea what is missing on the items. Please help.
Hi I think it should be like this
SI_item = {
"item_code": item_name,
"item_name": item_name,
"rate": line_item["price"],
"amount": line_item["price"] * line_item["quantity"],
"qty": line_item["quantity"],
"warehouse": "Sales Order Default - SSC",
"description": item_name
}
SI_items.append(SI_item)
SI = frappe.get_doc({"doctype": "Sales Invoice",
# "name": test_order["number"],
"title": customer_name,
"customer": customer_name,
"posting_date": test_order["created_at"],
"due_date": test_order["created_at"],
"items": SI_items,
"apply_discount_on": "Grand Total",
"discount_amount": promo,
"taxes": charges,
"docstatus": 1
})
SI_created = SI.insert(ignore_permissions=True)
2 Likes
Thanks for the reply John. Will try this out. All of my items are Services, WIll there still be a need to populate the warehouse?
I don’t it won’t be needing warehouse since they are Services
Thanks John. By the way, the first sccript works now. I was actually creating a Sales Invoice without an item on my SQL query. Thanks.
By the way, I have been in contact with Chris Ian regarding some development works here in the Philippines. I think you guys are from same company.
Great! Yes you can also do it by sql.
Yes we are in the same company Bai Web and Mobile Labs. It would be best if we communicate in Slack, email to me jvfiel@bai.ph your email ad that you prefer to use in Slack, and we’ll invite you