Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions posnext/doc_events/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,60 @@ def validate_si(doc,method):
"mode_of_payment": mop[0].mode_of_payment,
"amount": doc.rounded_total or doc.grand_total
})
def create_delivery_note(doc, method):
if doc.update_stock:
return

if doc.is_return != 1:
delivery_note = frappe.new_doc("Delivery Note")
delivery_note.customer = doc.customer
delivery_note.posting_date = doc.posting_date
delivery_note.posting_time = doc.posting_time
delivery_note.taxes_and_charges = doc.taxes_and_charges
delivery_note.company = doc.company

all_items_sufficient = True

for item in doc.items:
available_qty = frappe.db.get_value(
"Bin", {"item_code": item.item_code, "warehouse": item.warehouse}, "actual_qty"
) or 0

delivery_note.append("items", {
"item_code": item.item_code,
"uom": item.uom,
"qty": item.qty,
"rate": item.rate,
"warehouse": item.warehouse,
"against_sales_invoice": item.parent,
"si_detail": item.name,
"cost_center": item.cost_center
})

if item.qty > available_qty:
all_items_sufficient = False

for tax in doc.taxes:
delivery_note.append("taxes", {
"charge_type": tax.charge_type,
"account_head": tax.account_head,
"description": tax.description,
"rate": tax.rate,
"tax_amount": tax.tax_amount,
"total": tax.total,
"cost_center": tax.cost_center
})

for sp in doc.sales_team:
delivery_note.append("sales_team", {
"sales_person": sp.sales_person,
"allocated_percentage": sp.allocated_percentage
})

delivery_note.save()

if all_items_sufficient:
delivery_note.submit()
frappe.msgprint(f"Delivery Note {delivery_note.name} submitted as sufficient stock is available.")
else:
frappe.msgprint(f"Delivery Note {delivery_note.name} saved as draft due to insufficient stock.")
3 changes: 3 additions & 0 deletions posnext/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@
"Sales Invoice": {
"validate": [
"posnext.doc_events.sales_invoice.validate_si",
],
"on_submit": [
"posnext.doc_events.sales_invoice.create_delivery_note",
]
},
"POS Profile": {
Expand Down
18 changes: 17 additions & 1 deletion posnext/public/js/pos_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,25 @@ posnext.PointOfSale.Controller = class {
() => this.reload_status = true,
]);

this.setup_form_events();


}
setup_form_events() {
frappe.ui.form.on('Sales Invoice', {
after_save: function(frm) {
if (!frm.doc.pos_profile) return;

frappe.db.get_doc('POS Profile', frm.doc.pos_profile)
.then(pos_profile => {
if (pos_profile.custom_stock_update) {
frm.set_value('update_stock', 0);
// frm.save();
}
});
}
});
}


fetch_opening_entry(value) {
return frappe.call("posnext.posnext.page.posnext.point_of_sale.check_opening_entry", { "user": frappe.session.user, "value": value });
Expand Down
Loading