Hi
I am trying to create a transaction that updates various tables. I have not yet tested this, because I wanted to clarify a few points. Here is the code:-
#Transaction for Policy
@anvil.server.callable
@tables.in_transaction
def get_next_value_in_sequence():
row = app_tables.counter.get()
row['value'] += 1
return row['value']
def do_update():
#Add Travellers
for traveller in self.cp2.get_components():
row = app_tables.travellers.add_row(
TravellerFirstname=traveller.traveller_firstname.text.title(),
TravellerSurname=traveller.traveller_surname.text.title(),
TravellerDateofBirth=traveller.travellerform_dob.date,
User=anvil.users.get_current_user(),
PolicyNumber='value')
#Add Policy
row = app_tables.policies.add_row(
PolicyStartDate=self.trip_start_date,
PolicyEndDate=self.trip_end_date,
PolicyPremium=self.totalpremium,
PolicyIPT=self.totalipt,
User=anvil.users.get_current_user(),
PolicyTravellerCount=self.trav,
Location=self.location_region,
LocationDetail=self.location,
Days=self.days,
Travellers=self.trav,
Baggage=self.finalbaggage,
SingleArticle=self.finalarticle,
Cancellation=self.finalcancellation,
PolicyDocument='',
CreatedDate=datetime.date.today().strftime('%Y,%m,%d'),
PolicyNumber='value'
)
#Add User Address
row = app_tables.users.get_current_user(
UserAddress1=self.address1,
UserTown=self.town,
UserCounty=self.county,
UserPostcode=self.postcode,
UserMobile=self.mobile,
UserLandline=self.landline
)
#Add Trips
row = app_tables.mytrips.add_row(
TripName=self.tripname,
TripStartDate=self.trip_start_date,
TripEndDate=self.trip_end_date,
User=anvil.users.get_current_user(),
HolidayType=self.holidaytype,
LocationCountry=self.location,
LocationCity=self.location_city,
TripStatus=('Active'),
PolicyNumber='value'
)
Here are my questions:-
-
Should the part with the Counter for the transaction reference, be server side? At the moment I have set the table counter to view edit delete on form, but not sure if thats right.
-
I want the reference number created by the counter to be set as PolicyNumber, have I done that right?
-
In relation to the current user, by the time the person clicks to submit the transaction, they will be logged in. Have I set the line for User correctly?
-
Can anyone see any other glaring errors that I have made?