mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 08:54:45 +00:00
[buying, selling] [refactor] get item details
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes import msgprint, _
|
||||
from webnotes.utils import load_json, cstr, flt, now_datetime
|
||||
from webnotes.model.doc import addchild
|
||||
|
||||
@@ -268,4 +269,42 @@ class TransactionBase(DocListController):
|
||||
def validate_posting_time(self):
|
||||
if not self.doc.posting_time:
|
||||
self.doc.posting_time = now_datetime().strftime('%H:%M:%S')
|
||||
|
||||
|
||||
def validate_conversion_rate(currency, conversion_rate, conversion_rate_label, company):
|
||||
"""common validation for currency and price list currency"""
|
||||
if conversion_rate == 0:
|
||||
msgprint(conversion_rate_label + _(' cannot be 0'), raise_exception=True)
|
||||
|
||||
company_currency = webnotes.conn.get_value("Company", company, "default_currency")
|
||||
|
||||
# parenthesis for 'OR' are necessary as we want it to evaluate as
|
||||
# mandatory valid condition and (1st optional valid condition
|
||||
# or 2nd optional valid condition)
|
||||
valid_conversion_rate = (conversion_rate and
|
||||
((currency == company_currency and conversion_rate == 1.00)
|
||||
or (currency != company_currency and conversion_rate != 1.00)))
|
||||
|
||||
if not valid_conversion_rate:
|
||||
msgprint(_('Please enter valid ') + conversion_rate_label + (': ')
|
||||
+ ("1 %s = [?] %s" % (currency, company_currency)),
|
||||
raise_exception=True)
|
||||
|
||||
def validate_item_fetch(args, item):
|
||||
from stock.utils import validate_end_of_life
|
||||
validate_end_of_life(item.name, item.end_of_life)
|
||||
|
||||
# validate company
|
||||
if not args.company:
|
||||
msgprint(_("Please specify Company"), raise_exception=True)
|
||||
|
||||
# validate conversion rates
|
||||
meta = webnotes.get_doctype(args.doctype)
|
||||
if meta.get_field("currency"):
|
||||
# validate conversion rate
|
||||
validate_conversion_rate(args.currency, args.conversion_rate,
|
||||
meta.get_label("conversion_rate"), args.company)
|
||||
|
||||
# validate price list conversion rate
|
||||
if args.price_list_name and args.price_list_currency:
|
||||
validate_conversion_rate(args.price_list_currency, args.plc_conversion_rate,
|
||||
meta.get_label("plc_conversion_rate"), args.company)
|
||||
Reference in New Issue
Block a user