@@ -3294,47 +3294,64 @@ def changed(fname):
3294
3294
if changed ('commercial_partner_id' ):
3295
3295
move .line_ids .partner_id = after [move ]['commercial_partner_id' ]
3296
3296
3297
- @contextmanager
3298
- def _sync_dynamic_lines (self , container ):
3299
- with self ._disable_recursion (container , 'skip_invoice_sync' ) as disabled :
3300
- if disabled :
3301
- yield
3302
- return
3303
- def update_containers ():
3304
- # Only invoice-like and journal entries in "auto tax mode" are synced
3305
- tax_container ['records' ] = container ['records' ].filtered (lambda m : m .is_invoice (True ) or m .line_ids .tax_ids or m .line_ids .tax_repartition_line_id )
3306
- invoice_container ['records' ] = container ['records' ].filtered (lambda m : m .is_invoice (True ))
3307
- misc_container ['records' ] = container ['records' ].filtered (lambda m : m .is_entry () and not m .tax_cash_basis_origin_move_id )
3297
+ def _get_sync_stack (self , container ):
3298
+ tax_container , invoice_container , misc_container = ({} for _ in range (3 ))
3308
3299
3309
- tax_container , invoice_container , misc_container = ({} for __ in range (3 ))
3310
- update_containers ()
3311
- with ExitStack () as stack :
3312
- stack .enter_context (self ._sync_dynamic_line (
3300
+ def update_containers ():
3301
+ # Only invoice-like and journal entries in "auto tax mode" are synced
3302
+ tax_container ['records' ] = container ['records' ].filtered (lambda m : m .is_invoice (True ) or m .line_ids .tax_ids or m .line_ids .tax_repartition_line_id )
3303
+ invoice_container ['records' ] = container ['records' ].filtered (lambda m : m .is_invoice (True ))
3304
+ misc_container ['records' ] = container ['records' ].filtered (lambda m : m .is_entry () and not m .tax_cash_basis_origin_move_id )
3305
+
3306
+ return tax_container , invoice_container , misc_container
3307
+
3308
+ update_containers ()
3309
+
3310
+ stack = [
3311
+ (10 , self ._sync_dynamic_line (
3313
3312
existing_key_fname = 'term_key' ,
3314
3313
needed_vals_fname = 'needed_terms' ,
3315
3314
needed_dirty_fname = 'needed_terms_dirty' ,
3316
3315
line_type = 'payment_term' ,
3317
3316
container = invoice_container ,
3318
- ))
3319
- stack . enter_context ( self ._sync_unbalanced_lines (misc_container ))
3320
- stack . enter_context ( self ._sync_rounding_lines (invoice_container ))
3321
- stack . enter_context ( self ._sync_dynamic_line (
3317
+ )),
3318
+ ( 20 , self ._sync_unbalanced_lines (misc_container )),
3319
+ ( 30 , self ._sync_rounding_lines (invoice_container )),
3320
+ ( 40 , self ._sync_dynamic_line (
3322
3321
existing_key_fname = 'discount_allocation_key' ,
3323
3322
needed_vals_fname = 'line_ids.discount_allocation_needed' ,
3324
3323
needed_dirty_fname = 'line_ids.discount_allocation_dirty' ,
3325
3324
line_type = 'discount' ,
3326
3325
container = invoice_container ,
3327
- ))
3328
- stack . enter_context ( self ._sync_tax_lines (tax_container ))
3329
- stack . enter_context ( self ._sync_non_deductible_base_lines (invoice_container ))
3330
- stack . enter_context ( self ._sync_dynamic_line (
3326
+ )),
3327
+ ( 50 , self ._sync_tax_lines (tax_container )),
3328
+ ( 60 , self ._sync_non_deductible_base_lines (invoice_container )),
3329
+ ( 70 , self ._sync_dynamic_line (
3331
3330
existing_key_fname = 'epd_key' ,
3332
3331
needed_vals_fname = 'line_ids.epd_needed' ,
3333
3332
needed_dirty_fname = 'line_ids.epd_dirty' ,
3334
3333
line_type = 'epd' ,
3335
3334
container = invoice_container ,
3336
- ))
3337
- stack .enter_context (self ._sync_invoice (invoice_container ))
3335
+ )),
3336
+ (80 , self ._sync_invoice (invoice_container )),
3337
+ ]
3338
+
3339
+ return stack , update_containers
3340
+
3341
+ @contextmanager
3342
+ def _sync_dynamic_lines (self , container ):
3343
+ with self ._disable_recursion (container , 'skip_invoice_sync' ) as disabled :
3344
+ if disabled :
3345
+ yield
3346
+ return
3347
+
3348
+ stack_list , update_containers = self ._get_sync_stack (container )
3349
+ update_containers ()
3350
+ with ExitStack () as stack :
3351
+ stack_list .sort ()
3352
+ for _seq , contextmgr in stack_list :
3353
+ stack .enter_context (contextmgr )
3354
+
3338
3355
line_container = {'records' : self .line_ids }
3339
3356
with self .line_ids ._sync_invoice (line_container ):
3340
3357
yield
0 commit comments