diff --git a/posawesome/__init__.py b/posawesome/__init__.py index 36bec1d3..dc8a62b6 100644 --- a/posawesome/__init__.py +++ b/posawesome/__init__.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import frappe -__version__ = "6.1.2" +__version__ = "6.1.3" def console(*data): diff --git a/posawesome/hooks.py b/posawesome/hooks.py index 46a71f9d..2bf447ce 100644 --- a/posawesome/hooks.py +++ b/posawesome/hooks.py @@ -143,9 +143,9 @@ # "Task": "posawesome.task.get_dashboard_data" # } -override_doctype_class = { - "Sales Invoice": "posawesome.posawesome.api.taxes.customSalesInvoice", -} +# override_doctype_class = { +# "doctype": "method", +# } # exempt linked doctypes from being automatically cancelled # diff --git a/posawesome/posawesome/api/posapp.py b/posawesome/posawesome/api/posapp.py index 23fbb0f1..07b9b834 100644 --- a/posawesome/posawesome/api/posapp.py +++ b/posawesome/posawesome/api/posapp.py @@ -21,7 +21,7 @@ get_dummy_message, get_existing_payment_request_amount, ) -from erpnext.controllers.accounts_controller import add_taxes_from_tax_template + from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( get_loyalty_program_details_with_points, ) @@ -225,7 +225,13 @@ def _get_items(pos_profile, price_list, item_group, search_value): "item_code": ["in", items], "currency": pos_profile.get("currency"), "selling": 1, + "valid_from": ["<=", today], }, + or_filters=[ + ["valid_upto", ">=", today], + ["valid_upto", "in", ["", None]], + ], + order_by="valid_from ASC, valid_upto DESC", ) item_prices = {} @@ -444,6 +450,38 @@ def get_sales_person_names(): return sales_persons +def add_taxes_from_tax_template(item, parent_doc): + accounts_settings = frappe.get_cached_doc("Accounts Settings") + add_taxes_from_item_tax_template = ( + accounts_settings.add_taxes_from_item_tax_template + ) + if item.get("item_tax_template") and add_taxes_from_item_tax_template: + item_tax_template = item.get("item_tax_template") + taxes_template_details = frappe.get_all( + "Item Tax Template Detail", + filters={"parent": item_tax_template}, + fields=["tax_type"], + ) + + for tax_detail in taxes_template_details: + tax_type = tax_detail.get("tax_type") + + found = any(tax.account_head == tax_type for tax in parent_doc.taxes) + if not found: + tax_row = parent_doc.append("taxes", {}) + tax_row.update( + { + "description": str(tax_type).split(" - ")[0], + "charge_type": "On Net Total", + "account_head": tax_type, + } + ) + + if parent_doc.doctype == "Purchase Order": + tax_row.update({"category": "Total", "add_deduct_tax": "Add"}) + tax_row.db_insert() + + @frappe.whitelist() def update_invoice(data): data = json.loads(data) diff --git a/posawesome/public/js/posapp/components/pos/Payments.vue b/posawesome/public/js/posapp/components/pos/Payments.vue index f3c2c399..3c83a7f1 100644 --- a/posawesome/public/js/posapp/components/pos/Payments.vue +++ b/posawesome/public/js/posapp/components/pos/Payments.vue @@ -1229,11 +1229,18 @@ export default { set_mpesa_payment(payment) { this.pos_profile.use_customer_credit = 1; this.redeem_customer_credit = true; + const invoiceAmount = + this.invoice_doc.rounded_total || this.invoice_doc.grand_total; + let amount = + payment.unallocated_amount > invoiceAmount + ? invoiceAmount + : payment.unallocated_amount; + if (amount < 0 || !amount) amount = 0; const advance = { type: "Advance", credit_origin: payment.name, total_credit: flt(payment.unallocated_amount), - credit_to_redeem: flt(payment.unallocated_amount), + credit_to_redeem: flt(amount), }; this.clear_all_amounts(); this.customer_credit_dict.push(advance);