mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-21 22:19:18 +00:00
space to tabs
This commit is contained in:
@@ -17,48 +17,48 @@ from frappe.utils import nowdate
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_pos_data():
|
def get_pos_data():
|
||||||
doc = frappe.new_doc('Sales Invoice')
|
doc = frappe.new_doc('Sales Invoice')
|
||||||
doc.is_pos = 1
|
doc.is_pos = 1
|
||||||
pos_profile = get_pos_profile(doc.company) or {}
|
pos_profile = get_pos_profile(doc.company) or {}
|
||||||
if not pos_profile:
|
if not pos_profile:
|
||||||
frappe.throw(_("POS Profile is required to use Point-of-Sale"))
|
frappe.throw(_("POS Profile is required to use Point-of-Sale"))
|
||||||
|
|
||||||
if not doc.company:
|
if not doc.company:
|
||||||
doc.company = pos_profile.get('company')
|
doc.company = pos_profile.get('company')
|
||||||
|
|
||||||
doc.update_stock = pos_profile.get('update_stock')
|
doc.update_stock = pos_profile.get('update_stock')
|
||||||
|
|
||||||
if pos_profile.get('name'):
|
if pos_profile.get('name'):
|
||||||
pos_profile = frappe.get_doc('POS Profile', pos_profile.get('name'))
|
pos_profile = frappe.get_doc('POS Profile', pos_profile.get('name'))
|
||||||
pos_profile.validate()
|
pos_profile.validate()
|
||||||
|
|
||||||
company_data = get_company_data(doc.company)
|
company_data = get_company_data(doc.company)
|
||||||
update_pos_profile_data(doc, pos_profile, company_data)
|
update_pos_profile_data(doc, pos_profile, company_data)
|
||||||
update_multi_mode_option(doc, pos_profile)
|
update_multi_mode_option(doc, pos_profile)
|
||||||
default_print_format = pos_profile.get('print_format') or "Point of Sale"
|
default_print_format = pos_profile.get('print_format') or "Point of Sale"
|
||||||
print_template = frappe.db.get_value('Print Format', default_print_format, 'html')
|
print_template = frappe.db.get_value('Print Format', default_print_format, 'html')
|
||||||
items_list = get_items_list(pos_profile)
|
items_list = get_items_list(pos_profile)
|
||||||
customers = get_customers_list(pos_profile)
|
customers = get_customers_list(pos_profile)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'doc': doc,
|
'doc': doc,
|
||||||
'default_customer': pos_profile.get('customer'),
|
'default_customer': pos_profile.get('customer'),
|
||||||
'items': items_list,
|
'items': items_list,
|
||||||
'item_groups': get_item_groups(pos_profile),
|
'item_groups': get_item_groups(pos_profile),
|
||||||
'customers': customers,
|
'customers': customers,
|
||||||
'address': get_customers_address(customers),
|
'address': get_customers_address(customers),
|
||||||
'contacts': get_contacts(customers),
|
'contacts': get_contacts(customers),
|
||||||
'serial_no_data': get_serial_no_data(pos_profile, doc.company),
|
'serial_no_data': get_serial_no_data(pos_profile, doc.company),
|
||||||
'batch_no_data': get_batch_no_data(),
|
'batch_no_data': get_batch_no_data(),
|
||||||
'barcode_data': get_barcode_data(items_list),
|
'barcode_data': get_barcode_data(items_list),
|
||||||
'tax_data': get_item_tax_data(),
|
'tax_data': get_item_tax_data(),
|
||||||
'price_list_data': get_price_list_data(doc.selling_price_list),
|
'price_list_data': get_price_list_data(doc.selling_price_list),
|
||||||
'bin_data': get_bin_data(pos_profile),
|
'bin_data': get_bin_data(pos_profile),
|
||||||
'pricing_rules': get_pricing_rule_data(doc),
|
'pricing_rules': get_pricing_rule_data(doc),
|
||||||
'print_template': print_template,
|
'print_template': print_template,
|
||||||
'pos_profile': pos_profile,
|
'pos_profile': pos_profile,
|
||||||
'meta': get_meta()
|
'meta': get_meta()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_meta():
|
def get_meta():
|
||||||
@@ -68,7 +68,7 @@ def get_meta():
|
|||||||
}
|
}
|
||||||
|
|
||||||
for row in frappe.get_all('DocField', fields=['fieldname', 'options'],
|
for row in frappe.get_all('DocField', fields=['fieldname', 'options'],
|
||||||
filters={'parent': 'Sales Invoice', 'fieldtype': 'Table'}):
|
filters={'parent': 'Sales Invoice', 'fieldtype': 'Table'}):
|
||||||
doctype_meta[row.fieldname] = frappe.get_meta(row.options)
|
doctype_meta[row.fieldname] = frappe.get_meta(row.options)
|
||||||
|
|
||||||
return doctype_meta
|
return doctype_meta
|
||||||
@@ -106,7 +106,7 @@ def update_pos_profile_data(doc, pos_profile, company_data):
|
|||||||
doc.customer_group = pos_profile.get('customer_group') or get_root('Customer Group')
|
doc.customer_group = pos_profile.get('customer_group') or get_root('Customer Group')
|
||||||
doc.territory = pos_profile.get('territory') or get_root('Territory')
|
doc.territory = pos_profile.get('territory') or get_root('Territory')
|
||||||
doc.terms = frappe.db.get_value('Terms and Conditions', pos_profile.get(
|
doc.terms = frappe.db.get_value('Terms and Conditions', pos_profile.get(
|
||||||
'tc_name'), 'terms') or doc.terms or ''
|
'tc_name'), 'terms') or doc.terms or ''
|
||||||
doc.offline_pos_name = ''
|
doc.offline_pos_name = ''
|
||||||
|
|
||||||
|
|
||||||
@@ -140,8 +140,8 @@ def update_multi_mode_option(doc, pos_profile):
|
|||||||
|
|
||||||
|
|
||||||
def get_mode_of_payment(doc):
|
def get_mode_of_payment(doc):
|
||||||
return frappe.db.sql(""" select mpa.default_account, mpa.parent, mp.type as type from `tabMode of Payment Account` mpa,
|
return frappe.db.sql(""" select mpa.default_account, mpa.parent, mp.type as type from `tabMode of Payment Account` mpa, \
|
||||||
`tabMode of Payment` mp where mpa.parent = mp.name and mpa.company = %(company)s""", {'company': doc.company}, as_dict=1)
|
`tabMode of Payment` mp where mpa.parent = mp.name and mpa.company = %(company)s""", {'company': doc.company}, as_dict=1)
|
||||||
|
|
||||||
|
|
||||||
def update_tax_table(doc):
|
def update_tax_table(doc):
|
||||||
@@ -206,7 +206,8 @@ def get_customers_address(customers):
|
|||||||
(select parent from `tabDynamic Link` where link_doctype = 'Customer' and link_name = %s
|
(select parent from `tabDynamic Link` where link_doctype = 'Customer' and link_name = %s
|
||||||
and parenttype = 'Address')""", data.name, as_dict=1)
|
and parenttype = 'Address')""", data.name, as_dict=1)
|
||||||
address_data = {}
|
address_data = {}
|
||||||
if address: address_data = address[0]
|
if address:
|
||||||
|
address_data = address[0]
|
||||||
|
|
||||||
address_data.update({'full_name': data.customer_name, 'customer_pos_id': data.customer_pos_id})
|
address_data.update({'full_name': data.customer_name, 'customer_pos_id': data.customer_pos_id})
|
||||||
customer_address[data.name] = address_data
|
customer_address[data.name] = address_data
|
||||||
@@ -275,27 +276,27 @@ def get_batch_no_data():
|
|||||||
|
|
||||||
|
|
||||||
def get_barcode_data(items_list):
|
def get_barcode_data(items_list):
|
||||||
# get itemwise batch no data
|
# get itemwise batch no data
|
||||||
# exmaple: {'LED-GRE': [Batch001, Batch002]}
|
# exmaple: {'LED-GRE': [Batch001, Batch002]}
|
||||||
# where LED-GRE is item code, SN0001 is serial no and Pune is warehouse
|
# where LED-GRE is item code, SN0001 is serial no and Pune is warehouse
|
||||||
|
|
||||||
itemwise_barcode = {}
|
itemwise_barcode = {}
|
||||||
for item in items_list:
|
for item in items_list:
|
||||||
barcodes = frappe.db.sql("""
|
barcodes = frappe.db.sql("""
|
||||||
select barcode from `tabItem Barcode` where parent = '{0}'
|
select barcode from `tabItem Barcode` where parent = '{0}'
|
||||||
""".format(item.item_code), as_dict=1)
|
""".format(item.item_code), as_dict=1)
|
||||||
|
|
||||||
for barcode in barcodes:
|
for barcode in barcodes:
|
||||||
if item.item_code not in itemwise_barcode:
|
if item.item_code not in itemwise_barcode:
|
||||||
itemwise_barcode.setdefault(item.item_code, [])
|
itemwise_barcode.setdefault(item.item_code, [])
|
||||||
itemwise_barcode[item.item_code].append(barcode)
|
itemwise_barcode[item.item_code].append(barcode)
|
||||||
|
|
||||||
return itemwise_barcode
|
return itemwise_barcode
|
||||||
|
|
||||||
|
|
||||||
def get_item_tax_data():
|
def get_item_tax_data():
|
||||||
# get default tax of an item
|
# get default tax of an item
|
||||||
# example: {'Consulting Services': {'Excise 12 - TS': '12.000'}}
|
# example: {'Consulting Services': {'Excise 12 - TS': '12.000'}}
|
||||||
|
|
||||||
itemwise_tax = {}
|
itemwise_tax = {}
|
||||||
taxes = frappe.db.sql(""" select parent, tax_type, tax_rate from `tabItem Tax`""", as_dict=1)
|
taxes = frappe.db.sql(""" select parent, tax_type, tax_rate from `tabItem Tax`""", as_dict=1)
|
||||||
@@ -307,17 +308,19 @@ def get_item_tax_data():
|
|||||||
|
|
||||||
return itemwise_tax
|
return itemwise_tax
|
||||||
|
|
||||||
|
|
||||||
def get_price_list_data(selling_price_list):
|
def get_price_list_data(selling_price_list):
|
||||||
itemwise_price_list = {}
|
itemwise_price_list = {}
|
||||||
price_lists = frappe.db.sql("""Select ifnull(price_list_rate, 0) as price_list_rate,
|
price_lists = frappe.db.sql("""Select ifnull(price_list_rate, 0) as price_list_rate,
|
||||||
item_code from `tabItem Price` ip where price_list = %(price_list)s""",
|
item_code from `tabItem Price` ip where price_list = %(price_list)s""",
|
||||||
{'price_list': selling_price_list}, as_dict=1)
|
{'price_list': selling_price_list}, as_dict=1)
|
||||||
|
|
||||||
for item in price_lists:
|
for item in price_lists:
|
||||||
itemwise_price_list[item.item_code] = item.price_list_rate
|
itemwise_price_list[item.item_code] = item.price_list_rate
|
||||||
|
|
||||||
return itemwise_price_list
|
return itemwise_price_list
|
||||||
|
|
||||||
|
|
||||||
def get_bin_data(pos_profile):
|
def get_bin_data(pos_profile):
|
||||||
itemwise_bin_data = {}
|
itemwise_bin_data = {}
|
||||||
cond = "1=1"
|
cond = "1=1"
|
||||||
@@ -334,6 +337,7 @@ def get_bin_data(pos_profile):
|
|||||||
|
|
||||||
return itemwise_bin_data
|
return itemwise_bin_data
|
||||||
|
|
||||||
|
|
||||||
def get_pricing_rule_data(doc):
|
def get_pricing_rule_data(doc):
|
||||||
pricing_rules = ""
|
pricing_rules = ""
|
||||||
if doc.ignore_pricing_rule == 0:
|
if doc.ignore_pricing_rule == 0:
|
||||||
@@ -342,9 +346,10 @@ def get_pricing_rule_data(doc):
|
|||||||
and ifnull(company, '') in (%(company)s, '') and disable = 0 and %(date)s
|
and ifnull(company, '') in (%(company)s, '') and disable = 0 and %(date)s
|
||||||
between ifnull(valid_from, '2000-01-01') and ifnull(valid_upto, '2500-12-31')
|
between ifnull(valid_from, '2000-01-01') and ifnull(valid_upto, '2500-12-31')
|
||||||
order by priority desc, name desc""",
|
order by priority desc, name desc""",
|
||||||
{'company': doc.company, 'price_list': doc.selling_price_list, 'date': nowdate()}, as_dict=1)
|
{'company': doc.company, 'price_list': doc.selling_price_list, 'date': nowdate()}, as_dict=1)
|
||||||
return pricing_rules
|
return pricing_rules
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_invoice(doc_list={}, email_queue_list={}, customers_list={}):
|
def make_invoice(doc_list={}, email_queue_list={}, customers_list={}):
|
||||||
if isinstance(doc_list, basestring):
|
if isinstance(doc_list, basestring):
|
||||||
@@ -383,14 +388,16 @@ def make_invoice(doc_list={}, email_queue_list={}, customers_list={}):
|
|||||||
'synced_contacts': get_contacts(customers)
|
'synced_contacts': get_contacts(customers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def validate_records(doc):
|
def validate_records(doc):
|
||||||
validate_item(doc)
|
validate_item(doc)
|
||||||
|
|
||||||
|
|
||||||
def get_customer_id(doc, customer=None):
|
def get_customer_id(doc, customer=None):
|
||||||
cust_id = None
|
cust_id = None
|
||||||
if doc.get('customer_pos_id'):
|
if doc.get('customer_pos_id'):
|
||||||
cust_id = frappe.db.get_value('Customer',
|
cust_id = frappe.db.get_value('Customer',
|
||||||
{'customer_pos_id': doc.get('customer_pos_id')}, 'name')
|
{'customer_pos_id': doc.get('customer_pos_id')}, 'name')
|
||||||
|
|
||||||
if not cust_id:
|
if not cust_id:
|
||||||
customer = customer or doc.get('customer')
|
customer = customer or doc.get('customer')
|
||||||
@@ -401,6 +408,7 @@ def get_customer_id(doc, customer=None):
|
|||||||
|
|
||||||
return cust_id
|
return cust_id
|
||||||
|
|
||||||
|
|
||||||
def make_customer_and_address(customers):
|
def make_customer_and_address(customers):
|
||||||
customers_list = []
|
customers_list = []
|
||||||
for customer, data in customers.items():
|
for customer, data in customers.items():
|
||||||
@@ -417,6 +425,7 @@ def make_customer_and_address(customers):
|
|||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
return customers_list
|
return customers_list
|
||||||
|
|
||||||
|
|
||||||
def add_customer(data):
|
def add_customer(data):
|
||||||
customer_doc = frappe.new_doc('Customer')
|
customer_doc = frappe.new_doc('Customer')
|
||||||
customer_doc.customer_name = data.get('full_name') or data.get('customer')
|
customer_doc.customer_name = data.get('full_name') or data.get('customer')
|
||||||
@@ -425,28 +434,31 @@ def add_customer(data):
|
|||||||
customer_doc.customer_group = get_customer_group(data)
|
customer_doc.customer_group = get_customer_group(data)
|
||||||
customer_doc.territory = get_territory(data)
|
customer_doc.territory = get_territory(data)
|
||||||
customer_doc.flags.ignore_mandatory = True
|
customer_doc.flags.ignore_mandatory = True
|
||||||
customer_doc.save(ignore_permissions = True)
|
customer_doc.save(ignore_permissions=True)
|
||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
return customer_doc.name
|
return customer_doc.name
|
||||||
|
|
||||||
|
|
||||||
def get_territory(data):
|
def get_territory(data):
|
||||||
if data.get('territory'):
|
if data.get('territory'):
|
||||||
return data.get('territory')
|
return data.get('territory')
|
||||||
|
|
||||||
return frappe.db.get_single_value('Selling Settings',
|
return frappe.db.get_single_value('Selling Settings',
|
||||||
'territory') or _('All Territories')
|
'territory') or _('All Territories')
|
||||||
|
|
||||||
|
|
||||||
def get_customer_group(data):
|
def get_customer_group(data):
|
||||||
if data.get('customer_group'):
|
if data.get('customer_group'):
|
||||||
return data.get('customer_group')
|
return data.get('customer_group')
|
||||||
|
|
||||||
return frappe.db.get_single_value('Selling Settings',
|
return frappe.db.get_single_value('Selling Settings',
|
||||||
'customer_group') or frappe.db.get_value('Customer Group', {'is_group': 0}, 'name')
|
'customer_group') or frappe.db.get_value('Customer Group', {'is_group': 0}, 'name')
|
||||||
|
|
||||||
def make_contact(args,customer):
|
|
||||||
|
def make_contact(args, customer):
|
||||||
if args.get('email_id') or args.get('phone'):
|
if args.get('email_id') or args.get('phone'):
|
||||||
name = frappe.db.get_value('Dynamic Link',
|
name = frappe.db.get_value('Dynamic Link',
|
||||||
{'link_doctype': 'Customer', 'link_name': customer, 'parenttype': 'Contact'}, 'parent')
|
{'link_doctype': 'Customer', 'link_name': customer, 'parenttype': 'Contact'}, 'parent')
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
'first_name': args.get('full_name'),
|
'first_name': args.get('full_name'),
|
||||||
@@ -461,15 +473,17 @@ def make_contact(args,customer):
|
|||||||
doc.update(args)
|
doc.update(args)
|
||||||
doc.is_primary_contact = 1
|
doc.is_primary_contact = 1
|
||||||
if not name:
|
if not name:
|
||||||
doc.append('links',{
|
doc.append('links', {
|
||||||
'link_doctype': 'Customer',
|
'link_doctype': 'Customer',
|
||||||
'link_name': customer
|
'link_name': customer
|
||||||
})
|
})
|
||||||
doc.flags.ignore_mandatory = True
|
doc.flags.ignore_mandatory = True
|
||||||
doc.save(ignore_permissions=True)
|
doc.save(ignore_permissions=True)
|
||||||
|
|
||||||
|
|
||||||
def make_address(args, customer):
|
def make_address(args, customer):
|
||||||
if not args.get('address_line1'): return
|
if not args.get('address_line1'):
|
||||||
|
return
|
||||||
|
|
||||||
name = args.get('name')
|
name = args.get('name')
|
||||||
|
|
||||||
@@ -482,7 +496,7 @@ def make_address(args, customer):
|
|||||||
else:
|
else:
|
||||||
address = frappe.new_doc('Address')
|
address = frappe.new_doc('Address')
|
||||||
address.country = frappe.db.get_value('Company', args.get('company'), 'country')
|
address.country = frappe.db.get_value('Company', args.get('company'), 'country')
|
||||||
address.append('links',{
|
address.append('links', {
|
||||||
'link_doctype': 'Customer',
|
'link_doctype': 'Customer',
|
||||||
'link_name': customer
|
'link_name': customer
|
||||||
})
|
})
|
||||||
@@ -491,7 +505,8 @@ def make_address(args, customer):
|
|||||||
address.is_shipping_address = 1
|
address.is_shipping_address = 1
|
||||||
address.update(args)
|
address.update(args)
|
||||||
address.flags.ignore_mandatory = True
|
address.flags.ignore_mandatory = True
|
||||||
address.save(ignore_permissions = True)
|
address.save(ignore_permissions=True)
|
||||||
|
|
||||||
|
|
||||||
def make_email_queue(email_queue):
|
def make_email_queue(email_queue):
|
||||||
name_list = []
|
name_list = []
|
||||||
@@ -500,15 +515,16 @@ def make_email_queue(email_queue):
|
|||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
sender = frappe.session.user
|
sender = frappe.session.user
|
||||||
print_format = "POS Invoice"
|
print_format = "POS Invoice"
|
||||||
attachments = [frappe.attach_print('Sales Invoice', name, print_format= print_format)]
|
attachments = [frappe.attach_print('Sales Invoice', name, print_format=print_format)]
|
||||||
|
|
||||||
make(subject = data.get('subject'), content = data.get('content'), recipients = data.get('recipients'),
|
make(subject=data.get('subject'), content=data.get('content'), recipients=data.get('recipients'),
|
||||||
sender=sender,attachments = attachments, send_email=True,
|
sender=sender, attachments=attachments, send_email=True,
|
||||||
doctype='Sales Invoice', name=name)
|
doctype='Sales Invoice', name=name)
|
||||||
name_list.append(key)
|
name_list.append(key)
|
||||||
|
|
||||||
return name_list
|
return name_list
|
||||||
|
|
||||||
|
|
||||||
def validate_item(doc):
|
def validate_item(doc):
|
||||||
for item in doc.get('items'):
|
for item in doc.get('items'):
|
||||||
if not frappe.db.exists('Item', item.get('item_code')):
|
if not frappe.db.exists('Item', item.get('item_code')):
|
||||||
@@ -531,13 +547,15 @@ def submit_invoice(si_doc, name, doc, name_list):
|
|||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
name_list.append(name)
|
name_list.append(name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if frappe.message_log: frappe.message_log.pop()
|
if frappe.message_log:
|
||||||
|
frappe.message_log.pop()
|
||||||
frappe.db.rollback()
|
frappe.db.rollback()
|
||||||
frappe.log_error(frappe.get_traceback())
|
frappe.log_error(frappe.get_traceback())
|
||||||
name_list = save_invoice(doc, name, name_list)
|
name_list = save_invoice(doc, name, name_list)
|
||||||
|
|
||||||
return name_list
|
return name_list
|
||||||
|
|
||||||
|
|
||||||
def save_invoice(doc, name, name_list):
|
def save_invoice(doc, name, name_list):
|
||||||
try:
|
try:
|
||||||
if not frappe.db.exists('Sales Invoice', {'offline_pos_name': name}):
|
if not frappe.db.exists('Sales Invoice', {'offline_pos_name': name}):
|
||||||
|
|||||||
Reference in New Issue
Block a user