Skip to content

Commit

Permalink
[IMP] internal_transfer_with_agreed_amount: modify write vals in one …
Browse files Browse the repository at this point in the history
…method

Changelog:
- Set debit and credit values to write in _prepare_values_from_lines
  method when the exchange currency is the same as the company currency.
- Add methods to be inherited when payments also needs modifications.
  • Loading branch information
CLaurelB committed Nov 3, 2023
1 parent 5fc9d27 commit 207c450
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,23 @@ def _validate_currencies_in_internal_transfer(self, payment):
)
)

def _prepare_values_from_lines(self, lines, currency):
def _prepare_values_from_lines(self, lines, currency=None, is_same_company_currency=False):
line = lines[0]
if is_same_company_currency:
return {"debit": self.agreed_amount} if line.debit > 0 else {"credit": self.agreed_amount}
vals = {"debit": line.debit} if line.amount_currency > 0 else {"credit": line.credit}
sign = 1 if line.amount_currency > 0 else -1
vals.update({"amount_currency": sign * self.agreed_amount, "currency_id": currency.id})
return vals

def _preprocessing_payment_with_agreed_amount(self, payment):
"""This method is to be inherited in case pre-processing is required on the payments."""
return

def _postprocessing_payment_with_agreed_amount(self, payment):
"""This method is to be inherited in case post-processing is required on the payments."""
return

def apply(self):
active_ids = self._context.get("active_ids")
active_model = self._context.get("active_model")
Expand All @@ -58,14 +68,19 @@ def apply(self):
to_reconcile = amls.filtered(
lambda l: l.account_id == l.company_id.transfer_account_id
).full_reconcile_id.reconciled_line_ids
context = {"check_move_validity": False, "skip_account_move_synchronization": True}
if exchange_currency == payment.company_currency_id:
if len(amls) != 4:
return
amls.move_id.button_draft()
self._preprocessing_payment_with_agreed_amount(payment)
debit = amls.filtered(lambda x: x.debit > 0)
credit = amls.filtered(lambda x: x.credit > 0)
debit.with_context(check_move_validity=False).write({"debit": self.agreed_amount})
credit.with_context(check_move_validity=False).write({"credit": self.agreed_amount})
vals = self._prepare_values_from_lines(debit, is_same_company_currency=True)
debit.with_context(**context).write(vals)
vals = self._prepare_values_from_lines(credit, is_same_company_currency=True)
credit.with_context(**context).write(vals)
self._postprocessing_payment_with_agreed_amount(payment)
amls.move_id.action_post()
to_reconcile.reconcile()
return
Expand All @@ -74,10 +89,11 @@ def apply(self):
if len(aml_positive) > 2 or len(aml_negative) > 2:
return
aml_positive.move_id.button_draft()
context = {"check_move_validity": False, "skip_account_move_synchronization": True}
self._preprocessing_payment_with_agreed_amount(payment)
vals = self._prepare_values_from_lines(aml_positive, exchange_currency)
aml_positive.with_context(**context).write(vals)
vals = self._prepare_values_from_lines(aml_negative, exchange_currency)
aml_negative.with_context(**context).write(vals)
self._postprocessing_payment_with_agreed_amount(payment)
aml_positive.move_id.action_post()
to_reconcile.reconcile()

0 comments on commit 207c450

Please sign in to comment.