|
|
|
@ -3,11 +3,13 @@
|
|
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
import frappe, erpnext
|
|
|
|
|
import json
|
|
|
|
|
from frappe import _, throw
|
|
|
|
|
from frappe.utils import today, flt, cint, fmt_money, formatdate, getdate, add_days, add_months, get_last_day, nowdate
|
|
|
|
|
from erpnext.setup.utils import get_exchange_rate
|
|
|
|
|
from erpnext.accounts.utils import get_fiscal_years, validate_fiscal_year, get_account_currency
|
|
|
|
|
from erpnext.utilities.transaction_base import TransactionBase
|
|
|
|
|
from erpnext.buying.utils import update_last_purchase_rate
|
|
|
|
|
from erpnext.controllers.sales_and_purchase_return import validate_return
|
|
|
|
|
from erpnext.accounts.party import get_party_account_currency, validate_party_frozen_disabled
|
|
|
|
|
from erpnext.exceptions import InvalidCurrency
|
|
|
|
@ -15,6 +17,7 @@ from six import text_type
|
|
|
|
|
|
|
|
|
|
force_item_fields = ("item_group", "brand", "stock_uom", "is_fixed_asset")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AccountsController(TransactionBase):
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super(AccountsController, self).__init__(*args, **kwargs)
|
|
|
|
@ -122,7 +125,8 @@ class AccountsController(TransactionBase):
|
|
|
|
|
else:
|
|
|
|
|
# show message that the amount is not paid
|
|
|
|
|
self.paid_amount = 0
|
|
|
|
|
frappe.throw(_("Note: Payment Entry will not be created since 'Cash or Bank Account' was not specified"))
|
|
|
|
|
frappe.throw(
|
|
|
|
|
_("Note: Payment Entry will not be created since 'Cash or Bank Account' was not specified"))
|
|
|
|
|
else:
|
|
|
|
|
frappe.db.set(self, 'paid_amount', 0)
|
|
|
|
|
|
|
|
|
@ -142,7 +146,7 @@ class AccountsController(TransactionBase):
|
|
|
|
|
self.calculate_contribution()
|
|
|
|
|
|
|
|
|
|
def validate_date_with_fiscal_year(self):
|
|
|
|
|
if self.meta.get_field("fiscal_year") :
|
|
|
|
|
if self.meta.get_field("fiscal_year"):
|
|
|
|
|
date_field = ""
|
|
|
|
|
if self.meta.get_field("posting_date"):
|
|
|
|
|
date_field = "posting_date"
|
|
|
|
@ -308,7 +312,8 @@ class AccountsController(TransactionBase):
|
|
|
|
|
posting_date = args.get('posting_date') or self.get('posting_date')
|
|
|
|
|
fiscal_years = get_fiscal_years(posting_date, company=self.company)
|
|
|
|
|
if len(fiscal_years) > 1:
|
|
|
|
|
frappe.throw(_("Multiple fiscal years exist for the date {0}. Please set company in Fiscal Year").format(formatdate(posting_date)))
|
|
|
|
|
frappe.throw(_("Multiple fiscal years exist for the date {0}. Please set company in Fiscal Year").format(
|
|
|
|
|
formatdate(posting_date)))
|
|
|
|
|
else:
|
|
|
|
|
fiscal_year = fiscal_years[0][0]
|
|
|
|
|
|
|
|
|
@ -335,9 +340,9 @@ class AccountsController(TransactionBase):
|
|
|
|
|
|
|
|
|
|
if gl_dict.account and self.doctype not in ["Journal Entry",
|
|
|
|
|
"Period Closing Voucher", "Payment Entry"]:
|
|
|
|
|
|
|
|
|
|
self.validate_account_currency(gl_dict.account, account_currency)
|
|
|
|
|
set_balance_in_account_currency(gl_dict, account_currency, self.get("conversion_rate"), self.company_currency)
|
|
|
|
|
set_balance_in_account_currency(gl_dict, account_currency, self.get("conversion_rate"),
|
|
|
|
|
self.company_currency)
|
|
|
|
|
|
|
|
|
|
return gl_dict
|
|
|
|
|
|
|
|
|
@ -393,7 +398,6 @@ class AccountsController(TransactionBase):
|
|
|
|
|
|
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_advance_entries(self, include_unallocated=True):
|
|
|
|
|
if self.doctype == "Sales Invoice":
|
|
|
|
|
party_account = self.debit_to
|
|
|
|
@ -447,7 +451,8 @@ class AccountsController(TransactionBase):
|
|
|
|
|
advance_entries_against_si = [d.reference_name for d in self.get("advances")]
|
|
|
|
|
for d in advance_entries:
|
|
|
|
|
if not advance_entries_against_si or d.reference_name not in advance_entries_against_si:
|
|
|
|
|
frappe.msgprint(_("Payment Entry {0} is linked against Order {1}, check if it should be pulled as advance in this invoice.")
|
|
|
|
|
frappe.msgprint(_(
|
|
|
|
|
"Payment Entry {0} is linked against Order {1}, check if it should be pulled as advance in this invoice.")
|
|
|
|
|
.format(d.reference_name, d.against_order))
|
|
|
|
|
|
|
|
|
|
def update_against_document_in_jv(self):
|
|
|
|
@ -474,21 +479,21 @@ class AccountsController(TransactionBase):
|
|
|
|
|
if flt(d.allocated_amount) > 0:
|
|
|
|
|
args = frappe._dict({
|
|
|
|
|
'voucher_type': d.reference_type,
|
|
|
|
|
'voucher_no' : d.reference_name,
|
|
|
|
|
'voucher_detail_no' : d.reference_row,
|
|
|
|
|
'against_voucher_type' : self.doctype,
|
|
|
|
|
'against_voucher' : self.name,
|
|
|
|
|
'account' : party_account,
|
|
|
|
|
'voucher_no': d.reference_name,
|
|
|
|
|
'voucher_detail_no': d.reference_row,
|
|
|
|
|
'against_voucher_type': self.doctype,
|
|
|
|
|
'against_voucher': self.name,
|
|
|
|
|
'account': party_account,
|
|
|
|
|
'party_type': party_type,
|
|
|
|
|
'party': party,
|
|
|
|
|
'is_advance' : 'Yes',
|
|
|
|
|
'dr_or_cr' : dr_or_cr,
|
|
|
|
|
'unadjusted_amount' : flt(d.advance_amount),
|
|
|
|
|
'allocated_amount' : flt(d.allocated_amount),
|
|
|
|
|
'is_advance': 'Yes',
|
|
|
|
|
'dr_or_cr': dr_or_cr,
|
|
|
|
|
'unadjusted_amount': flt(d.advance_amount),
|
|
|
|
|
'allocated_amount': flt(d.allocated_amount),
|
|
|
|
|
'exchange_rate': (self.conversion_rate
|
|
|
|
|
if self.party_account_currency != self.company_currency else 1),
|
|
|
|
|
'grand_total': (self.base_grand_total
|
|
|
|
|
if self.party_account_currency==self.company_currency else self.grand_total),
|
|
|
|
|
if self.party_account_currency == self.company_currency else self.grand_total),
|
|
|
|
|
'outstanding_amount': self.outstanding_amount
|
|
|
|
|
})
|
|
|
|
|
lst.append(args)
|
|
|
|
@ -507,7 +512,9 @@ class AccountsController(TransactionBase):
|
|
|
|
|
ref_amt = flt(frappe.db.get_value(ref_dt + " Item",
|
|
|
|
|
item.get(item_ref_dn), based_on), self.precision(based_on, item))
|
|
|
|
|
if not ref_amt:
|
|
|
|
|
frappe.msgprint(_("Warning: System will not check overbilling since amount for Item {0} in {1} is zero").format(item.item_code, ref_dt))
|
|
|
|
|
frappe.msgprint(
|
|
|
|
|
_("Warning: System will not check overbilling since amount for Item {0} in {1} is zero").format(
|
|
|
|
|
item.item_code, ref_dt))
|
|
|
|
|
else:
|
|
|
|
|
already_billed = frappe.db.sql("""select sum(%s) from `tab%s`
|
|
|
|
|
where %s=%s and docstatus=1 and parent != %s""" %
|
|
|
|
@ -523,7 +530,9 @@ class AccountsController(TransactionBase):
|
|
|
|
|
max_allowed_amt = flt(ref_amt * (100 + tolerance) / 100)
|
|
|
|
|
|
|
|
|
|
if total_billed_amt - max_allowed_amt > 0.01:
|
|
|
|
|
frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set in Stock Settings").format(item.item_code, item.idx, max_allowed_amt))
|
|
|
|
|
frappe.throw(_(
|
|
|
|
|
"Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set in Stock Settings").format(
|
|
|
|
|
item.item_code, item.idx, max_allowed_amt))
|
|
|
|
|
|
|
|
|
|
def get_company_default(self, fieldname):
|
|
|
|
|
from erpnext.accounts.utils import get_company_default
|
|
|
|
@ -535,7 +544,7 @@ class AccountsController(TransactionBase):
|
|
|
|
|
if item_codes:
|
|
|
|
|
stock_items = [r[0] for r in frappe.db.sql("""select name
|
|
|
|
|
from `tabItem` where name in (%s) and is_stock_item=1""" % \
|
|
|
|
|
(", ".join((["%s"]*len(item_codes))),), item_codes)]
|
|
|
|
|
(", ".join((["%s"] * len(item_codes))),), item_codes)]
|
|
|
|
|
|
|
|
|
|
return stock_items
|
|
|
|
|
|
|
|
|
@ -619,7 +628,6 @@ class AccountsController(TransactionBase):
|
|
|
|
|
if (party_account_currency
|
|
|
|
|
and party_account_currency != self.company_currency
|
|
|
|
|
and self.currency != party_account_currency):
|
|
|
|
|
|
|
|
|
|
frappe.throw(_("Accounting Entry for {0}: {1} can only be made in currency: {2}")
|
|
|
|
|
.format(party_type, party, party_account_currency), InvalidCurrency)
|
|
|
|
|
|
|
|
|
@ -631,7 +639,7 @@ class AccountsController(TransactionBase):
|
|
|
|
|
for d in self.get("items"):
|
|
|
|
|
if d.is_fixed_asset:
|
|
|
|
|
# if d.qty > 1:
|
|
|
|
|
# frappe.throw(_("Row #{0}: Qty must be 1, as item is a fixed asset. Please use separate row for multiple qty.").format(d.idx))
|
|
|
|
|
# frappe.throw(_("Row #{0}: Qty must be 1, as item is a fixed asset. Please use separate row for multiple qty.").format(d.idx))
|
|
|
|
|
|
|
|
|
|
if d.meta.get_field("asset") and d.asset:
|
|
|
|
|
asset = frappe.get_doc("Asset", d.asset)
|
|
|
|
@ -645,18 +653,23 @@ class AccountsController(TransactionBase):
|
|
|
|
|
.format(d.idx, d.asset, d.item_code))
|
|
|
|
|
|
|
|
|
|
# elif asset.docstatus != 1:
|
|
|
|
|
# frappe.throw(_("Row #{0}: Asset {1} must be submitted").format(d.idx, d.asset))
|
|
|
|
|
# frappe.throw(_("Row #{0}: Asset {1} must be submitted").format(d.idx, d.asset))
|
|
|
|
|
|
|
|
|
|
elif self.doctype == "Purchase Invoice":
|
|
|
|
|
# if asset.status != "Submitted":
|
|
|
|
|
# frappe.throw(_("Row #{0}: Asset {1} is already {2}")
|
|
|
|
|
# .format(d.idx, d.asset, asset.status))
|
|
|
|
|
# frappe.throw(_("Row #{0}: Asset {1} is already {2}")
|
|
|
|
|
# .format(d.idx, d.asset, asset.status))
|
|
|
|
|
if getdate(asset.purchase_date) != getdate(self.posting_date):
|
|
|
|
|
frappe.throw(_("Row #{0}: Posting Date must be same as purchase date {1} of asset {2}").format(d.idx, asset.purchase_date, d.asset))
|
|
|
|
|
frappe.throw(
|
|
|
|
|
_("Row #{0}: Posting Date must be same as purchase date {1} of asset {2}").format(d.idx,
|
|
|
|
|
asset.purchase_date,
|
|
|
|
|
d.asset))
|
|
|
|
|
elif asset.is_existing_asset:
|
|
|
|
|
frappe.throw(_("Row #{0}: Purchase Invoice cannot be made against an existing asset {1}").format(d.idx, d.asset))
|
|
|
|
|
frappe.throw(
|
|
|
|
|
_("Row #{0}: Purchase Invoice cannot be made against an existing asset {1}").format(
|
|
|
|
|
d.idx, d.asset))
|
|
|
|
|
|
|
|
|
|
elif self.docstatus=="Sales Invoice" and self.docstatus == 1:
|
|
|
|
|
elif self.docstatus == "Sales Invoice" and self.docstatus == 1:
|
|
|
|
|
if self.update_stock:
|
|
|
|
|
frappe.throw(_("'Update Stock' cannot be checked for fixed asset sale"))
|
|
|
|
|
|
|
|
|
@ -693,7 +706,7 @@ class AccountsController(TransactionBase):
|
|
|
|
|
if item.item_code in group_item_qty:
|
|
|
|
|
item.qty = group_item_qty[item.item_code]
|
|
|
|
|
item.amount = group_item_amount[item.item_code]
|
|
|
|
|
item.rate = flt(flt(item.amount)/flt(item.qty), item.precision("rate"))
|
|
|
|
|
item.rate = flt(flt(item.amount) / flt(item.qty), item.precision("rate"))
|
|
|
|
|
del group_item_qty[item.item_code]
|
|
|
|
|
else:
|
|
|
|
|
duplicate_list.append(item)
|
|
|
|
@ -774,6 +787,7 @@ class AccountsController(TransactionBase):
|
|
|
|
|
def get_tax_rate(account_head):
|
|
|
|
|
return frappe.db.get_value("Account", account_head, ["tax_rate", "account_name"], as_dict=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist()
|
|
|
|
|
def get_default_taxes_and_charges(master_doctype, tax_template=None, company=None):
|
|
|
|
|
if not company: return {}
|
|
|
|
@ -790,6 +804,7 @@ def get_default_taxes_and_charges(master_doctype, tax_template=None, company=Non
|
|
|
|
|
'taxes': get_taxes_and_charges(master_doctype, default_tax)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist()
|
|
|
|
|
def get_taxes_and_charges(master_doctype, master_name):
|
|
|
|
|
if not master_name:
|
|
|
|
@ -809,6 +824,7 @@ def get_taxes_and_charges(master_doctype, master_name):
|
|
|
|
|
|
|
|
|
|
return taxes_and_charges
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_conversion_rate(currency, conversion_rate, conversion_rate_label, company):
|
|
|
|
|
"""common validation for currency and price list currency"""
|
|
|
|
|
|
|
|
|
@ -818,12 +834,14 @@ def validate_conversion_rate(currency, conversion_rate, conversion_rate_label, c
|
|
|
|
|
throw(_("{0} is mandatory. Maybe Currency Exchange record is not created for {1} to {2}.").format(
|
|
|
|
|
conversion_rate_label, currency, company_currency))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_taxes_and_charges(tax):
|
|
|
|
|
if tax.charge_type in ['Actual', 'On Net Total'] and tax.row_id:
|
|
|
|
|
frappe.throw(_("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"))
|
|
|
|
|
elif tax.charge_type in ['On Previous Row Amount', 'On Previous Row Total']:
|
|
|
|
|
if cint(tax.idx) == 1:
|
|
|
|
|
frappe.throw(_("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"))
|
|
|
|
|
frappe.throw(
|
|
|
|
|
_("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"))
|
|
|
|
|
elif not tax.row_id:
|
|
|
|
|
frappe.throw(_("Please specify a valid Row ID for row {0} in table {1}".format(tax.idx, _(tax.doctype))))
|
|
|
|
|
elif tax.row_id and cint(tax.row_id) >= cint(tax.idx):
|
|
|
|
@ -832,6 +850,7 @@ def validate_taxes_and_charges(tax):
|
|
|
|
|
if tax.charge_type == "Actual":
|
|
|
|
|
tax.rate = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_inclusive_tax(tax, doc):
|
|
|
|
|
def _on_previous_row_error(row_range):
|
|
|
|
|
throw(_("To include tax in row {0} in Item rate, taxes in rows {1} must also be included").format(tax.idx,
|
|
|
|
@ -852,28 +871,28 @@ def validate_inclusive_tax(tax, doc):
|
|
|
|
|
elif tax.get("category") == "Valuation":
|
|
|
|
|
frappe.throw(_("Valuation type charges can not marked as Inclusive"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_balance_in_account_currency(gl_dict, account_currency=None, conversion_rate=None, company_currency=None):
|
|
|
|
|
if (not conversion_rate) and (account_currency!=company_currency):
|
|
|
|
|
if (not conversion_rate) and (account_currency != company_currency):
|
|
|
|
|
frappe.throw(_("Account: {0} with currency: {1} can not be selected")
|
|
|
|
|
.format(gl_dict.account, account_currency))
|
|
|
|
|
|
|
|
|
|
gl_dict["account_currency"] = company_currency if account_currency==company_currency \
|
|
|
|
|
gl_dict["account_currency"] = company_currency if account_currency == company_currency \
|
|
|
|
|
else account_currency
|
|
|
|
|
|
|
|
|
|
# set debit/credit in account currency if not provided
|
|
|
|
|
if flt(gl_dict.debit) and not flt(gl_dict.debit_in_account_currency):
|
|
|
|
|
gl_dict.debit_in_account_currency = gl_dict.debit if account_currency==company_currency \
|
|
|
|
|
gl_dict.debit_in_account_currency = gl_dict.debit if account_currency == company_currency \
|
|
|
|
|
else flt(gl_dict.debit / conversion_rate, 2)
|
|
|
|
|
|
|
|
|
|
if flt(gl_dict.credit) and not flt(gl_dict.credit_in_account_currency):
|
|
|
|
|
gl_dict.credit_in_account_currency = gl_dict.credit if account_currency==company_currency \
|
|
|
|
|
gl_dict.credit_in_account_currency = gl_dict.credit if account_currency == company_currency \
|
|
|
|
|
else flt(gl_dict.credit / conversion_rate, 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_advance_journal_entries(party_type, party, party_account, amount_field,
|
|
|
|
|
order_doctype, order_list, include_unallocated=True):
|
|
|
|
|
|
|
|
|
|
dr_or_cr = "credit_in_account_currency" if party_type=="Customer" else "debit_in_account_currency"
|
|
|
|
|
dr_or_cr = "credit_in_account_currency" if party_type == "Customer" else "debit_in_account_currency"
|
|
|
|
|
|
|
|
|
|
conditions = []
|
|
|
|
|
if include_unallocated:
|
|
|
|
@ -881,7 +900,7 @@ def get_advance_journal_entries(party_type, party, party_account, amount_field,
|
|
|
|
|
|
|
|
|
|
if order_list:
|
|
|
|
|
order_condition = ', '.join(['%s'] * len(order_list))
|
|
|
|
|
conditions.append(" (t2.reference_type = '{0}' and ifnull(t2.reference_name, '') in ({1}))"\
|
|
|
|
|
conditions.append(" (t2.reference_type = '{0}' and ifnull(t2.reference_name, '') in ({1}))" \
|
|
|
|
|
.format(order_doctype, order_condition))
|
|
|
|
|
|
|
|
|
|
reference_condition = " and (" + " or ".join(conditions) + ")" if conditions else ""
|
|
|
|
@ -903,6 +922,7 @@ def get_advance_journal_entries(party_type, party, party_account, amount_field,
|
|
|
|
|
|
|
|
|
|
return list(journal_entries)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_advance_payment_entries(party_type, party, party_account,
|
|
|
|
|
order_doctype, order_list=None, include_unallocated=True, against_all_orders=False):
|
|
|
|
|
party_account_field = "paid_from" if party_type == "Customer" else "paid_to"
|
|
|
|
@ -911,7 +931,7 @@ def get_advance_payment_entries(party_type, party, party_account,
|
|
|
|
|
|
|
|
|
|
if order_list or against_all_orders:
|
|
|
|
|
if order_list:
|
|
|
|
|
reference_condition = " and t2.reference_name in ({0})"\
|
|
|
|
|
reference_condition = " and t2.reference_name in ({0})" \
|
|
|
|
|
.format(', '.join(['%s'] * len(order_list)))
|
|
|
|
|
else:
|
|
|
|
|
reference_condition = ""
|
|
|
|
@ -929,7 +949,8 @@ def get_advance_payment_entries(party_type, party, party_account,
|
|
|
|
|
and t2.reference_doctype = %s {1}
|
|
|
|
|
order by t1.posting_date
|
|
|
|
|
""".format(party_account_field, reference_condition),
|
|
|
|
|
[party_account, payment_type, party_type, party, order_doctype] + order_list, as_dict=1)
|
|
|
|
|
[party_account, payment_type, party_type, party,
|
|
|
|
|
order_doctype] + order_list, as_dict=1)
|
|
|
|
|
|
|
|
|
|
if include_unallocated:
|
|
|
|
|
unallocated_payment_entries = frappe.db.sql("""
|
|
|
|
@ -944,6 +965,7 @@ def get_advance_payment_entries(party_type, party, party_account,
|
|
|
|
|
|
|
|
|
|
return list(payment_entries_against_order) + list(unallocated_payment_entries)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_invoice_status():
|
|
|
|
|
# Daily update the status of the invoices
|
|
|
|
|
|
|
|
|
@ -953,6 +975,7 @@ def update_invoice_status():
|
|
|
|
|
frappe.db.sql(""" update `tabPurchase Invoice` set status = 'Overdue'
|
|
|
|
|
where due_date < CURDATE() and docstatus = 1 and outstanding_amount > 0""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist()
|
|
|
|
|
def get_payment_terms(terms_template, posting_date=None, grand_total=None, bill_date=None):
|
|
|
|
|
if not terms_template:
|
|
|
|
@ -967,6 +990,7 @@ def get_payment_terms(terms_template, posting_date=None, grand_total=None, bill_
|
|
|
|
|
|
|
|
|
|
return schedule
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist()
|
|
|
|
|
def get_payment_term_details(term, posting_date=None, grand_total=None, bill_date=None):
|
|
|
|
|
term_details = frappe._dict()
|
|
|
|
@ -988,6 +1012,7 @@ def get_payment_term_details(term, posting_date=None, grand_total=None, bill_dat
|
|
|
|
|
|
|
|
|
|
return term_details
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_due_date(term, posting_date=None, bill_date=None):
|
|
|
|
|
due_date = None
|
|
|
|
|
date = bill_date or posting_date
|
|
|
|
@ -1013,3 +1038,56 @@ def get_supplier_block_status(party_name):
|
|
|
|
|
}
|
|
|
|
|
return info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist()
|
|
|
|
|
def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name):
|
|
|
|
|
data = json.loads(trans_items)
|
|
|
|
|
for d in data:
|
|
|
|
|
child_item = frappe.get_doc(parent_doctype + ' Item', d.get("docname"))
|
|
|
|
|
child_item.qty = flt(d.get("qty"))
|
|
|
|
|
|
|
|
|
|
if child_item.billed_amt > (flt(d.get("rate")) * flt(d.get("qty"))):
|
|
|
|
|
frappe.throw(_("Row #{0}: Cannot set Rate if amount is greater than billed amount for Item {1}.")
|
|
|
|
|
.format(child_item.idx, child_item.item_code))
|
|
|
|
|
else:
|
|
|
|
|
child_item.rate = flt(d.get("rate"))
|
|
|
|
|
child_item.flags.ignore_validate_update_after_submit = True
|
|
|
|
|
child_item.save()
|
|
|
|
|
|
|
|
|
|
p_doctype = frappe.get_doc(parent_doctype, parent_doctype_name)
|
|
|
|
|
|
|
|
|
|
p_doctype.flags.ignore_validate_update_after_submit = True
|
|
|
|
|
p_doctype.set_qty_as_per_stock_uom()
|
|
|
|
|
p_doctype.calculate_taxes_and_totals()
|
|
|
|
|
frappe.get_doc('Authorization Control').validate_approving_authority(p_doctype.doctype,
|
|
|
|
|
p_doctype.company, p_doctype.base_grand_total)
|
|
|
|
|
|
|
|
|
|
p_doctype.set_payment_schedule()
|
|
|
|
|
if parent_doctype == 'Purchase Order':
|
|
|
|
|
p_doctype.validate_minimum_order_qty()
|
|
|
|
|
p_doctype.validate_budget()
|
|
|
|
|
if p_doctype.is_against_so():
|
|
|
|
|
p_doctype.update_status_updater()
|
|
|
|
|
else:
|
|
|
|
|
p_doctype.check_credit_limit()
|
|
|
|
|
|
|
|
|
|
p_doctype.save()
|
|
|
|
|
|
|
|
|
|
if parent_doctype == 'Purchase Order':
|
|
|
|
|
update_last_purchase_rate(p_doctype, is_submit = 1)
|
|
|
|
|
p_doctype.update_prevdoc_status()
|
|
|
|
|
p_doctype.update_requested_qty()
|
|
|
|
|
p_doctype.update_ordered_qty()
|
|
|
|
|
p_doctype.update_ordered_and_reserved_qty()
|
|
|
|
|
p_doctype.update_receiving_percentage()
|
|
|
|
|
if p_doctype.is_subcontracted == "Yes":
|
|
|
|
|
p_doctype.update_reserved_qty_for_subcontract()
|
|
|
|
|
else:
|
|
|
|
|
p_doctype.update_reserved_qty()
|
|
|
|
|
p_doctype.update_project()
|
|
|
|
|
p_doctype.update_prevdoc_status('submit')
|
|
|
|
|
p_doctype.update_delivery_status()
|
|
|
|
|
|
|
|
|
|
p_doctype.update_blanket_order()
|
|
|
|
|
p_doctype.update_billing_percentage()
|
|
|
|
|
p_doctype.set_status()
|
|
|
|
|