<commit_before># ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import webnotes
from webnotes.utils import load_json, cint, cstr, flt, get_defaults
from webnotes.model.doc import Document, addchild, removechild, getchildren
from webnotes.model.doclist import getlist, copy_doclist
from webnotes import msgprint

class TransactionBase:

	# Get Customer Default Primary Address - first load
	# -----------------------
	def get_default_customer_address(self, args=''):
		address_text, address_name = self.get_address_text(customer=self.doc.customer)
		contact_text, contact_name, contact_email, contact_mobile = self.get_contact_text(customer=self.doc.customer)
		self.doc.customer_address = address_name or ''
		self.doc.contact_person = contact_name or ''
		self.doc.address_display = address_text or ''
		self.doc.contact_display = contact_text or ''
		self.doc.contact_email = contact_email or ''
		self.doc.contact_mobile = contact_mobile or ''
	
		self.get_customer_details(self.doc.customer)
		if args != 'onload':
			self.get_sales_person(self.doc.customer)
		
	# Get Customer Default Shipping Address - first load
	# -----------------------
	def get_default_customer_shipping_address(self, args=''):		
		address_text, address_name = self.get_address_text(customer=self.doc.customer,is_shipping_address=1)
		contact_text, contact_name, contact_email, contact_mobile = self.get_contact_text(customer=self.doc.customer)		
		self.doc.customer_address = address_name or ''
		self.doc.contact_person = contact_name or ''
		self.doc.address_display = address_text or ''
		self.doc.contact_display = contact_text or ''
		self.doc.contact_email = contact_email or ''
		self.doc.contact_mobile = contact_mobile or ''
		
		self.get_customer_details(self.doc.customer)
		if self.doc.doctype != 'Quotation' and args != 'onload':
			self.get_sales_person(self.doc.customer)			

	# Get Customer Address
	# -----------------------
	def get_customer_address(self, args):
		args = load_json(args)		
		address_text, address_name = self.get_address_text(address_name=args['address'])
		contact_text, contact_name, contact_email, contact_mobile = self.get_contact_text(contact_name=args['contact'])
		ret = {
			'customer_address' : address_name,
			'contact_person' : contact_name,
			'address_display' : address_text,
			'contact_display' : contact_text,
			'contact_email' : contact_email,
			'contact_mobile' : contact_mobile
		}
		return ret	
			
	# Get Address Text
	# -----------------------
	def get_address_text(self, customer=None, address_name=None, supplier=None, is_shipping_address=None):
		if customer:
			cond = customer and 'customer="%s"' % customer or 'name="%s"' % address_name
		elif supplier:
			cond = supplier and 'supplier="%s"' % supplier or 'name="%s"' % address_name	
		else:
			cond = 'name="%s"' % address_name	

		if is_shipping_address:
			details = webnotes.conn.sql("select name, address_line1, address_line2, city, country, pincode, state, phone from `tabAddress` where %s and docstatus != 2 order by is_shipping_address desc limit 1" % cond, as_dict = 1)
		else:
			details = webnotes.conn.sql("select name, address_line1, address_line2, city, country, pincode, state, phone from `tabAddress` where %s and docstatus != 2 order by is_primary_address desc limit 1" % cond, as_dict = 1)
		
		extract = lambda x: details and details[0] and details[0].get(x,'') or ''
		address_fields = [('','address_line1'),('\n','address_line2'),('\n','city'),(' ','pincode'),('\n','state'),('\n','country'),('\nPhone: ','phone')]
		address_display = ''.join([a[0]+extract(a[1]) for a in address_fields if extract(a[1])])
		if address_display.startswith('\n'): address_display = address_display[1:]		

		address_name = details and details[0]['name'] or ''
		return address_display, address_name

	# Get Contact Text
	# -----------------------
	def get_contact_text(self, customer=None, contact_name=None, supplier=None):
		if customer:
			cond = customer and 'customer="%s"' % customer or 'name="%s"' % contact_name
		elif supplier:
			cond = supplier and 'supplier="%s"' % supplier or 'name="%s"' % contact_name
		else:<commit_msg>fax added in address display<commit_after># ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import webnotes
from webnotes.utils import load_json, cint, cstr, flt, get_defaults
from webnotes.model.doc import Document, addchild, removechild, getchildren
from webnotes.model.doclist import getlist, copy_doclist
from webnotes import msgprint

class TransactionBase:

	# Get Customer Default Primary Address - first load
	# -----------------------
	def get_default_customer_address(self, args=''):
		address_text, address_name = self.get_address_text(customer=self.doc.customer)
		contact_text, contact_name, contact_email, contact_mobile = self.get_contact_text(customer=self.doc.customer)
		self.doc.customer_address = address_name or ''
		self.doc.contact_person = contact_name or ''
		self.doc.address_display = address_text or ''
		self.doc.contact_display = contact_text or ''
		self.doc.contact_email = contact_email or ''
		self.doc.contact_mobile = contact_mobile or ''
	
		self.get_customer_details(self.doc.customer)
		if args != 'onload':
			self.get_sales_person(self.doc.customer)
		
	# Get Customer Default Shipping Address - first load
	# -----------------------
	def get_default_customer_shipping_address(self, args=''):		
		address_text, address_name = self.get_address_text(customer=self.doc.customer,is_shipping_address=1)
		contact_text, contact_name, contact_email, contact_mobile = self.get_contact_text(customer=self.doc.customer)		
		self.doc.customer_address = address_name or ''
		self.doc.contact_person = contact_name or ''
		self.doc.address_display = address_text or ''
		self.doc.contact_display = contact_text or ''
		self.doc.contact_email = contact_email or ''
		self.doc.contact_mobile = contact_mobile or ''
		
		self.get_customer_details(self.doc.customer)
		if self.doc.doctype != 'Quotation' and args != 'onload':
			self.get_sales_person(self.doc.customer)			

	# Get Customer Address
	# -----------------------
	def get_customer_address(self, args):
		args = load_json(args)		
		address_text, address_name = self.get_address_text(address_name=args['address'])
		contact_text, contact_name, contact_email, contact_mobile = self.get_contact_text(contact_name=args['contact'])
		ret = {
			'customer_address' : address_name,
			'contact_person' : contact_name,
			'address_display' : address_text,
			'contact_display' : contact_text,
			'contact_email' : contact_email,
			'contact_mobile' : contact_mobile
		}
		return ret	
			
	# Get Address Text
	# -----------------------
	def get_address_text(self, customer=None, address_name=None, supplier=None, is_shipping_address=None):
		if customer:
			cond = customer and 'customer="%s"' % customer or 'name="%s"' % address_name
		elif supplier:
			cond = supplier and 'supplier="%s"' % supplier or 'name="%s"' % address_name	
		else:
			cond = 'name="%s"' % address_name	

		if is_shipping_address:
			details = webnotes.conn.sql("select name, address_line1, address_line2, city, country, pincode, state, phone, fax from `tabAddress` where %s and docstatus != 2 order by is_shipping_address desc limit 1" % cond, as_dict = 1)
		else:
			details = webnotes.conn.sql("select name, address_line1, address_line2, city, country, pincode, state, phone, fax from `tabAddress` where %s and docstatus != 2 order by is_primary_address desc limit 1" % cond, as_dict = 1)
		
		extract = lambda x: details and details[0] and details[0].get(x,'') or ''
		address_fields = [('','address_line1'),('\n','address_line2'),('\n','city'),(' ','pincode'),('\n','state'),('\n','country'),('\nPhone: ','phone'),('\nFax: ', 'fax')]
		address_display = ''.join([a[0]+extract(a[1]) for a in address_fields if extract(a[1])])
		if address_display.startswith('\n'): address_display = address_display[1:]		

		address_name = details and details[0]['name'] or ''
		return address_display, address_name

	# Get Contact Text
	# -----------------------
	def get_contact_text(self, customer=None, contact_name=None, supplier=None):
		if customer:
			cond = customer and 'customer="%s"' % customer or 'name="%s"' % contact_name
		elif supplier:
			cond = supplier and 'supplier="%s"' % supplier or 'name="%s"' % contact_name
		else:
{'fraction_non_alphanumeric': 0.13578208832026414, 'fraction_numerical': 0.005158893933140734, 'mean_word_length': 4.390989988876529, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7470770', 'n_tokens_mistral': 3178, 'n_tokens_neox': 2950, 'n_words': 820}