Skip to content

Commit

Permalink
Version: 3.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yrestom committed Dec 24, 2022
1 parent 3ff3f30 commit d1b3584
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 5 deletions.
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__ = "3.4.1"
__version__ = "3.5.0"


def console(*data):
Expand Down
20 changes: 17 additions & 3 deletions posawesome/posawesome/api/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import frappe
from frappe import _
from frappe.model.mapper import get_mapped_doc
from frappe.utils import flt, add_days
from frappe.utils import flt, add_days, cint
from posawesome.posawesome.doctype.pos_coupon.pos_coupon import update_coupon_code_count
from posawesome.posawesome.api.posapp import get_company_domain
from posawesome.posawesome.doctype.delivery_charges.delivery_charges import (
get_applicable_delivery_charges,
)
from erpnext.accounts.party import get_party_account_currency
from erpnext.controllers.accounts_controller import get_payment_terms


def validate(doc, method):
Expand Down Expand Up @@ -72,6 +74,7 @@ def create_sales_order(doc):
sales_order_doc.posa_notes = doc.posa_notes
sales_order_doc.flags.ignore_permissions = True
sales_order_doc.flags.ignore_account_permission = True
sales_order_doc.is_pos = 1
sales_order_doc.save()
sales_order_doc.submit()
url = frappe.utils.get_url_to_form(
Expand Down Expand Up @@ -120,12 +123,23 @@ def update_item(obj, target, source_parent):
},
"postprocess": update_item,
},
"Payment Schedule": {
"doctype": "Payment Schedule",
"field_map": {
"discount": "discount",
"discounted_amount": "discounted_amount",
"due_date": "due_date",
"outstanding": "outstanding",
"paid_amount": "paid_amount",
"payment_amount": "payment_amount",
},
"add_if_empty": False
},
"Sales Taxes and Charges": {
"doctype": "Sales Taxes and Charges",
"add_if_empty": True,
"add_if_empty": False,
},
"Sales Team": {"doctype": "Sales Team", "add_if_empty": True},
"Payment Schedule": {"doctype": "Payment Schedule", "add_if_empty": True},
},
target_doc,
set_missing_values,
Expand Down
82 changes: 81 additions & 1 deletion posawesome/posawesome/api/posapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import unicode_literals
import json
import frappe
from frappe.utils import nowdate, flt, cstr
from frappe.utils import nowdate, flt, cstr, cint
from frappe import _
from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
from erpnext.stock.get_item_details import get_item_details
Expand All @@ -26,6 +26,8 @@
from posawesome.posawesome.doctype.delivery_charges.delivery_charges import (
get_applicable_delivery_charges as _get_applicable_delivery_charges,
)
from erpnext.accounts.party import get_party_account_currency
from erpnext.controllers.accounts_controller import get_payment_terms


@frappe.whitelist()
Expand Down Expand Up @@ -482,6 +484,8 @@ def submit_invoice(invoice, data):
invoice_doc.flags.ignore_permissions = True
frappe.flags.ignore_account_permission = True
invoice_doc.posa_is_printed = 1
invoice_doc.calculate_taxes_and_totals()
set_payment_schedule(invoice_doc)
invoice_doc.save()

if frappe.get_value(
Expand Down Expand Up @@ -1451,3 +1455,79 @@ def get_applicable_delivery_charges(
return _get_applicable_delivery_charges(
company, pos_profile, customer, shipping_address_name
)


def set_payment_schedule(doc):
if doc.doctype == "Sales Invoice" and doc.is_return:
doc.payment_terms_template = ""
return

party_account_currency = doc.get("party_account_currency")
if not party_account_currency:
party_type, party = doc.get_party()

if party_type and party:
party_account_currency = get_party_account_currency(party_type, party, doc.company)

posting_date = doc.get("bill_date") or doc.get("posting_date") or doc.get("transaction_date")
date = doc.get("due_date")
due_date = date or posting_date

base_grand_total = doc.get("base_rounded_total") or doc.base_grand_total - doc.base_paid_amount
grand_total = doc.get("rounded_total") or doc.grand_total - doc.paid_amount

if doc.doctype in ("Sales Invoice", "Purchase Invoice"):
base_grand_total = base_grand_total - flt(doc.base_write_off_amount)
grand_total = grand_total - flt(doc.write_off_amount)
po_or_so, doctype, fieldname = doc.get_order_details()
automatically_fetch_payment_terms = cint(
frappe.db.get_single_value("Accounts Settings", "automatically_fetch_payment_terms")
)

if doc.get("total_advance"):
if party_account_currency == doc.company_currency:
base_grand_total -= doc.get("total_advance")
grand_total = flt(
base_grand_total / doc.get("conversion_rate"), doc.precision("grand_total")
)
else:
grand_total -= doc.get("total_advance")
base_grand_total = flt(
grand_total * doc.get("conversion_rate"), doc.precision("base_grand_total")
)

if not doc.get("payment_schedule"):
if (
doc.doctype in ["Sales Invoice", "Purchase Invoice"]
and automatically_fetch_payment_terms
and doc.linked_order_has_payment_terms(po_or_so, fieldname, doctype)
):
doc.fetch_payment_terms_from_order(po_or_so, doctype)
if doc.get("payment_terms_template"):
doc.ignore_default_payment_terms_template = 1
elif doc.get("payment_terms_template"):
data = get_payment_terms(doc.payment_terms_template, posting_date, grand_total, base_grand_total)
for item in data:
doc.append("payment_schedule", item)
elif doc.doctype not in ["Purchase Receipt"]:
data = dict(
due_date=due_date,
invoice_portion=100,
payment_amount=grand_total,
base_payment_amount=base_grand_total,
)
doc.append("payment_schedule", data)
frappe.msgprint(str(doc.outstanding_amount))
for d in doc.get("payment_schedule"):
if d.invoice_portion:
d.payment_amount = flt(
grand_total * flt(d.invoice_portion / 100), d.precision("payment_amount")
)
d.base_payment_amount = flt(
base_grand_total * flt(d.invoice_portion / 100), d.precision("base_payment_amount")
)
d.outstanding = d.payment_amount
elif not d.invoice_portion:
d.base_payment_amount = flt(
d.payment_amount * doc.get("conversion_rate"), d.precision("base_payment_amount")
)

0 comments on commit d1b3584

Please sign in to comment.