@@ -17,9 +17,9 @@ def _get_wt_moves(self):
1717 )
1818 return wt_moves
1919
20- @api .model
21- def create (self , vals ):
22- res = super (AccountFullReconcile , self ).create (vals )
20+ @api .model_create_multi
21+ def create (self , vals_list ):
22+ res = super (AccountFullReconcile , self ).create (vals_list )
2323 wt_moves = res ._get_wt_moves ()
2424 for wt_move in wt_moves :
2525 if wt_move .full_reconcile_id :
@@ -39,67 +39,70 @@ def unlink(self):
3939class AccountPartialReconcile (models .Model ):
4040 _inherit = "account.partial.reconcile"
4141
42- @api .model
43- def create (self , vals ):
44- # In case of WT The amount of reconcile mustn't exceed the tot net
45- # amount. The amount residual will be full reconciled with amount net
46- # and amount wt created with payment
47- invoice = False
48- ml_ids = []
49- if vals .get ("debit_move_id" ):
50- ml_ids .append (vals .get ("debit_move_id" ))
51- if vals .get ("credit_move_id" ):
52- ml_ids .append (vals .get ("credit_move_id" ))
53- move_lines = self .env ["account.move.line" ].browse (ml_ids )
54- invoice = move_lines .filtered (lambda x : x .exists ()).move_id .filtered (
55- lambda x : x .is_invoice ()
56- )
57- # XXX
58- # the following code mimics 12.0 behaviour; probably it's not correct
59- if invoice :
60- invoice = invoice [0 ]
61-
62- # Limit value of reconciliation
63- if invoice and invoice .withholding_tax and invoice .amount_net_pay :
64- # We must consider amount in foreign currency, if present
65- # Note that this is always executed, for every reconciliation.
66- # Thus, we must not change amount when not in withholding tax case
67- amount = vals .get ("amount_currency" ) or vals .get ("amount" )
68- digits_rounding_precision = invoice .company_id .currency_id .rounding
42+ @api .model_create_multi
43+ def create (self , vals_list ):
44+ ret = self .env ["account.partial.reconcile" ]
45+ for vals in vals_list :
46+ # In case of WT The amount of reconcile mustn't exceed the tot net
47+ # amount. The amount residual will be full reconciled with amount net
48+ # and amount wt created with payment
49+ invoice = False
50+ ml_ids = []
51+ if vals .get ("debit_move_id" ):
52+ ml_ids .append (vals .get ("debit_move_id" ))
53+ if vals .get ("credit_move_id" ):
54+ ml_ids .append (vals .get ("credit_move_id" ))
55+ move_lines = self .env ["account.move.line" ].browse (ml_ids )
56+ invoice = move_lines .filtered (lambda x : x .exists ()).move_id .filtered (
57+ lambda x : x .is_invoice ()
58+ )
59+ # XXX
60+ # the following code mimics 12.0 behaviour; probably it's not correct
61+ if invoice :
62+ invoice = invoice [0 ]
63+
64+ # Limit value of reconciliation
65+ if invoice and invoice .withholding_tax and invoice .amount_net_pay :
66+ # We must consider amount in foreign currency, if present
67+ # Note that this is always executed, for every reconciliation.
68+ # Thus, we must not change amount when not in withholding tax case
69+ amount = vals .get ("amount_currency" ) or vals .get ("amount" )
70+ digits_rounding_precision = invoice .company_id .currency_id .rounding
71+ if (
72+ float_compare (
73+ amount ,
74+ invoice .amount_net_pay ,
75+ precision_rounding = digits_rounding_precision ,
76+ )
77+ == 1
78+ ):
79+ vals .update ({"amount" : invoice .amount_net_pay })
80+
81+ # Create reconciliation
82+ reconcile = super (AccountPartialReconcile , self ).create (vals )
83+ # Avoid re-generate wt moves if the move line is an wt move.
84+ # It's possible if the user unreconciles a wt move under invoice
85+ ld = self .env ["account.move.line" ].browse (vals .get ("debit_move_id" ))
86+ lc = self .env ["account.move.line" ].browse (vals .get ("credit_move_id" ))
87+
6988 if (
70- float_compare (
71- amount ,
72- invoice .amount_net_pay ,
73- precision_rounding = digits_rounding_precision ,
74- )
75- == 1
89+ lc .withholding_tax_generated_by_move_id
90+ or ld .withholding_tax_generated_by_move_id
7691 ):
77- vals .update ({"amount" : invoice .amount_net_pay })
78-
79- # Create reconciliation
80- reconcile = super (AccountPartialReconcile , self ).create (vals )
81- # Avoid re-generate wt moves if the move line is an wt move.
82- # It's possible if the user unreconciles a wt move under invoice
83- ld = self .env ["account.move.line" ].browse (vals .get ("debit_move_id" ))
84- lc = self .env ["account.move.line" ].browse (vals .get ("credit_move_id" ))
85-
86- if (
87- lc .withholding_tax_generated_by_move_id
88- or ld .withholding_tax_generated_by_move_id
89- ):
90- is_wt_move = True
91- else :
92- is_wt_move = False
93- # Wt moves creation
94- if (
95- invoice .withholding_tax_line_ids
96- and not self ._context .get ("no_generate_wt_move" )
97- and not is_wt_move
98- ):
99- # and not wt_existing_moves\
100- reconcile .generate_wt_moves ()
101-
102- return reconcile
92+ is_wt_move = True
93+ else :
94+ is_wt_move = False
95+ # Wt moves creation
96+ if (
97+ invoice .withholding_tax_line_ids
98+ and not self ._context .get ("no_generate_wt_move" )
99+ and not is_wt_move
100+ ):
101+ # and not wt_existing_moves\
102+ reconcile .generate_wt_moves ()
103+ ret |= reconcile
104+
105+ return ret
103106
104107 def _prepare_wt_move (self , vals ):
105108 """
@@ -138,11 +141,18 @@ def generate_wt_moves(self):
138141 amount_wt = wt_st .get_wt_competence (self .amount )
139142 # Date maturity
140143 p_date_maturity = False
141- payment_lines = wt_st .withholding_tax_id .payment_term .compute (
142- amount_wt , rec_line_payment .date or False
144+ payment_lines = wt_st .withholding_tax_id .payment_term ._compute_terms (
145+ date_ref = rec_line_payment .date or False ,
146+ currency = self .env .company .currency_id ,
147+ company = self .env .company ,
148+ tax_amount = 0 ,
149+ tax_amount_currency = 0 ,
150+ untaxed_amount = amount_wt ,
151+ untaxed_amount_currency = amount_wt ,
152+ sign = 1 ,
143153 )
144154 if payment_lines and payment_lines [0 ]:
145- p_date_maturity = payment_lines [0 ][0 ]
155+ p_date_maturity = payment_lines [0 ]["date" ]
146156 wt_move_vals = {
147157 "statement_id" : wt_st .id ,
148158 "date" : rec_line_payment .date ,
@@ -330,8 +340,8 @@ def _compute_amount_withholding_tax(self):
330340 invoice .withholding_tax_amount = withholding_tax_amount
331341
332342 reconciled_lines = invoice .line_ids .filtered (
333- lambda line : line .account_id .user_type_id . type
334- in ("receivable " , "payable " )
343+ lambda line : line .account_id .account_type
344+ in ("asset_receivable " , "liability_payable " )
335345 )
336346 reconciled_amls = reconciled_lines .mapped (
337347 "matched_debit_ids.debit_move_id"
@@ -344,7 +354,7 @@ def _compute_amount_withholding_tax(self):
344354 amount_net_pay_residual , dp_obj .precision_get ("Account" )
345355 )
346356
347- withholding_tax = fields .Boolean ("Withholding Tax" )
357+ withholding_tax = fields .Boolean ()
348358 withholding_tax_in_print = fields .Boolean (
349359 "Show Withholding Tax In Print" , default = True
350360 )
@@ -402,7 +412,10 @@ def action_post(self):
402412 # Rates
403413 rate_num = 0
404414 for move_line in inv .line_ids :
405- if move_line .account_id .internal_type not in ["receivable" , "payable" ]:
415+ if move_line .account_id .account_type not in [
416+ "asset_receivable" ,
417+ "liability_payable" ,
418+ ]:
406419 continue
407420 rate_num += 1
408421 if rate_num :
@@ -414,7 +427,10 @@ def action_post(self):
414427 # Re-read move lines to assign the amounts of wt
415428 i = 0
416429 for move_line in inv .line_ids :
417- if move_line .account_id .internal_type not in ["receivable" , "payable" ]:
430+ if move_line .account_id .account_type not in [
431+ "asset_receivable" ,
432+ "liability_payable" ,
433+ ]:
418434 continue
419435 i += 1
420436 if i == rate_num :
@@ -505,8 +521,8 @@ class AccountMoveLine(models.Model):
505521 _inherit = "account.move.line"
506522
507523 withholding_tax_id = fields .Many2one ("withholding.tax" , string = "Withholding Tax" )
508- withholding_tax_base = fields .Float (string = "Withholding Tax Base" )
509- withholding_tax_amount = fields .Float (string = "Withholding Tax Amount" )
524+ withholding_tax_base = fields .Float ()
525+ withholding_tax_amount = fields .Float ()
510526 withholding_tax_generated_by_move_id = fields .Many2one (
511527 "account.move" , string = "Withholding Tax generated from" , readonly = True
512528 )
@@ -587,18 +603,16 @@ def _compute_coeff(self):
587603 withholding_tax_id = fields .Many2one (
588604 "withholding.tax" , string = "Withholding tax" , ondelete = "restrict"
589605 )
590- sequence = fields .Integer ("Sequence" )
591- base = fields .Float ("Base" )
592- tax = fields .Float ("Tax" )
606+ sequence = fields .Integer ()
607+ base = fields .Float ()
608+ tax = fields .Float ()
593609 base_coeff = fields .Float (
594- "Base Coeff" ,
595610 compute = "_compute_coeff" ,
596611 store = True ,
597612 help = "Coeff used\
598613 to compute amount competence in the riconciliation" ,
599614 )
600615 tax_coeff = fields .Float (
601- "Tax Coeff" ,
602616 compute = "_compute_coeff" ,
603617 store = True ,
604618 help = "Coeff used\
0 commit comments