3131class Mixin :
3232 """Mixin containing methods attached to TransactionBuilder Class."""
3333
34+ @property
35+ def line_num (self ):
36+ return len (self .create_model .get ('lines' , []))
37+
38+ def _get_line_number (self , line_number = None ):
39+ if line_number is None :
40+ line_number = self .line_num
41+ return str (line_number )
42+
3443 def with_commit (self ):
3544 """
3645 Set the commit flag of the transaction.
@@ -127,7 +136,14 @@ def with_latlong(self, address_type, lat, long_):
127136 'longitude' : float (long_ )}
128137 return self
129138
130- def with_line (self , amount , quantity , item_code , tax_code , line_number = None ):
139+ def with_line (
140+ self ,
141+ amount ,
142+ quantity ,
143+ item_code ,
144+ tax_code ,
145+ line_number = None ,
146+ ):
131147 r"""
132148 Add a line to the transaction.
133149
@@ -136,42 +152,45 @@ def with_line(self, amount, quantity, item_code, tax_code, line_number=None):
136152 :param string item_code: Code of the item.
137153 :param string tax_code: Tax Code of the item. If left blank, \
138154 the default item (P0000000) is assumed.
139- :param [int] line_number: Value of the line number.
155+ :param str line_number: Value of the line number.
140156 :return: TransactionBuilder
141157 """
142- if line_number is not None :
143- self .line_num = line_number ;
144-
158+
145159 temp = {
146- 'number' : str ( self .line_num ),
160+ 'number' : self ._get_line_number ( line_number ),
147161 'amount' : amount ,
148162 'quantity' : quantity ,
149163 'itemCode' : str (item_code ),
150164 'taxCode' : str (tax_code )
151165 }
152166 self .create_model ['lines' ].append (temp )
153- self .line_num += 1
154167 return self
155168
156- def with_exempt_line (self , amount , item_code , exemption_code ):
169+ def with_exempt_line (
170+ self ,
171+ amount ,
172+ item_code ,
173+ exemption_code ,
174+ line_number = None ,
175+ ):
157176 """
158177 Add a line with an exemption to this transaction.
159178
160179 :param float amount: The amount of this line item
161180 :param string item_code: The code for the item
162181 :param string exemption_code: The exemption code for this line item
182+ :param str line_number: Value of the line number.
163183 :return: TransactionBuilder
164184 """
165185
166186 temp = {
167- 'number' : str ( self .line_num ),
187+ 'number' : self ._get_line_number ( line_number ),
168188 'quantity' : 1 ,
169189 'amount' : amount ,
170190 'exemptionCode' : str (exemption_code ),
171191 'itemCode' : str (item_code )
172192 }
173193 self .create_model ['lines' ].append (temp )
174- self .line_num += 1
175194 return self
176195
177196 def with_diagnostics (self ):
@@ -298,7 +317,13 @@ def with_tax_override(self, type_, reason, tax_amount, tax_date):
298317 }
299318 return self
300319
301- def with_separate_address_line (self , amount , type_ , address ):
320+ def with_separate_address_line (
321+ self ,
322+ amount ,
323+ type_ ,
324+ address ,
325+ line_number = None ,
326+ ):
302327 r"""
303328 Add a line to this transaction.
304329
@@ -316,10 +341,11 @@ def with_separate_address_line(self, amount, type_, address):
316341 region State or Region of the location.
317342 postal_code Postal/zip code of the location.
318343 country The two-letter country code of the location.
344+ :param str line_number: Value of the line number.
319345 :return: TransactionBuilder
320346 """
321347 temp = {
322- 'number' : self .line_num ,
348+ 'number' : self ._get_line_number ( line_number ) ,
323349 'quantity' : 1 ,
324350 'amount' : amount ,
325351 'addresses' : {
@@ -328,7 +354,6 @@ def with_separate_address_line(self, amount, type_, address):
328354 }
329355
330356 self .create_model ['lines' ].append (temp )
331- self .line_num += 1
332357 return self
333358
334359 def create_adjustment_request (self , desc , reason ):
0 commit comments