@@ -257,30 +257,7 @@ def action_post(self):
257
257
for pay_date in pterm_list :
258
258
if not self .month_check (pay_date ["date" ], previous_date_due ):
259
259
# ---- Get Line values for service product
260
- service_prod = invoice .company_id .due_cost_service_id
261
- account = service_prod .product_tmpl_id .get_product_accounts (
262
- invoice .fiscal_position_id
263
- )["income" ]
264
- line_vals = {
265
- "partner_id" : invoice .partner_id .id ,
266
- "product_id" : service_prod .id ,
267
- "move_id" : invoice .id ,
268
- "price_unit" : (
269
- invoice .invoice_payment_term_id .riba_payment_cost
270
- ),
271
- "due_cost_line" : True ,
272
- "name" : _ ("{line_name} for {month}-{year}" ).format (
273
- line_name = service_prod .name ,
274
- month = pay_date ["date" ].month ,
275
- year = pay_date ["date" ].year ,
276
- ),
277
- "account_id" : account .id ,
278
- "sequence" : 9999 ,
279
- }
280
- # ---- Update Line Value with tax if is set on product
281
- if invoice .company_id .due_cost_service_id .taxes_id :
282
- tax = invoice .fiscal_position_id .map_tax (service_prod .taxes_id )
283
- line_vals .update ({"tax_ids" : [(4 , tax .id )]})
260
+ line_vals = invoice .get_due_cost_line_vals (pay_date )
284
261
invoice .write ({"invoice_line_ids" : [(0 , 0 , line_vals )]})
285
262
# ---- recompute invoice taxes
286
263
invoice ._sync_dynamic_lines (
@@ -359,6 +336,34 @@ def get_apply_due_cost(self):
359
336
def get_due_cost_line_ids (self ):
360
337
return self .invoice_line_ids .filtered (lambda line : line .due_cost_line ).ids
361
338
339
+ def get_due_cost_line_vals (self , pay_date ):
340
+ self .ensure_one ()
341
+ service_prod = self .company_id .due_cost_service_id
342
+ account = service_prod .product_tmpl_id .get_product_accounts (
343
+ self .fiscal_position_id
344
+ )["income" ]
345
+ line_vals = {
346
+ "partner_id" : self .partner_id .id ,
347
+ "product_id" : service_prod .id ,
348
+ "move_id" : self .id ,
349
+ "price_unit" : (
350
+ self .invoice_payment_term_id .riba_payment_cost
351
+ ),
352
+ "due_cost_line" : True ,
353
+ "name" : _ ("{line_name} for {month}-{year}" ).format (
354
+ line_name = service_prod .name ,
355
+ month = pay_date ["date" ].month ,
356
+ year = pay_date ["date" ].year ,
357
+ ),
358
+ "account_id" : account .id ,
359
+ "sequence" : 9999 ,
360
+ }
361
+ # ---- Update Line Value with tax if is set on product
362
+ if self .company_id .due_cost_service_id .taxes_id :
363
+ tax = self .fiscal_position_id .map_tax (service_prod .taxes_id )
364
+ line_vals .update ({"tax_ids" : [(4 , tax .id )]})
365
+ return line_vals
366
+
362
367
def action_riba_payment_date (self ):
363
368
return {
364
369
"type" : "ir.actions.act_window" ,
0 commit comments