Updating Customers¶
Updating Customers¶
1db = impact.active_database
2
3impact.gui.output_toolbox.clear()
4impact.gui.output_toolbox.add("customer Count: " + str(db.customers.count))
5impact.gui.output_toolbox.add("**** Find By Name 'Default' ****")
6
7c = db.customers.find_by_name("Default")
8
9if c is None:
10 impact.gui.output_toolbox.add("Error: Unable to locate a customer with name 'Default'")
11else:
12
13 # save Key so we can locate the same ICustomer again after changing its name
14 cust_key = c.key
15
16 impact.gui.output_toolbox.add("Code: " + str(c.code))
17 impact.gui.output_toolbox.add("Name: " + str(c.name))
18 impact.gui.output_toolbox.add("Active: " + str(c.active))
19
20 # WARNING: If you are using Enterprise each of these changes will trigger the customer
21 # to be published. If you want to avoid this then use IDatabaseValues and the changes
22 # will only be published once when DoUpdate is called
23 c.code = "DEF_CUST"
24 c.name = "Default (Renamed)"
25 c.active = False
26
27 # Note: It is important to assign c.values to a local
28 # variable because otherwise we would get a new interface everytime
29 # we used c.values which would return to stored values
30 values = c.values
31
32 values.save("CS_ADDR1", "Some Street")
33 values.save("CS_ADDR2", "Christchurch")
34 values.save("CS_ADDR3", "New Zealand")
35 values.save("CS_CONTAC1", "Rob Whitehead")
36
37 # The values are updated in the database when DoUpdate is called
38 if values.do_update():
39 impact.gui.output_toolbox.add("Successfully updated customer '" + c.name + "'")
40 else:
41 impact.gui.output_toolbox.add("Error: Unable to update customer")
42
43 # To ensure any changes are reflected internally you also need to call
44 # ICustomers.refresh() to force all customers to be reloaded from the database
45 # if you don't then old cached values may be used.
46
47 # NOTE: If you are iterating an ICustomers collection and updating individual ICustomer's
48 # it is important not to call ICustomers.refresh() until after you have updated all
49 # the customers.
50 db.customers.refresh()
51
52 c = db.customers.find_by_key(cust_key)
53
54 impact.gui.output_toolbox.add("Code: " + str(c.code))
55 impact.gui.output_toolbox.add("Name: " + str(c.name))
56 impact.gui.output_toolbox.add("Active: " + str(c.active))
57
58
59
60
61
62
63
64
65