Skip to content

Commit

Permalink
Merge pull request #355 from yrestom/develop
Browse files Browse the repository at this point in the history
Version: 6.1.0
  • Loading branch information
yrestom authored Jul 22, 2023
2 parents cffbb74 + 001bc45 commit da72b95
Show file tree
Hide file tree
Showing 9 changed files with 887 additions and 543 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ assignees: ''
**IMPORTANT** Before reporting a bug:
A properly detailed bug report can save a LOT of time and help fixing issues as soon as possible.
A properly detailed bug report can save a LOT of time and help fix issues as soon as possible.
- ->
### Versions
Expand All @@ -31,7 +31,7 @@ A properly detailed bug report can save a LOT of time and help fixing issues as
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
4. See the error

### What is Expected?

Expand All @@ -44,4 +44,4 @@ Add any other context about the problem here.


### Screenshots
If applicable, add screenshots to help explain your problem.
If applicable, could you add screenshots to help explain your problem?
2 changes: 1 addition & 1 deletion posawesome/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import unicode_literals
import frappe

__version__ = "6.0.4"
__version__ = "6.1.0"


def console(*data):
Expand Down
91 changes: 63 additions & 28 deletions posawesome/posawesome/api/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from erpnext.setup.utils import get_exchange_rate
from erpnext.accounts.doctype.bank_account.bank_account import get_party_bank_account
from posawesome.posawesome.api.m_pesa import submit_mpesa_payment
from erpnext.accounts.utils import QueryPaymentLedger, get_outstanding_invoices as _get_outstanding_invoices


def create_payment_entry(
Expand All @@ -23,6 +24,7 @@ def create_payment_entry(
reference_date=None,
reference_no=None,
posting_date=None,
cost_center=None,
submit=0,
):
# TODO : need to have a better way to handle currency
Expand All @@ -48,7 +50,7 @@ def create_payment_entry(
pe = frappe.new_doc("Payment Entry")
pe.payment_type = payment_type
pe.company = company
pe.cost_center = erpnext.get_default_cost_center(company)
pe.cost_center = cost_center or erpnext.get_default_cost_center(company)
pe.posting_date = date
pe.mode_of_payment = mode_of_payment
pe.party_type = party_type
Expand Down Expand Up @@ -127,34 +129,66 @@ def set_paid_amount_and_received_amount(

@frappe.whitelist()
def get_outstanding_invoices(company, currency, customer=None, pos_profile_name=None):
filters = {
"company": company,
"outstanding_amount": (">", 0),
"docstatus": 1,
"is_return": 0,
"currency": currency,
}
if customer:
filters.update({"customer": customer})
if pos_profile_name:
filters.update({"pos_profile": pos_profile_name})
invoices = frappe.get_all(
"Sales Invoice",
filters=filters,
fields=[
"name",
"customer",
"customer_name",
"outstanding_amount",
"grand_total",
"due_date",
"posting_date",
"currency",
"pos_profile",
],
order_by="due_date asc",
)
return invoices
precision = frappe.get_precision("Sales Invoice", "outstanding_amount") or 2
outstanding_invoices = _get_outstanding_invoices(
party_type="Customer",
party=customer,
account=get_party_account("Customer", customer, company),
)
invoices_list = []
customer_name = frappe.get_cached_value("Customer", customer, "customer_name")
for invoice in outstanding_invoices:
if invoice.get("currency") == currency:
if pos_profile_name and frappe.get_cached_value(
"Sales Invoice", invoice.get("voucher_no"), "pos_profile"
) != pos_profile_name:
continue
outstanding_amount = invoice.outstanding_amount
if outstanding_amount > 0.5 / (10**precision):
invoice_dict = {
"name": invoice.get("voucher_no"),
"customer": customer,
"customer_name": customer_name,
"outstanding_amount": invoice.get("outstanding_amount"),
"grand_total": invoice.get("invoice_amount"),
"due_date": invoice.get("due_date"),
"posting_date": invoice.get("posting_date"),
"currency": invoice.get("currency"),
"pos_profile": pos_profile_name,

}
invoices_list.append(invoice_dict)
return invoices_list
else:
filters = {
"company": company,
"outstanding_amount": (">", 0),
"docstatus": 1,
"is_return": 0,
"currency": currency,
}
if customer:
filters.update({"customer": customer})
if pos_profile_name:
filters.update({"pos_profile": pos_profile_name})
invoices = frappe.get_all(
"Sales Invoice",
filters=filters,
fields=[
"name",
"customer",
"customer_name",
"outstanding_amount",
"grand_total",
"due_date",
"posting_date",
"currency",
"pos_profile",
],
order_by="due_date asc",
)
return invoices


@frappe.whitelist()
Expand Down Expand Up @@ -258,6 +292,7 @@ def process_pos_payment(payload):
posting_date=today,
reference_no=pos_opening_shift_name,
reference_date=today,
cost_center=data.pos_profile.get("cost_center"),
submit=1,
)
new_payments_entry.append(new_payment_entry)
Expand Down
34 changes: 29 additions & 5 deletions posawesome/posawesome/api/posapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
get_applicable_delivery_charges as _get_applicable_delivery_charges,
)
from frappe.utils.caching import redis_cache
from posawesome.posawesome.api.taxes import calculate_taxes


@frappe.whitelist()
def get_opening_dialog_data():
data = {}
data["companys"] = frappe.get_list("Company", limit_page_length=0, order_by="name")
data["companies"] = frappe.get_list("Company", limit_page_length=0, order_by="name")
data["pos_profiles_data"] = frappe.get_list(
"POS Profile",
filters={"disabled": 0},
Expand Down Expand Up @@ -266,6 +267,7 @@ def _get_items(pos_profile, price_list, item_group, search_value):
"batch_qty": batch.qty,
"expiry_date": batch_doc.expiry_date,
"batch_price": batch_doc.posa_batch_price,
"manufacturing_date": batch_doc.manufacturing_date,
}
)
serial_no_data = []
Expand Down Expand Up @@ -491,6 +493,7 @@ def update_invoice(data):
for tax in invoice_doc.taxes:
tax.included_in_print_rate = 1

calculate_taxes(invoice_doc)
invoice_doc.save()
return invoice_doc

Expand Down Expand Up @@ -884,6 +887,7 @@ def _get_items_details(pos_profile, items_data):
"batch_qty": batch.qty,
"expiry_date": batch_doc.expiry_date,
"batch_price": batch_doc.posa_batch_price,
"manufacturing_date": batch_doc.manufacturing_date,
}
)

Expand Down Expand Up @@ -913,12 +917,31 @@ def _get_items_details(pos_profile, items_data):
@frappe.whitelist()
def get_item_detail(item, doc=None, warehouse=None, price_list=None):
item = json.loads(item)
today = nowdate()
item_code = item.get("item_code")
if warehouse and item.get("has_batch_no") and not item.get("batch_no"):
item["batch_no"] = get_batch_no(
item_code, warehouse, item.get("qty"), False, item.get("d")
)
batch_no_data = []
if warehouse and item.get("has_batch_no"):
batch_list = get_batch_qty(warehouse=warehouse, item_code=item_code)
if batch_list:
for batch in batch_list:
if batch.qty > 0 and batch.batch_no:
batch_doc = frappe.get_cached_doc("Batch", batch.batch_no)
if (
str(batch_doc.expiry_date) > str(today)
or batch_doc.expiry_date in ["", None]
) and batch_doc.disabled == 0:
batch_no_data.append(
{
"batch_no": batch.batch_no,
"batch_qty": batch.qty,
"expiry_date": batch_doc.expiry_date,
"batch_price": batch_doc.posa_batch_price,
"manufacturing_date": batch_doc.manufacturing_date,
}
)

item["selling_price_list"] = price_list

max_discount = frappe.get_value("Item", item_code, "max_discount")
res = get_item_details(
item,
Expand All @@ -928,6 +951,7 @@ def get_item_detail(item, doc=None, warehouse=None, price_list=None):
if item.get("is_stock_item") and warehouse:
res["actual_qty"] = get_stock_availability(item_code, warehouse)
res["max_discount"] = max_discount
res["batch_no_data"] = batch_no_data
return res


Expand Down
Loading

0 comments on commit da72b95

Please sign in to comment.