@@ -66,7 +66,12 @@ class AccountBankStatementLine(models.Model):
6666 domain = [("rule_type" , "=" , "writeoff_button" )],
6767 )
6868 manual_name = fields .Char (store = False , default = False , prefetch = False )
69- manual_amount = fields .Monetary (store = False , default = False , prefetch = False )
69+ manual_amount = fields .Monetary (
70+ store = False , default = False , prefetch = False , currency_field = "manual_currency_id"
71+ )
72+ manual_currency_id = fields .Many2one (
73+ "res.currency" , readonly = True , store = False , prefetch = False
74+ )
7075 manual_original_amount = fields .Monetary (
7176 default = False , store = False , prefetch = False , readonly = True
7277 )
@@ -240,13 +245,15 @@ def _onchange_manual_reconcile_reference(self):
240245 "manual_move_type" : False ,
241246 "manual_kind" : False ,
242247 "manual_original_amount" : False ,
248+ "manual_currency_id" : False ,
243249 "analytic_distribution" : False ,
244250 }
245251 )
246252 continue
247253 else :
248254 self .manual_account_id = line ["account_id" ][0 ]
249255 self .manual_amount = line ["amount" ]
256+ self .manual_currency_id = line ["currency_id" ]
250257 self .manual_name = line ["name" ]
251258 self .manual_partner_id = (
252259 line .get ("partner_id" ) and line ["partner_id" ][0 ]
@@ -323,7 +330,9 @@ def _compute_reconcile_data_info(self):
323330 if record .reconcile_data :
324331 record .reconcile_data_info = record .reconcile_data
325332 else :
326- record .reconcile_data_info = record ._default_reconcile_data ()
333+ record .reconcile_data_info = record ._default_reconcile_data (
334+ from_unreconcile = record .is_reconciled
335+ )
327336 record .can_reconcile = record .reconcile_data_info .get (
328337 "can_reconcile" , False
329338 )
@@ -418,35 +427,44 @@ def _compute_exchange_rate(self, data, reconcile_auxiliary_id):
418427 reconcile_auxiliary_id += 1
419428 return reconcile_auxiliary_id
420429
421- def _default_reconcile_data (self ):
430+ def _default_reconcile_data (self , from_unreconcile = False ):
422431 liquidity_lines , suspense_lines , other_lines = self ._seek_for_lines ()
423432 data = [self ._get_reconcile_line (line , "liquidity" ) for line in liquidity_lines ]
424433 reconcile_auxiliary_id = 1
425- res = (
426- self .env ["account.reconcile.model" ]
427- .search ([("rule_type" , "in" , ["invoice_matching" , "writeoff_suggestion" ])])
428- ._apply_rules (self , self ._retrieve_partner ())
429- )
430- if res and res .get ("status" , "" ) == "write_off" :
431- return self ._recompute_suspense_line (
432- * self ._reconcile_data_by_model (
433- data , res ["model" ], reconcile_auxiliary_id
434- ),
435- self .manual_reference
436- )
437- elif res and res .get ("amls" ):
438- amount = self .amount_total_signed
439- for line in res .get ("amls" , []):
440- line_data = self ._get_reconcile_line (
441- line , "other" , is_counterpart = True , max_amount = amount
434+ if not from_unreconcile :
435+ res = (
436+ self .env ["account.reconcile.model" ]
437+ .search (
438+ [("rule_type" , "in" , ["invoice_matching" , "writeoff_suggestion" ])]
442439 )
443- amount -= line_data .get ("amount" )
444- data .append (line_data )
445- return self ._recompute_suspense_line (
446- data , reconcile_auxiliary_id , self .manual_reference
440+ ._apply_rules (self , self ._retrieve_partner ())
447441 )
442+ if res and res .get ("status" , "" ) == "write_off" :
443+ return self ._recompute_suspense_line (
444+ * self ._reconcile_data_by_model (
445+ data , res ["model" ], reconcile_auxiliary_id
446+ ),
447+ self .manual_reference
448+ )
449+ elif res and res .get ("amls" ):
450+ amount = self .amount_total_signed
451+ for line in res .get ("amls" , []):
452+ line_data = self ._get_reconcile_line (
453+ line , "other" , is_counterpart = True , max_amount = amount
454+ )
455+ amount -= line_data .get ("amount" )
456+ data .append (line_data )
457+ return self ._recompute_suspense_line (
458+ data , reconcile_auxiliary_id , self .manual_reference
459+ )
448460 return self ._recompute_suspense_line (
449- data + [self ._get_reconcile_line (line , "other" ) for line in other_lines ],
461+ data
462+ + [
463+ self ._get_reconcile_line (
464+ line , "other" , from_unreconcile = from_unreconcile
465+ )
466+ for line in other_lines
467+ ],
450468 reconcile_auxiliary_id ,
451469 self .manual_reference ,
452470 )
@@ -458,9 +476,11 @@ def clean_reconcile(self):
458476 def reconcile_bank_line (self ):
459477 self .ensure_one ()
460478 self .reconcile_mode = self .journal_id .reconcile_mode
461- return getattr (self , "_reconcile_bank_line_%s" % self .reconcile_mode )(
479+ result = getattr (self , "_reconcile_bank_line_%s" % self .reconcile_mode )(
462480 self .reconcile_data_info ["data" ]
463481 )
482+ self .reconcile_data_info = False
483+ return result
464484
465485 def _reconcile_bank_line_edit (self , data ):
466486 _liquidity_lines , suspense_lines , other_lines = self ._seek_for_lines ()
@@ -574,12 +594,13 @@ def unreconcile_bank_line(self):
574594 self .ensure_one ()
575595 return getattr (
576596 self , "_unreconcile_bank_line_%s" % (self .reconcile_mode or "edit" )
577- )(self . reconcile_data_info [ "data" ] )
597+ )()
578598
579- def _unreconcile_bank_line_edit (self , data ):
599+ def _unreconcile_bank_line_edit (self ):
600+ self .reconcile_data_info = self ._default_reconcile_data (from_unreconcile = True )
580601 self .action_undo_reconciliation ()
581602
582- def _unreconcile_bank_line_keep (self , data ):
603+ def _unreconcile_bank_line_keep (self ):
583604 raise UserError (_ ("Keep suspense move lines mode cannot be unreconciled" ))
584605
585606 def _reconcile_move_line_vals (self , line , move_id = False ):
0 commit comments