commit
1f3310e0d1
@ -165,7 +165,7 @@ class Account(Document):
|
|||||||
# If outstanding greater than credit limit and not authorized person raise exception
|
# If outstanding greater than credit limit and not authorized person raise exception
|
||||||
if credit_limit > 0 and flt(total_outstanding) > credit_limit \
|
if credit_limit > 0 and flt(total_outstanding) > credit_limit \
|
||||||
and not self.get_authorized_user():
|
and not self.get_authorized_user():
|
||||||
throw(_("{0} Credit limit {0} crossed").format(_(credit_limit_from), credit_limit))
|
throw(_("{0} Credit limit {1} crossed").format(_(credit_limit_from), credit_limit))
|
||||||
|
|
||||||
def validate_due_date(self, posting_date, due_date):
|
def validate_due_date(self, posting_date, due_date):
|
||||||
credit_days = (self.credit_days or frappe.db.get_value("Company", self.company, "credit_days"))
|
credit_days = (self.credit_days or frappe.db.get_value("Company", self.company, "credit_days"))
|
||||||
|
@ -20,6 +20,9 @@ def execute(filters=None):
|
|||||||
return columns, res
|
return columns, res
|
||||||
|
|
||||||
def validate_filters(filters, account_details):
|
def validate_filters(filters, account_details):
|
||||||
|
if filters.get("account") and not account_details.get(filters.account):
|
||||||
|
frappe.throw(_("Account {0} does not exists").format(filters.account))
|
||||||
|
|
||||||
if filters.get("account") and filters.get("group_by_account") \
|
if filters.get("account") and filters.get("group_by_account") \
|
||||||
and account_details[filters.account].group_or_ledger == "Ledger":
|
and account_details[filters.account].group_or_ledger == "Ledger":
|
||||||
frappe.throw(_("Can not filter based on Account, if grouped by Account"))
|
frappe.throw(_("Can not filter based on Account, if grouped by Account"))
|
||||||
|
@ -70,9 +70,14 @@ class PurchaseOrder(BuyingController):
|
|||||||
def validate_minimum_order_qty(self):
|
def validate_minimum_order_qty(self):
|
||||||
itemwise_min_order_qty = frappe._dict(frappe.db.sql("select name, min_order_qty from tabItem"))
|
itemwise_min_order_qty = frappe._dict(frappe.db.sql("select name, min_order_qty from tabItem"))
|
||||||
|
|
||||||
|
itemwise_qty = frappe._dict()
|
||||||
for d in self.get("po_details"):
|
for d in self.get("po_details"):
|
||||||
if flt(d.stock_qty) < flt(itemwise_min_order_qty.get(d.item_code)):
|
itemwise_qty.setdefault(d.item_code, 0)
|
||||||
frappe.throw(_("Row #{0}: Ordered qty can not less than item's minimum order qty (defined in item master).").format(d.idx))
|
itemwise_qty[d.item_code] += flt(d.stock_qty)
|
||||||
|
|
||||||
|
for item_code, qty in itemwise_qty.items():
|
||||||
|
if flt(qty) < flt(itemwise_min_order_qty.get(item_code)):
|
||||||
|
frappe.throw(_("Item #{0}: Ordered qty can not less than item's minimum order qty (defined in item master).").format(item_code))
|
||||||
|
|
||||||
def get_schedule_dates(self):
|
def get_schedule_dates(self):
|
||||||
for d in self.get('po_details'):
|
for d in self.get('po_details'):
|
||||||
|
@ -151,7 +151,7 @@ class SellingController(StockController):
|
|||||||
|
|
||||||
cumulated_tax_fraction += tax.tax_fraction_for_current_item
|
cumulated_tax_fraction += tax.tax_fraction_for_current_item
|
||||||
|
|
||||||
if cumulated_tax_fraction and not self.discount_amount_applied:
|
if cumulated_tax_fraction and not self.discount_amount_applied and item.qty:
|
||||||
item.base_amount = flt((item.amount * self.conversion_rate) /
|
item.base_amount = flt((item.amount * self.conversion_rate) /
|
||||||
(1 + cumulated_tax_fraction), self.precision("base_amount", item))
|
(1 + cumulated_tax_fraction), self.precision("base_amount", item))
|
||||||
|
|
||||||
@ -308,14 +308,23 @@ class SellingController(StockController):
|
|||||||
customer_account = frappe.db.get_value("Account", {"company": self.company,
|
customer_account = frappe.db.get_value("Account", {"company": self.company,
|
||||||
"master_name": self.customer}, "name")
|
"master_name": self.customer}, "name")
|
||||||
if customer_account:
|
if customer_account:
|
||||||
total_outstanding = frappe.db.sql("""select
|
invoice_outstanding = frappe.db.sql("""select
|
||||||
sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
|
sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
|
||||||
from `tabGL Entry` where account = %s""", customer_account)
|
from `tabGL Entry` where account = %s""", customer_account)
|
||||||
total_outstanding = total_outstanding[0][0] if total_outstanding else 0
|
invoice_outstanding = flt(invoice_outstanding[0][0]) if invoice_outstanding else 0
|
||||||
|
|
||||||
outstanding_including_current = flt(total_outstanding) + flt(grand_total)
|
ordered_amount_to_be_billed = frappe.db.sql("""
|
||||||
frappe.get_doc('Account', customer_account).run_method("check_credit_limit",
|
select sum(grand_total*(100 - ifnull(per_billed, 0))/100)
|
||||||
outstanding_including_current)
|
from `tabSales Order`
|
||||||
|
where customer=%s and docstatus = 1
|
||||||
|
and ifnull(per_billed, 0) < 100 and status != 'Stopped'""", self.customer)
|
||||||
|
|
||||||
|
ordered_amount_to_be_billed = flt(ordered_amount_to_be_billed[0][0]) \
|
||||||
|
if ordered_amount_to_be_billed else 0.0
|
||||||
|
|
||||||
|
total_outstanding = invoice_outstanding + ordered_amount_to_be_billed
|
||||||
|
|
||||||
|
frappe.get_doc('Account', customer_account).check_credit_limit(total_outstanding)
|
||||||
|
|
||||||
def validate_max_discount(self):
|
def validate_max_discount(self):
|
||||||
for d in self.get(self.fname):
|
for d in self.get(self.fname):
|
||||||
@ -330,6 +339,9 @@ class SellingController(StockController):
|
|||||||
reserved_warehouse = ""
|
reserved_warehouse = ""
|
||||||
reserved_qty_for_main_item = 0
|
reserved_qty_for_main_item = 0
|
||||||
|
|
||||||
|
if not d.qty:
|
||||||
|
frappe.throw(_("Row {0}: Qty is mandatory").format(d.idx))
|
||||||
|
|
||||||
if self.doctype == "Sales Order":
|
if self.doctype == "Sales Order":
|
||||||
if (frappe.db.get_value("Item", d.item_code, "is_stock_item") == 'Yes' or
|
if (frappe.db.get_value("Item", d.item_code, "is_stock_item") == 'Yes' or
|
||||||
self.has_sales_bom(d.item_code)) and not d.warehouse:
|
self.has_sales_bom(d.item_code)) and not d.warehouse:
|
||||||
|
@ -47,7 +47,7 @@ class ProductionOrder(Document):
|
|||||||
|
|
||||||
self.validate_production_order_against_so()
|
self.validate_production_order_against_so()
|
||||||
else:
|
else:
|
||||||
frappe.throw(_("Sales Order {0} is not valid") % self.sales_order)
|
frappe.throw(_("Sales Order {0} is not valid").format(self.sales_order))
|
||||||
|
|
||||||
def validate_warehouse(self):
|
def validate_warehouse(self):
|
||||||
from erpnext.stock.utils import validate_warehouse_company
|
from erpnext.stock.utils import validate_warehouse_company
|
||||||
|
@ -287,6 +287,7 @@ def make_purchase_order_based_on_supplier(source_name, target_doc=None):
|
|||||||
def get_material_requests_based_on_supplier(supplier):
|
def get_material_requests_based_on_supplier(supplier):
|
||||||
supplier_items = [d[0] for d in frappe.db.get_values("Item",
|
supplier_items = [d[0] for d in frappe.db.get_values("Item",
|
||||||
{"default_supplier": supplier})]
|
{"default_supplier": supplier})]
|
||||||
|
if supplier_items:
|
||||||
material_requests = frappe.db.sql_list("""select distinct mr.name
|
material_requests = frappe.db.sql_list("""select distinct mr.name
|
||||||
from `tabMaterial Request` mr, `tabMaterial Request Item` mr_item
|
from `tabMaterial Request` mr, `tabMaterial Request Item` mr_item
|
||||||
where mr.name = mr_item.parent
|
where mr.name = mr_item.parent
|
||||||
@ -296,6 +297,8 @@ def get_material_requests_based_on_supplier(supplier):
|
|||||||
and mr.docstatus = 1
|
and mr.docstatus = 1
|
||||||
and mr.status != 'Stopped'""" % ', '.join(['%s']*len(supplier_items)),
|
and mr.status != 'Stopped'""" % ', '.join(['%s']*len(supplier_items)),
|
||||||
tuple(supplier_items))
|
tuple(supplier_items))
|
||||||
|
else:
|
||||||
|
material_requests = []
|
||||||
return material_requests, supplier_items
|
return material_requests, supplier_items
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user