Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16.0 fix mcurr tests #2

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions account_reconcile_oca/models/account_bank_statement_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,29 @@
)._default_reconcile_data()
self.can_reconcile = self.reconcile_data_info.get("can_reconcile", False)

def _get_amount_currency(self, line, dest_curr):
if line["line_currency_id"] == dest_curr.id:
amount = line["currency_amount"]
else:
amount = self.company_id.currency_id._convert(

Check warning on line 192 in account_reconcile_oca/models/account_bank_statement_line.py

View check run for this annotation

Codecov / codecov/patch

account_reconcile_oca/models/account_bank_statement_line.py#L192

Added line #L192 was not covered by tests
line["amount"],
dest_curr,
self.company_id,
self.date,
)
return amount

@api.onchange("add_account_move_line_id")
def _onchange_add_account_move_line_id(self):
if self.add_account_move_line_id:
data = self.reconcile_data_info["data"]
new_data = []
is_new_line = True
pending_amount = 0.0
currency = self._get_reconcile_currency()
for line in data:
if line["kind"] != "suspense":
pending_amount += currency._convert(
line["currency_amount"],
self.env["res.currency"].browse(
line.get("line_currency_id", currency.id)
),
self.company_id,
self.date,
pending_amount += self._get_amount_currency(
line, self._get_reconcile_currency()
)
if self.add_account_move_line_id.id in line.get(
"counterpart_line_ids", []
Expand Down Expand Up @@ -425,6 +431,10 @@
for line in data:
if line["reference"] == self.manual_reference:
if self._check_line_changed(line):
if line["line_currency_id"] == self.company_id.currency_id.id:
currency_amount = self.manual_amount
else:
currency_amount = self.manual_amount_in_currency
line.update(
{
"name": self.manual_name,
Expand All @@ -442,7 +452,7 @@
if self.manual_amount > 0
else 0.0,
"analytic_distribution": self.analytic_distribution,
"currency_amount": self.manual_amount_in_currency,
"currency_amount": currency_amount,
"kind": line["kind"]
if line["kind"] != "suspense"
else "other",
Expand Down Expand Up @@ -578,6 +588,7 @@
self.manual_reference,
)
elif res and res.get("amls"):
# TODO should be signed in currency get_reconcile_currency
amount = self.amount_total_signed
for line in res.get("amls", []):
reconcile_auxiliary_id, line_data = self._get_reconcile_line(
Expand Down Expand Up @@ -881,7 +892,7 @@
self.manual_reference,
)
elif res.get("amls"):
amount = self.amount
amount = self.amount_currency or self.amount
for line in res.get("amls", []):
reconcile_auxiliary_id, line_datas = record._get_reconcile_line(
line, "other", is_counterpart=True, max_amount=amount, move=True
Expand Down Expand Up @@ -1037,7 +1048,7 @@
self.company_id,
self.date,
)
return to_amount - amount
return self.company_id.currency_id.round(to_amount - amount)

def _compute_exchange_rate(
self,
Expand Down Expand Up @@ -1106,7 +1117,7 @@

def _get_reconcile_currency(self):
return (
self.currency_id
self.foreign_currency_id
or self.journal_id.currency_id
or self.company_id._currency_id
or self.company_id.currency_id
)
24 changes: 16 additions & 8 deletions account_reconcile_oca/models/account_reconcile_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,25 @@
):
date = self.date if "date" in self._fields else line.date
original_amount = amount = net_amount = line.debit - line.credit
line_currency = line.currency_id
if is_counterpart:
currency_amount = -line.amount_residual_currency or line.amount_residual
amount = -line.amount_residual
currency = line.currency_id or line.company_id.currency_id
original_amount = net_amount = -line.amount_residual
if max_amount:
real_currency_amount = currency._convert(
currency_amount,
self._get_reconcile_currency(),
self.company_id,
date,
)
dest_currency = self._get_reconcile_currency()
if currency == dest_currency:
real_currency_amount = currency_amount
elif self.company_id.currency_id == dest_currency:
real_currency_amount = amount

Check warning on line 61 in account_reconcile_oca/models/account_reconcile_abstract.py

View check run for this annotation

Codecov / codecov/patch

account_reconcile_oca/models/account_reconcile_abstract.py#L61

Added line #L61 was not covered by tests
else:
real_currency_amount = self.company_id.currency_id._convert(

Check warning on line 63 in account_reconcile_oca/models/account_reconcile_abstract.py

View check run for this annotation

Codecov / codecov/patch

account_reconcile_oca/models/account_reconcile_abstract.py#L63

Added line #L63 was not covered by tests
amount,
dest_currency,
self.company_id,
date,
)
if (
-real_currency_amount > max_amount > 0
or -real_currency_amount < max_amount < 0
Expand All @@ -76,7 +83,8 @@
date,
)
else:
currency_amount = line.amount_currency
currency_amount = self.amount_currency or self.amount
line_currency = self._get_reconcile_currency()
vals = {
"move_id": move and line.move_id.id,
"move": move and line.move_id.name,
Expand All @@ -91,7 +99,7 @@
"amount": amount,
"net_amount": amount - net_amount,
"currency_id": self.company_id.currency_id.id,
"line_currency_id": line.currency_id.id,
"line_currency_id": line_currency.id,
"currency_amount": currency_amount,
"analytic_distribution": line.analytic_distribution,
"kind": kind,
Expand Down
Loading
Loading