blob: 41c97b8e5d81460f15bc14fcd00689b4739f7220 [file] [log] [blame]
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05301import webnotes
2
3from webnotes.model.doc import Document
4from webnotes.utils import load_json, cint, cstr
5from webnotes import msgprint, errprint
6
7def make_address():
8 from webnotes.modules.module_manager import reload_doc
Nabin Hait25ffe5b2011-07-28 13:49:03 +05309 reload_doc('utilities','doctype','address')
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053010
11 from webnotes.model.db_schema import updatedb
12 updatedb('Address')
13
14def make_address_from_customer():
15 for c in webnotes.conn.sql("select * from tabCustomer", as_dict=1):
16 d = Document('Address')
17 d.address_line1 = c['address_line1']
18 d.address_line2 = c['address_line2']
19 d.city = c['city']
20 d.country = c['country']
21 d.pincode = c['pincode']
22 d.state = c['state']
23 d.fax = c['fax_1']
24 d.email_id = c['email_id']
25 d.phone = c['phone_1']
26 d.customer = c['name']
27 d.customer_name = c['customer_name']
28 d.is_primary_address = 1
29 d.address_type = 'Office'
30 try:
31 d.save(1)
32 except NameError, e:
33 pass
34
35def make_address_from_supplier():
36 for c in webnotes.conn.sql("select * from tabSupplier", as_dict=1):
37 d = Document('Address')
38 d.address_line1 = c['address_line1']
39 d.address_line2 = c['address_line2']
40 d.city = c['city']
41 d.country = c['country']
42 d.pincode = c['pincode']
43 d.state = c['state']
44 d.supplier = c['name']
45 d.supplier_name = c['supplier_name']
46 d.is_primary_address = 1
47 d.address_type = 'Office'
48 try:
49 d.save(1)
50 except NameError, e:
51 pass
52
53def make_contact_from_contacttab():
54 webnotes.conn.sql("""
55 update ignore tabContact set
56 is_primary_contact = if(is_primary_contact='Yes',1,0)
57 """)
58
59 webnotes.conn.sql("""
60 update ignore tabContact t1, tabCustomer t2 set
61 t1.name = concat(ifnull(t1.contact_name,t1.name), '-', ifnull(t1.customer_name, t2.name))
62 where ifnull(t1.is_customer,0)=1
63 and t1.customer = t2.name
64 """)
65
66 webnotes.conn.sql("""
67 update ignore tabContact t1, tabSupplier t2 set
68 t1.name = concat(ifnull(t1.contact_name,t1.name), '-', ifnull(t1.supplier_name, t2.name))
69 where ifnull(t1.is_supplier,0)=1
70 and t1.supplier = t2.name
71 """)
72
73 webnotes.conn.sql("""
74 update ignore tabContact set
75 name = concat(ifnull(contact_name,name), '-', sales_partner)
76 where ifnull(is_sales_partner,0)=1
77 """)
78
79 webnotes.conn.commit()
80 try:
81 webnotes.conn.sql("""alter table tabContact change contact_no phone varchar(180)""")
82 webnotes.conn.sql("""alter table tabContact change is_primary_contact is_primary_contact int(1)""")
83 except:
84 pass
85 webnotes.conn.begin()
86
87def delete_unwanted_fields():
88 delete_fields = [
89 ('Contact', 'is_sales_partner'), ('Contact', 'sales_partner_address'), ('Contact', 'partner_type'), ('Contact', 'disable_login'), ('Contact', 'contact_address'), ('Contact', 'fax'), ('Contact', 'company_name'), ('Contact', 'contact_no'), ('Contact', 'customer_group'), ('Contact', 'has_login'), ('Contact', 'Create Login'), ('Contact', 'contact_name'), ('Contact', 'company_address'), ('Contact', 'customer_address'), ('Contact', 'supplier_address'), ('Contact', 'supplier_type'), ('Contact', 'is_customer'), ('Contact', 'is_supplier'), ('Contact', 'employee_id'), ('Contact', 'is_employee'),
90 ('Customer', 'region'), ('Customer', 'pincode'), ('Customer', 'city'), ('Customer', 'country'), ('Customer', 'state'), ('Customer', 'address'), ('Customer', 'telephone'), ('Customer', 'address_line2'), ('Customer', 'address_line1'), ('Customer', 'last_sales_order'), ('Customer', 'Shipping HTML'), ('Customer', 'phone_1'), ('Customer', 'Territory Help'), ('Customer', 'CG Help'), ('Customer', 'fax_1'), ('Customer', 'email_id'),
91 ('Customer Issue', 'email_id'), ('Customer Issue', 'contact_no'),
92 ('Delivery Note', 'customer_mobile_no'), ('Delivery Note', 'Send SMS'), ('Delivery Note', 'Get Other Charges'), ('Delivery Note', 'message'), ('Delivery Note', 'shipping_address'), ('Delivery Note', 'ship_to'), ('Delivery Note', 'ship_det_no'), ('Delivery Note', 'contact_no'), ('Delivery Note', 'Customer Details'), ('Delivery Note', 'email_id'), ('Delivery Note', 'delivery_address'), ('Delivery Note', 'Contact Help'), ('Delivery Note', 'Territory Help'),
93 ('Enquiry', 'address'), ('Enquiry', 'Send Email'), ('Enquiry', 'enquiry_attachment_detail'), ('Enquiry', 'contact_date_ref'), ('Enquiry', 'Update Follow up'), ('Enquiry', 'email_id1'), ('Enquiry', 'cc_to'), ('Enquiry', 'subject'), ('Enquiry', 'message'), ('Enquiry', 'Attachment Html'), ('Enquiry', 'Create New File'), ('Enquiry', 'contact_no'), ('Enquiry', 'email_id'), ('Enquiry', 'project'), ('Enquiry', 'update_follow_up'), ('Enquiry', 'Contact Help'),
94 ('Installation Note', 'address'),
95 ('Lead', 'message'), ('Lead', 'Send Email'), ('Lead', 'address'), ('Lead', 'subject'), ('Lead', 'contact_no'), ('Lead', 'TerritoryHelp'),
96 ('Maintenance Schedule', 'address'),
97 ('Maintenance Visit', 'address'),
98 ('Purchase Order', 'Contact Help'), ('Purchase Order', 'supplier_qtn'), ('Purchase Order', 'contact_no'), ('Purchase Order', 'email'),
99 ('Purchase Receipt', 'Contact Help'),
100 ('Quotation', 'email_id'), ('Quotation', 'contact_no'), ('Quotation', 'Update Follow up'), ('Quotation', 'contact_date_ref'), ('Quotation', 'Territory Help'), ('Quotation', 'Contact Help'),
101 ('Receivable Voucher', 'Territory Help'),
102 ('Sales Order', 'contact_no'), ('Sales Order', 'email_id'), ('Sales Order', 'Contact Help'), ('Sales Order', 'file_list'), ('Sales Order', 'ship_det_no'), ('Sales Order', 'mobile_no'), ('Sales Order', 'Territory Help'), ('Sales Order', 'ship_to'), ('Sales Order', 'Customer Details'),
103 ('Sales Partner', 'area_code'), ('Sales Partner', 'telephone'), ('Sales Partner', 'email'), ('Sales Partner', 'address'), ('Sales Partner', 'TerritoryHelp'), ('Sales Partner', 'pincode'), ('Sales Partner', 'country'), ('Sales Partner', 'city'), ('Sales Partner', 'address_line2'), ('Sales Partner', 'address_line1'), ('Sales Partner', 'mobile'), ('Sales Partner', 'state'),
104 ('Serial No', 'supplier_address'),
105 ('Supplier', 'city'), ('Supplier', 'country'), ('Supplier', 'state'), ('Supplier', 'address_line1'), ('Supplier', 'last_purchase_order'), ('Supplier', 'address'), ('Supplier', 'address_line2'), ('Supplier', 'pincode'), ('Supplier rating', 'address'), ('Supplier rating', 'select'), ('Supplier rating', 'supplier')]
106 for d in delete_fields:
107 webnotes.conn.sql("delete from tabDocField where parent=%s and if(ifnull(fieldname,'')='',ifnull(label,''),fieldname)=%s", (d[0], d[1]))
108
109#def gen_txt_files():
110# from webnotes.modules.export_module import export_to_files
111# for dt in ['Contact','Customer','Customer Issue','Delivery Note','Enquiry','Installation Note','Lead','Maintenance Schedule','Maintenance Visit','Purchase Order','Purchase Receipt','Quotation','Receivable Voucher','Sales Order','Sales Partner','Serial No','Supplier']:
112# export_to_files(record_list=[['DocType',dt]])
113
114def reload_doc_files():
115 from webnotes.modules.module_manager import reload_doc
Nabin Hait25ffe5b2011-07-28 13:49:03 +0530116 reload_doc('utilities', 'doctype', 'contact')
117 reload_doc('selling', 'doctype', 'customer')
118 reload_doc('support', 'doctype', 'customer_issue')
119 reload_doc('stock', 'doctype', 'delivery_note')
120 reload_doc('selling', 'doctype', 'enquiry')
121 reload_doc('selling', 'doctype', 'installation_note')
122 reload_doc('selling', 'doctype', 'lead')
123 reload_doc('support', 'doctype', 'maintenance_schedule')
124 reload_doc('support', 'doctype', 'maintenance_visit')
125 reload_doc('buying', 'doctype', 'purchase_order')
126 reload_doc('stock', 'doctype', 'purchase_receipt')
127 reload_doc('selling', 'doctype', 'quotation')
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530128 reload_doc('accounts', 'doctype', 'receivable_voucher')
129 reload_doc('accounts', 'doctype', 'payable_voucher')
Nabin Hait25ffe5b2011-07-28 13:49:03 +0530130 reload_doc('selling', 'doctype', 'sales_order')
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530131 reload_doc('setup', 'doctype', 'sales_partner')
Nabin Hait25ffe5b2011-07-28 13:49:03 +0530132 reload_doc('stock', 'doctype', 'serial_no')
133 reload_doc('buying', 'doctype', 'supplier')
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530134
135def reload_mapper_files():
136 from webnotes.modules.module_manager import reload_doc
137 reload_doc('Mapper', 'DocType Mapper', 'Customer Issue-Maintenance Visit')
138 reload_doc('Mapper', 'DocType Mapper', 'Delivery Note-Installation Note')
139 reload_doc('Mapper', 'DocType Mapper', 'Delivery Note-Receivable Voucher')
140 reload_doc('Mapper', 'DocType Mapper', 'Enquiry-Quotation')
141 reload_doc('Mapper', 'DocType Mapper', 'Lead-Customer')
142 reload_doc('Mapper', 'DocType Mapper', 'Lead-Enquiry')
143 reload_doc('Mapper', 'DocType Mapper', 'Purchase Order-Payable Voucher')
144 reload_doc('Mapper', 'DocType Mapper', 'Purchase Order-Purchase Receipt')
145 reload_doc('Mapper', 'DocType Mapper', 'Purchase Receipt-Payable Voucher')
146 reload_doc('Mapper', 'DocType Mapper', 'Quotation-Sales Order')
147 reload_doc('Mapper', 'DocType Mapper', 'Receivable Voucher-Delivery Note')
148 reload_doc('Mapper', 'DocType Mapper', 'Sales Order-Delivery Note')
149 reload_doc('Mapper', 'DocType Mapper', 'Sales Order-Maintenance Schedule')
150 reload_doc('Mapper', 'DocType Mapper', 'Sales Order-Maintenance Visit')
151 reload_doc('Mapper', 'DocType Mapper', 'Sales Order-Receivable Voucher')
152
153def delete_unwanted_mapper_fields():
154 delete_fields = [
155 ('Customer Issue-Maintenance Visit', 'customer_address', 'address'),
156 ('Delivery Note-Installation Note', 'customer_address', 'address'),
157 ('Enquiry-Quotation', 'contact_no', 'contact_no'), ('Enquiry-Quotation', 'subject', 'enq_det'), ('Enquiry-Quotation', 'customer_name', 'customer_name'), ('Enquiry-Quotation', 'customer_name', 'customer_name'), ('Enquiry-Quotation', 'address', 'customer_address'), ('Enquiry-Quotation', 'email_id', 'email_id'),
158 ('Quotation-Sales Order', 'contact_no', 'contact_no'), ('Quotation-Sales Order', 'email_id', 'email_id'), ('Quotation-Sales Order', 'customer_mobile_no', 'customer_mobile_no'),
159 ('Sales Order-Delivery Note', 'customer_address', 'delivery_address'), ('Sales Order-Delivery Note', 'customer_address', 'customer_address'), ('Sales Order-Delivery Note', 'contact_no', 'contact_no'), ('Sales Order-Delivery Note', 'email_id', 'email_id'), ('Sales Order-Delivery Note', 'ship_det_no', 'ship_det_no'), ('Sales Order-Delivery Note', 'ship_to', 'ship_to'), ('Sales Order-Delivery Note', 'shipping_address', 'shipping_address'), ('Sales Order-Delivery Note', 'customer_mobile_no', 'customer_mobile_no'),
160 ('Sales Order-Maintenance Schedule', 'customer_address', 'address'),
161 ('Sales Order-Maintenance Visit', 'customer_address', 'address'),
162 ('Sales Order-Receivable Voucher', 'contact_no', 'contact_no')]
163
164 for rec in delete_fields:
165 webnotes.conn.sql("delete from `tabField Mapper Detail` where parent=%s and from_field=%s and to_field=%s",(rec[0], rec[1], rec[2]))
166
167def sync_docfield_properties():
168 update_fields = [
169 ('Contact', 'customer', 'Customer', 0L, None, 0L, None), ('Contact', 'supplier', 'Supplier', 0L, None, None, None), ('Contact', 'is_primary_contact', None, 0L, None, None, None), ('Contact', 'email_id', None, 0L, 1L, None, None), ('Contact', 'department', 'Suggest', 0L, None, None, None), ('Contact', 'designation', 'Suggest', 0L, None, None, None),
170 ('Customer Issue', 'customer', 'Customer', 0L, 1L, 1L, None), ('Customer Issue', 'customer_address', 'Address', 0L, None, 1L, None), ('Customer Issue', 'contact_person', 'Contact', 0L, None, 1L, None), ('Customer Issue', 'customer_name', None, 1L, None, None, None), ('Customer Issue', 'company', 'Company', 0L, 1L, 1L, None), ('Customer Issue', 'fiscal_year', 'link:Fiscal Year', 0L, 1L, 1L, None),
171 ('Delivery Note', 'customer_address', 'Address', 0L, None, 1L, None), ('Delivery Note', 'contact_person', 'Contact', 0L, None, 1L, None), ('Delivery Note', 'customer_name', None, 1L, None, None, None), ('Delivery Note', 'status', '\nDraft\nSubmitted\nCancelled', 1L, 1L, 1L, None), ('Delivery Note', 'territory', 'Territory', 0L, 1L, 1L, 0L), ('Delivery Note', 'customer_group', 'Customer Group', 0L, None, 1L, None), ('Delivery Note', 'transporter_name', None, 0L, 0L, 1L, None), ('Delivery Note', 'lr_no', None, 0L, 0L, 1L, None), ('Delivery Note', 'lr_date', None, 0L, None, 1L, None), ('Delivery Note', 'currency', 'link:Currency', 0L, 1L, 1L, None), ('Delivery Note', 'letter_head', 'link:Letter Head', 0L, None, 1L, None),
172 ('Enquiry', 'contact_person', 'Contact', 0L, None, 1L, None), ('Enquiry', 'customer_name', None, 1L, None, 0L, None), ('Enquiry', 'lead', 'Lead', 0L, None, 1L, 0L), ('Enquiry', 'enquiry_type', '\nSales\nMaintenance', 0L, 1L, None, None), ('Enquiry', 'territory', 'Territory', 0L, 1L, 1L, None), ('Enquiry', 'customer_group', 'Customer Group', 0L, 0L, 1L, 0L), ('Enquiry', 'contact_by', 'Profile', 0L, None, None, None),
173 ('Installation Note', 'contact_person', 'Contact', 0L, None, 1L, None), ('Installation Note', 'customer_name', None, 1L, 0L, None, None), ('Installation Note', 'territory', 'Territory', 0L, 1L, 1L, None), ('Installation Note', 'status', 'Draft\nSubmitted\nCancelled', 1L, 1L, 1L, None),
174 ('Lead', 'city', None, 0L, 1L, 1L, None), ('Lead', 'country', 'link:Country', 0L, 1L, 1L, None), ('Lead', 'state', 'Suggest', 0L, None, 1L, None), ('Lead', 'company', 'Company', 0L, 1L, None, None), ('Lead', 'contact_by', 'Profile', 0L, 0L, 0L, 0L),
175 ('Maintenance Schedule', 'customer', 'Customer', 0L, 1L, 1L, None), ('Maintenance Schedule', 'contact_person', 'Contact', 0L, None, 1L, None), ('Maintenance Schedule', 'status', '\nDraft\nSubmitted\nCancelled', 1L, 1L, None, None), ('Maintenance Schedule', 'territory', 'Territory', 0L, 1L, None, None),
176 ('Maintenance Visit', 'customer', 'Customer', 0L, 1L, 1L, None), ('Maintenance Visit', 'contact_person', 'Contact', 0L, None, 1L, None), ('Maintenance Visit', 'customer_name', None, 1L, None, None, None), ('Maintenance Visit', 'company', 'link:Company', 0L, 1L, 1L, None), ('Maintenance Visit', 'fiscal_year', 'link:Fiscal Year', 0L, 1L, 1L, None), ('Maintenance Visit', 'status', '\nDraft\nCancelled\nSubmitted', 1L, 1L, None, None), ('Maintenance Visit', 'territory', 'Territory', 0L, None, 1L, None),
177 ('Purchase Order', 'supplier_address', 'Address', 0L, None, 1L, None), ('Purchase Order', 'contact_person', 'Contact', 0L, None, 1L, None), ('Purchase Order', 'supplier_name', None, 1L, None, None, None), ('Purchase Order', 'status', '\nDraft\nSubmitted\nStopped\nCancelled', 1L, 1L, 1L, None), ('Purchase Order', 'indent_no', 'Indent', 0L, None, 1L, 0L), ('Purchase Order', 'is_subcontracted', '\nYes\nNo', 0L, None, 1L, None), ('Purchase Order', 'currency', 'link:Currency', 0L, 1L, 1L, None), ('Purchase Order', 'net_total', None, 1L, 0L, 1L, None),
178 ('Purchase Receipt', 'supplier_address', 'Address', 0L, None, 1L, None), ('Purchase Receipt', 'contact_person', 'Contact', 0L, None, 1L, None), ('Purchase Receipt', 'supplier_name', None, 1L, None, None, None), ('Purchase Receipt', 'status', '\nDraft\nSubmitted\nCancelled', 1L, 1L, 1L, None), ('Purchase Receipt', 'currency', 'link:Currency', 0L, 1L, 1L, None),
179 ('Quotation', 'customer', 'Customer', 0L, None, 1L, 0L), ('Quotation', 'customer_address', 'Address', 0L, None, 1L, 0L), ('Quotation', 'contact_person', 'Contact', 0L, 0L, 1L, 0L), ('Quotation', 'customer_name', None, 1L, None, None, None), ('Quotation', 'lead', 'Lead', 0L, None, 1L, 0L), ('Quotation', 'lead_name', None, 1L, None, None, None), ('Quotation', 'order_type', '\nSales\nMaintenance', 0L, 1L, 0L, None), ('Quotation', 'status', '\nDraft\nSubmitted\nOrder Confirmed\nOrder Lost\nCancelled', 1L, 1L, 1L, None), ('Quotation', 'territory', 'Territory', 0L, 1L, 1L, 0L), ('Quotation', 'currency', 'link:Currency', 0L, 1L, 1L, None), ('Quotation', 'letter_head', 'link:Letter Head', 0L, None, 1L, None), ('Quotation', 'order_lost_reason', None, 1L, None, 1L, None), ('Quotation', 'contact_by', 'Profile', 0L, None, 1L, None), ('Quotation', 'contact_date', None, 0L, None, 1L, None), ('Quotation', 'to_discuss', None, 0L, None, 1L, None),
180 ('Receivable Voucher', 'debit_to', 'Account', 0L, 1L, 1L, None), ('Receivable Voucher', 'customer_address', 'Address', 0L, None, 1L, None), ('Receivable Voucher', 'territory', 'Territory', 0L, 1L, 1L, None), ('Receivable Voucher', 'paid_amount', None, 0L, None, 1L, None), ('Receivable Voucher', 'company', 'Company', 0L, 1L, 1L, None), ('Receivable Voucher', 'fiscal_year', 'link:Fiscal Year', 0L, 1L, 1L, None), ('Receivable Voucher', 'outstanding_amount', None, 1L, None, 1L, None),
181 ('Payable Voucher', 'supplier_address', 'Address', 0L, None, 1L, None), ('Payable Voucher', 'contact_display', None, 1L, None, None, None), ('Payable Voucher', 'contact_mobile', None, 1L, None, None, None), ('Payable Voucher', 'contact_email', None, 1L, None, 1L, None), ('Payable Voucher', 'currency', 'link:Currency', 0L, 1L, 1L, None), ('Payable Voucher', 'conversion_rate', None, 0L, 1L, 1L, None), ('Payable Voucher', 'company', 'Company', 0L, 1L, 1L, None), ('Payable Voucher', 'fiscal_year', 'link:Fiscal Year', 0L, 1L, 1L, None),
182 ('Sales Order', 'customer_address', 'Address', 0L, None, 1L, 0L), ('Sales Order', 'contact_person', 'Contact', 0L, None, 1L, None), ('Sales Order', 'customer_name', None, 1L, None, None, None), ('Sales Order', 'status', '\nDraft\nSubmitted\nStopped\nCancelled', 1L, 1L, 1L, None), ('Sales Order', 'quotation_date', None, 1L, 0L, 1L, 1L), ('Sales Order', 'currency', 'link:Currency', 0L, 1L, 1L, None), ('Sales Order', 'letter_head', 'link:Letter Head', 0L, None, 1L, None),
183 ('Sales Partner', 'territory', 'Territory', 0L, 1L, None, None),
184 ('Supplier', 'company', 'Company', 0L, 1L, None, None)]
185
186 for rec in update_fields:
187 webnotes.conn.sql("UPDATE `tabDocField` SET options=%s, permlevel=%s, reqd=%s, print_hide=%s, hidden=%s where parent=%s and fieldname=%s",(rec[2], rec[3], rec[4], rec[5], rec[6], rec[0], rec[1]))
188
189def run_patch():
190 make_address()
191 make_address_from_customer()
192 make_address_from_supplier()
193 make_contact_from_contacttab()
194 delete_unwanted_fields()
195 reload_doc_files()
196 reload_mapper_files()
197 delete_unwanted_mapper_fields()
198 sync_docfield_properties()
199
200#Old Customer Data Sync Patch for "Quotation, SO, PO, RV, PV, DN, PR, Installation Note, Maintenance Schedule, Customer Issue, Maintenance Visit"
201#--------------------------------------------------------------
202
203def run_old_data_sync_patch():
204 sync_quotation_customer_data()
205 sync_sales_order_customer_data()
206 sync_purchase_order_supplier_data()
207 sync_receivable_voucher_customer_data()
208 sync_payable_voucher_supplier_data()
209 sync_delivery_note_customer_data()
210 sync_purchase_receipt_supplier_data()
211 sync_installation_note_customer_data()
212 sync_maintenance_schedule_customer_data()
213 sync_customer_issue_customer_data()
214 sync_maintenance_visit_customer_data()
215 sync_lead_phone()
216
217#Quotation
218def sync_quotation_customer_data():
219 data_rec = webnotes.conn.sql("""
220 SELECT tq.name as id,tq.customer,
221 ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
222 FROM tabQuotation tq, tabAddress ta
223 WHERE tq.customer = ta.customer
224 AND tq.quotation_to = 'Customer'
225 AND tq.docstatus !=2
226 ORDER BY tq.name
227 """, as_dict=1)
228
229 for rec in data_rec:
230 address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
231
232 webnotes.conn.sql("""
233 UPDATE tabQuotation SET
234 customer_address = %s,
235 address_display = %s
236 WHERE name = %s
237 """,(rec['customer_address'],address_display,rec['id']))
238
239 data_rec = webnotes.conn.sql("""
240 SELECT tq.name as id,tq.customer,
241 tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
242 FROM tabQuotation tq, tabContact tc
243 WHERE tq.customer = tc.customer
244 AND tq.quotation_to = 'Customer'
245 AND tq.docstatus !=2
246 ORDER BY tq.name
247 """, as_dict=1)
248
249 for rec in data_rec:
250 contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
251
252 webnotes.conn.sql("""
253 UPDATE tabQuotation SET
254 contact_person = %s,
255 contact_mobile = %s,
256 contact_email = %s,
257 contact_display = %s
258 WHERE name = %s
259 """,(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
260
261
262#Sales Order
263def sync_sales_order_customer_data():
264 data_rec = webnotes.conn.sql("""
265 SELECT t.name as id,t.customer,
266 ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
267 FROM `tabSales Order` t, tabAddress ta
268 WHERE t.customer = ta.customer
269 AND t.docstatus !=2
270 ORDER BY t.name
271 """, as_dict=1)
272
273 for rec in data_rec:
274 address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Phone: '+rec['phone'] or ''))
275
276 webnotes.conn.sql("""
277 UPDATE `tabSales Order` SET
278 customer_address = %s,
279 address_display = %s
280 WHERE name = %s
281 """,(rec['customer_address'],address_display,rec['id']))
282
283 data_rec = webnotes.conn.sql("""
284 SELECT t.name as id,t.customer,
285 tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
286 FROM `tabSales Order` t, tabContact tc
287 WHERE t.customer = tc.customer
288 AND t.docstatus !=2
289 ORDER BY t.name
290 """, as_dict=1)
291
292 for rec in data_rec:
293 contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
294
295 webnotes.conn.sql("""
296 UPDATE `tabSales Order` SET
297 contact_person = %s,
298 contact_mobile = %s,
299 contact_email = %s,
300 contact_display = %s
301 WHERE name = %s
302 """,(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
303
304#Purchase Order
305def sync_purchase_order_supplier_data():
306 data_rec = webnotes.conn.sql("""
307 SELECT t.name as id,t.supplier,
308 ta.name as supplier_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
309 FROM `tabPurchase Order` t, tabAddress ta
310 WHERE t.supplier = ta.supplier
311 AND t.docstatus !=2
312 ORDER BY t.name
313 """, as_dict=1)
314
315 for rec in data_rec:
316 address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
317
318 webnotes.conn.sql("""
319 UPDATE `tabPurchase Order` SET
320 supplier_address = %s,
321 address_display = %s
322 WHERE name = %s
323 """,(rec['supplier_address'],address_display,rec['id']))
324
325 data_rec = webnotes.conn.sql("""
326 SELECT t.name as id,t.supplier,
327 tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
328 FROM `tabPurchase Order` t, tabContact tc
329 WHERE t.supplier = tc.supplier
330 AND t.docstatus !=2
331 ORDER BY t.name
332 """, as_dict=1)
333
334 for rec in data_rec:
335 contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
336
337 webnotes.conn.sql("""
338 UPDATE `tabPurchase Order` SET
339 contact_person = %s,
340 contact_mobile = %s,
341 contact_email = %s,
342 contact_display = %s
343 WHERE name = %s
344 """,(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
345
346#Sales Invoice
347def sync_receivable_voucher_customer_data():
348 data_rec = webnotes.conn.sql("""
349 SELECT t.name as id,t.customer,
350 ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
351 FROM `tabReceivable Voucher` t, tabAddress ta
352 WHERE t.customer = ta.customer
353 AND t.docstatus !=2
354 ORDER BY t.name
355 """, as_dict=1)
356
357 for rec in data_rec:
358 address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
359
360 webnotes.conn.sql("""
361 UPDATE `tabReceivable Voucher` SET
362 customer_address = %s,
363 address_display = %s
364 WHERE name = %s
365 """,(rec['customer_address'],address_display,rec['id']))
366
367 data_rec = webnotes.conn.sql("""
368 SELECT t.name as id,t.customer,
369 tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
370 FROM `tabReceivable Voucher` t, tabContact tc
371 WHERE t.customer = tc.customer
372 AND t.docstatus !=2
373 ORDER BY t.name
374 """, as_dict=1)
375
376 for rec in data_rec:
377 contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
378
379 webnotes.conn.sql("""
380 UPDATE `tabReceivable Voucher` SET
381 contact_person = %s,
382 contact_mobile = %s,
383 contact_email = %s,
384 contact_display = %s
385 WHERE name = %s
386 """,(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
387
388#Purchase Invoice
389def sync_payable_voucher_supplier_data():
390 data_rec = webnotes.conn.sql("""
391 SELECT t.name as id,t.supplier,
392 ta.name as supplier_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
393 FROM `tabPayable Voucher` t, tabAddress ta
394 WHERE t.supplier = ta.supplier
395 AND t.docstatus !=2
396 ORDER BY t.name
397 """, as_dict=1)
398
399 for rec in data_rec:
400 address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
401
402 webnotes.conn.sql("""
403 UPDATE `tabPayable Voucher` SET
404 supplier_address = %s,
405 address_display = %s
406 WHERE name = %s
407 """,(rec['supplier_address'],address_display,rec['id']))
408
409 data_rec = webnotes.conn.sql("""
410 SELECT t.name as id,t.supplier,
411 tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
412 FROM `tabPayable Voucher` t, tabContact tc
413 WHERE t.supplier = tc.supplier
414 AND t.docstatus !=2
415 ORDER BY t.name
416 """, as_dict=1)
417
418 for rec in data_rec:
419 contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
420
421 webnotes.conn.sql("""
422 UPDATE `tabPayable Voucher` SET
423 contact_person = %s,
424 contact_mobile = %s,
425 contact_email = %s,
426 contact_display = %s
427 WHERE name = %s
428 """,(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
429
430#Delivery Note
431def sync_delivery_note_customer_data():
432 data_rec = webnotes.conn.sql("""
433 SELECT t.name as id,t.customer,
434 ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
435 FROM `tabDelivery Note` t, tabAddress ta
436 WHERE t.customer = ta.customer
437 AND t.docstatus !=2
438 ORDER BY t.name
439 """, as_dict=1)
440
441 for rec in data_rec:
442 address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
443
444 webnotes.conn.sql("""
445 UPDATE `tabDelivery Note` SET
446 customer_address = %s,
447 address_display = %s
448 WHERE name = %s
449 """,(rec['customer_address'],address_display,rec['id']))
450
451 data_rec = webnotes.conn.sql("""
452 SELECT t.name as id,t.customer,
453 tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
454 FROM `tabDelivery Note` t, tabContact tc
455 WHERE t.customer = tc.customer
456 AND t.docstatus !=2
457 ORDER BY t.name
458 """, as_dict=1)
459
460 for rec in data_rec:
461 contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
462
463 webnotes.conn.sql("""
464 UPDATE `tabDelivery Note` SET
465 contact_person = %s,
466 contact_mobile = %s,
467 contact_email = %s,
468 contact_display = %s
469 WHERE name = %s
470 """,(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
471
472#Purchase Receipt
473def sync_purchase_receipt_supplier_data():
474 data_rec = webnotes.conn.sql("""
475 SELECT t.name as id,t.supplier,
476 ta.name as supplier_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
477 FROM `tabPurchase Receipt` t, tabAddress ta
478 WHERE t.supplier = ta.supplier
479 AND t.docstatus !=2
480 ORDER BY t.name
481 """, as_dict=1)
482
483 for rec in data_rec:
484 address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
485
486 webnotes.conn.sql("""
487 UPDATE `tabPurchase Receipt` SET
488 supplier_address = %s,
489 address_display = %s
490 WHERE name = %s
491 """,(rec['supplier_address'],address_display,rec['id']))
492
493 data_rec = webnotes.conn.sql("""
494 SELECT t.name as id,t.supplier,
495 tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
496 FROM `tabPurchase Receipt` t, tabContact tc
497 WHERE t.supplier = tc.supplier
498 AND t.docstatus !=2
499 ORDER BY t.name
500 """, as_dict=1)
501
502 for rec in data_rec:
503 contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
504
505 webnotes.conn.sql("""
506 UPDATE `tabPurchase Receipt` SET
507 contact_person = %s,
508 contact_mobile = %s,
509 contact_email = %s,
510 contact_display = %s
511 WHERE name = %s
512 """,(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
513
514#Installation Note
515def sync_installation_note_customer_data():
516 data_rec = webnotes.conn.sql("""
517 SELECT t.name as id,t.customer,
518 ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
519 FROM `tabInstallation Note` t, tabAddress ta
520 WHERE t.customer = ta.customer
521 AND t.docstatus !=2
522 ORDER BY t.name
523 """, as_dict=1)
524
525 for rec in data_rec:
526 address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
527
528 webnotes.conn.sql("""
529 UPDATE `tabInstallation Note` SET
530 customer_address = %s,
531 address_display = %s
532 WHERE name = %s
533 """,(rec['customer_address'],address_display,rec['id']))
534
535 data_rec = webnotes.conn.sql("""
536 SELECT t.name as id,t.customer,
537 tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
538 FROM `tabInstallation Note` t, tabContact tc
539 WHERE t.customer = tc.customer
540 AND t.docstatus !=2
541 ORDER BY t.name
542 """, as_dict=1)
543
544 for rec in data_rec:
545 contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
546
547 webnotes.conn.sql("""
548 UPDATE `tabInstallation Note` SET
549 contact_person = %s,
550 contact_mobile = %s,
551 contact_email = %s,
552 contact_display = %s
553 WHERE name = %s
554 """,(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
555
556#Maintenance Schedule
557def sync_maintenance_schedule_customer_data():
558 data_rec = webnotes.conn.sql("""
559 SELECT t.name as id,t.customer,
560 ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
561 FROM `tabMaintenance Schedule` t, tabAddress ta
562 WHERE t.customer = ta.customer
563 AND t.docstatus !=2
564 ORDER BY t.name
565 """, as_dict=1)
566
567 for rec in data_rec:
568 address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
569
570 webnotes.conn.sql("""
571 UPDATE `tabMaintenance Schedule` SET
572 customer_address = %s,
573 address_display = %s
574 WHERE name = %s
575 """,(rec['customer_address'],address_display,rec['id']))
576
577 data_rec = webnotes.conn.sql("""
578 SELECT t.name as id,t.customer,
579 tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
580 FROM `tabMaintenance Schedule` t, tabContact tc
581 WHERE t.customer = tc.customer
582 AND t.docstatus !=2
583 ORDER BY t.name
584 """, as_dict=1)
585
586 for rec in data_rec:
587 contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
588
589 webnotes.conn.sql("""
590 UPDATE `tabMaintenance Schedule` SET
591 contact_person = %s,
592 contact_mobile = %s,
593 contact_email = %s,
594 contact_display = %s
595 WHERE name = %s
596 """,(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
597
598#Customer Issue
599def sync_customer_issue_customer_data():
600 data_rec = webnotes.conn.sql("""
601 SELECT t.name as id,t.customer,
602 ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
603 FROM `tabCustomer Issue` t, tabAddress ta
604 WHERE t.customer = ta.customer
605 AND t.docstatus !=2
606 ORDER BY t.name
607 """, as_dict=1)
608
609 for rec in data_rec:
610 address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
611
612 webnotes.conn.sql("""
613 UPDATE `tabCustomer Issue` SET
614 customer_address = %s,
615 address_display = %s
616 WHERE name = %s
617 """,(rec['customer_address'],address_display,rec['id']))
618
619 data_rec = webnotes.conn.sql("""
620 SELECT t.name as id,t.customer,
621 tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
622 FROM `tabCustomer Issue` t, tabContact tc
623 WHERE t.customer = tc.customer
624 AND t.docstatus !=2
625 ORDER BY t.name
626 """, as_dict=1)
627
628 for rec in data_rec:
629 contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
630
631 webnotes.conn.sql("""
632 UPDATE `tabCustomer Issue` SET
633 contact_person = %s,
634 contact_mobile = %s,
635 contact_email = %s,
636 contact_display = %s
637 WHERE name = %s
638 """,(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
639
640#Maintenance Visit
641def sync_maintenance_visit_customer_data():
642 data_rec = webnotes.conn.sql("""
643 SELECT t.name as id,t.customer,
644 ta.name as customer_address, ta.address_line1, ta.address_line2, ta.city, ta.country, ta.pincode, ta.state, ta.phone
645 FROM `tabMaintenance Visit` t, tabAddress ta
646 WHERE t.customer = ta.customer
647 AND t.docstatus !=2
648 ORDER BY t.name
649 """, as_dict=1)
650
651 for rec in data_rec:
652 address_display = cstr((rec['address_line1'] and rec['address_line1'] or '')) + cstr((rec['address_line2'] and '\n' + rec['address_line2'] or '')) + cstr((rec['city'] and '\n'+rec['city'] or '')) + cstr((rec['pincode'] and ', ' + rec['pincode'] or '')) + cstr((rec['state'] and '\n'+rec['state']+', ' or '')) + cstr((rec['country'] and rec['country'] or '')) + '\n' + cstr((rec['phone'] and 'Tel: '+rec['phone'] or ''))
653
654 webnotes.conn.sql("""
655 UPDATE `tabMaintenance Visit` SET
656 customer_address = %s,
657 address_display = %s
658 WHERE name = %s
659 """,(rec['customer_address'],address_display,rec['id']))
660
661 data_rec = webnotes.conn.sql("""
662 SELECT t.name as id,t.customer,
663 tc.name as contact_person, tc.first_name, tc.last_name, tc.email_id, tc.phone as contact_phone, tc.mobile_no, tc.department, tc.designation
664 FROM `tabMaintenance Visit` t, tabContact tc
665 WHERE t.customer = tc.customer
666 AND t.docstatus !=2
667 ORDER BY t.name
668 """, as_dict=1)
669
670 for rec in data_rec:
671 contact_display = (rec['first_name'] and rec['first_name'] or '') + (rec['last_name'] and ' ' + rec['last_name'] or '')
672
673 webnotes.conn.sql("""
674 UPDATE `tabMaintenance Visit` SET
675 contact_person = %s,
676 contact_mobile = %s,
677 contact_email = %s,
678 contact_display = %s
679 WHERE name = %s
680 """,(rec['contact_person'],rec['mobile_no'],rec['email_id'],contact_display,rec['id']))
681
682#lead phone data sync
683def sync_lead_phone():
684 webnotes.conn.sql("""
685 update ignore tabLead set
686 phone = contact_no
687 where contact_no is not null
688 """)