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
2 changes: 1 addition & 1 deletion posnext/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.0"
__version__ = "0.1.1"
31 changes: 17 additions & 14 deletions posnext/overrides/pos_closing_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get_pos_invoices(start, end, pos_profile, user):
select
name, timestamp(posting_date, posting_time) as "timestamp"
from
`tabSales Invoice`
`tabPOS Invoice`
where
owner = %s and docstatus = 1 and pos_profile = %s
""",
Expand All @@ -30,7 +30,7 @@ def get_pos_invoices(start, end, pos_profile, user):
data = [d for d in data if start_dt <= get_datetime(d.timestamp) <= end_dt]

# need to get taxes and payments so can't avoid get_doc
data = [frappe.get_doc("Sales Invoice", d.name).as_dict() for d in data]
data = [frappe.get_doc("POS Invoice", d.name).as_dict() for d in data]
return data


Expand All @@ -49,31 +49,34 @@ def validate_pos_invoices(self):
invalid_rows = []
for d in self.pos_transactions:
invalid_row = {"idx": d.idx}
pos_invoice = frappe.db.get_values(
"Sales Invoice",
pos_invoice_data = frappe.db.get_values(
"POS Invoice",
d.pos_invoice,
["pos_profile", "docstatus", "owner"],
as_dict=1,
)[0]
# if pos_invoice.consolidated_invoice:
# invalid_row.setdefault("msg", []).append(
# _("Sales Invoice is {}").format(frappe.bold("already consolidated"))
# )
# invalid_rows.append(invalid_row)
# continue

if not pos_invoice_data:
invalid_row.setdefault("msg", []).append(
_("POS Invoice {} not found").format(frappe.bold(d.pos_invoice))
)
invalid_rows.append(invalid_row)
continue

pos_invoice = pos_invoice_data[0]
if pos_invoice.pos_profile != self.pos_profile:
invalid_row.setdefault("msg", []).append(
_("Sales Profile doesn't matches {}").format(
_("POS Profile doesn't matches {}").format(
frappe.bold(self.pos_profile)
)
)
if pos_invoice.docstatus != 1:
invalid_row.setdefault("msg", []).append(
_("Sales Invoice is not {}").format(frappe.bold("submitted"))
_("POS Invoice is not {}").format(frappe.bold("submitted"))
)
if pos_invoice.owner != self.user:
invalid_row.setdefault("msg", []).append(
_("Sales Invoice isn't created by user {}").format(
_("POS Invoice isn't created by user {}").format(
frappe.bold(self.owner)
)
)
Expand All @@ -89,4 +92,4 @@ def validate_pos_invoices(self):
for msg in row.get("msg"):
error_list.append(_("Row #{}: {}").format(row.get("idx"), msg))

frappe.throw(error_list, title=_("Invalid Sales Invoices"), as_list=True)
frappe.throw(error_list, title=_("Invalid POS Invoices"), as_list=True)
35 changes: 11 additions & 24 deletions posnext/overrides/pos_invoice_merge_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def serial_and_batch_bundle_reference_for_pos_invoice(self):

def on_cancel(self):
pos_invoice_docs = [
frappe.get_cached_doc("Sales Invoice", d.pos_invoice)
frappe.get_cached_doc("POS Invoice", d.pos_invoice)
for d in self.pos_invoices
]

Expand All @@ -28,28 +28,15 @@ def on_cancel(self):
self.cancel_linked_invoices()

def on_submit(self):
pos_invoice_docs = [
frappe.get_cached_doc("Sales Invoice", d.pos_invoice)
for d in self.pos_invoices
]

returns = [d for d in pos_invoice_docs if d.get("is_return") == 1]
sales = [d for d in pos_invoice_docs if d.get("is_return") == 0]

sales_invoice, credit_note = "", ""
if returns:
credit_note = self.process_merging_into_credit_note(returns)

if sales:
sales_invoice = self.process_merging_into_sales_invoice(sales)

self.save() # save consolidated_sales_invoice & consolidated_credit_note ref in merge log
self.update_pos_invoices(pos_invoice_docs, sales_invoice, credit_note)
# Set serial and batch bundle references first
self.serial_and_batch_bundle_reference_for_pos_invoice()
# Then call parent's on_submit which has all the consolidation logic
super().on_submit()

def validate_pos_invoice_status(self):
for d in self.pos_invoices:
status, docstatus, is_return, return_against = frappe.db.get_value(
"Sales Invoice",
"POS Invoice",
d.pos_invoice,
["status", "docstatus", "is_return", "return_against"],
)
Expand All @@ -58,13 +45,13 @@ def validate_pos_invoice_status(self):
bold_status = frappe.bold(status)
if docstatus != 1:
frappe.throw(
_("Row #{}: Sales Invoice {} is not submitted yet").format(
_("Row #{}: POS Invoice {} is not submitted yet").format(
d.idx, bold_pos_invoice
)
)
if status == "Consolidated":
frappe.throw(
_("Row #{}: Sales Invoice {} has been {}").format(
_("Row #{}: POS Invoice {} has been {}").format(
d.idx, bold_pos_invoice, bold_status
)
)
Expand All @@ -75,7 +62,7 @@ def validate_pos_invoice_status(self):
):
bold_return_against = frappe.bold(return_against)
return_against_status = frappe.db.get_value(
"Sales Invoice", return_against, "status"
"POS Invoice", return_against, "status"
)
if return_against_status != "Consolidated":
# if return entry is not getting merged in the current pos closing and if it is not consolidated
Expand Down Expand Up @@ -121,7 +108,7 @@ def split_invoices(invoices):
_invoices = []
special_invoices = []
pos_return_docs = [
frappe.get_cached_doc("Sales Invoice", d.pos_invoice)
frappe.get_cached_doc("POS Invoice", d.pos_invoice)
for d in invoices
if d.is_return and d.return_against
]
Expand Down Expand Up @@ -183,7 +170,7 @@ def get_all_unconsolidated_invoices():
"docstatus": 1,
}
pos_invoices = frappe.db.get_all(
"Sales Invoice",
"POS Invoice",
filters=filters,
fields=[
"name as pos_invoice",
Expand Down
17 changes: 9 additions & 8 deletions posnext/posnext/page/posnext/point_of_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def get_past_order_list(search_term, status, pos_profile=None, limit=20):
"pos_profile": pos_profile,
}
invoices_by_customer = frappe.db.get_all(
"Sales Invoice",
"POS Invoice",
filters=fltr1,
fields=fields,
page_length=limit,
Expand All @@ -418,7 +418,7 @@ def get_past_order_list(search_term, status, pos_profile=None, limit=20):
"pos_profile": pos_profile,
}
invoices_by_name = frappe.db.get_all(
"Sales Invoice",
"POS Invoice",
filters=fltr2,
fields=fields,
page_length=limit,
Expand All @@ -430,7 +430,7 @@ def get_past_order_list(search_term, status, pos_profile=None, limit=20):
if pos_profile:
fltr = {"status": status, "pos_profile": pos_profile}
invoice_list = frappe.db.get_all(
"Sales Invoice", filters=fltr, fields=fields, page_length=limit
"POS Invoice", filters=fltr, fields=fields, page_length=limit
)

return invoice_list
Expand Down Expand Up @@ -527,7 +527,7 @@ def generate_pdf_and_save(docname, doctype, print_format=None):
def make_sales_return(source_name, target_doc=None):
from erpnext.controllers.sales_and_purchase_return import make_return_doc

return make_return_doc("Sales Invoice", source_name, target_doc)
return make_return_doc("POS Invoice", source_name, target_doc)


@frappe.whitelist()
Expand All @@ -536,10 +536,11 @@ def get_lcr(customer=None, item_code=None):
if customer and item_code:
d = frappe.db.sql(
f"""
SELECT item.rate FROM `tabSales Invoice Item` item INNER JOIN `tabSales Invoice` SI ON SI.name=item.parent
WHERE SI.customer='{customer}' AND item.item_code='{item_code}'
ORDER BY SI.creation desc
LIMIT 1
SELECT item.rate FROM `tabPOS Invoice Item` item
INNER JOIN `tabPOS Invoice` PI ON PI.name=item.parent
WHERE PI.customer='{customer}' AND item.item_code='{item_code}'
AND PI.docstatus = 1
ORDER BY PI.creation desc
""",
as_dict=True,
)
Expand Down
16 changes: 10 additions & 6 deletions posnext/public/js/pos_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ posnext.PointOfSale.Controller = class {
this.setup_form_events();
}
setup_form_events() {
frappe.ui.form.on("Sales Invoice", {
frappe.ui.form.on("POS Invoice", {
after_save: function (frm) {
if (!frm.doc.pos_profile) return;

Expand Down Expand Up @@ -516,7 +516,7 @@ posnext.PointOfSale.Controller = class {
wrapper: this.$components_wrapper,
events: {
open_invoice_data: (name) => {
frappe.db.get_doc("Sales Invoice", name).then((doc) => {
frappe.db.get_doc("POS Invoice", name).then((doc) => {
this.order_summary.load_summary_of(doc);
});
},
Expand All @@ -542,7 +542,7 @@ posnext.PointOfSale.Controller = class {

process_return: (name) => {
this.recent_order_list.toggle_component(false);
frappe.db.get_doc("Sales Invoice", name).then((doc) => {
frappe.db.get_doc("POS Invoice", name).then((doc) => {
frappe.run_serially([
() => this.make_return_invoice(doc),
() => this.cart.load_invoice(),
Expand Down Expand Up @@ -618,7 +618,7 @@ posnext.PointOfSale.Controller = class {
}

make_sales_invoice_frm() {
const doctype = "Sales Invoice";
const doctype = "POS Invoice";
return new Promise((resolve) => {
if (this.frm) {
this.frm = this.get_new_frm(this.frm);
Expand All @@ -639,7 +639,7 @@ posnext.PointOfSale.Controller = class {
}

get_new_frm(_frm) {
const doctype = "Sales Invoice";
const doctype = "POS Invoice";
const page = $("<div>");
const frm = _frm || new frappe.ui.form.Form(doctype, page, false);
const name = frappe.model.make_new_doc_and_get_name(doctype, true);
Expand Down Expand Up @@ -809,6 +809,10 @@ posnext.PointOfSale.Controller = class {
total_incoming_rate += parseFloat(item.valuation_rate) * item.qty;
});
this.item_selector.update_total_incoming_rate(total_incoming_rate);
if (item_row) {
this.cart.update_totals_section(this.frm);
this.cart.update_item_html(item_row);
}

return item_row; // eslint-disable-line no-unsafe-finally
}
Expand Down Expand Up @@ -961,7 +965,7 @@ posnext.PointOfSale.Controller = class {
frappe.throw({
title: __("Not Available"),
message: __(
"Serial No: {0} has already been transacted into another Sales Invoice.",
"Serial No: {0} has already been transacted into another POS Invoice.",
[serial_no.bold()],
),
});
Expand Down
Loading