mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[MIG][16.0] account_move_base_import : migration to 16
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
# Copyright 2011-2016 Akretion
|
||||
# Copyright 2011-2022 Akretion
|
||||
# Copyright 2011-2019 Camptocamp SA
|
||||
# Copyright 2013 Savoir-faire Linux
|
||||
# Copyright 2014 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
{
|
||||
"name": "Journal Entry base import",
|
||||
"version": "14.0.1.0.1",
|
||||
"version": "16.0.1.0.1",
|
||||
"author": "Akretion,Camptocamp,Odoo Community Association (OCA)",
|
||||
"category": "Finance",
|
||||
"depends": ["account"],
|
||||
|
||||
@@ -103,27 +103,27 @@ class AccountJournal(models.Model):
|
||||
"already_completed": True,
|
||||
"journal_id": self.id,
|
||||
"company_id": self.company_id.id,
|
||||
"currency_id": self.currency_id.id,
|
||||
"currency_id": self.currency_id.id or move.currency_id.id,
|
||||
"company_currency_id": self.company_id.currency_id.id,
|
||||
"amount_residual": amount,
|
||||
}
|
||||
return counterpart_values
|
||||
|
||||
def _create_counterpart(self, parser, move):
|
||||
move_line_obj = self.env["account.move.line"]
|
||||
def _get_counterpart_vals_list(self, parser, move, line_vals_list):
|
||||
refund = 0.0
|
||||
payment = 0.0
|
||||
commission = 0.0
|
||||
transfer_lines = []
|
||||
for move_line in move.line_ids:
|
||||
if (
|
||||
move_line.account_id == self.commission_account_id
|
||||
and move_line.already_completed
|
||||
for move_line_vals in line_vals_list:
|
||||
if move_line_vals[
|
||||
"account_id"
|
||||
] == self.commission_account_id.id and move_line_vals.get(
|
||||
"already_completed"
|
||||
):
|
||||
commission -= move_line.debit
|
||||
commission -= move_line_vals["debit"]
|
||||
else:
|
||||
refund -= move_line.debit
|
||||
payment += move_line.credit
|
||||
refund -= move_line_vals["debit"]
|
||||
payment += move_line_vals["credit"]
|
||||
if self.split_counterpart:
|
||||
if refund:
|
||||
transfer_lines.append(refund)
|
||||
@@ -135,17 +135,15 @@ class AccountJournal(models.Model):
|
||||
transfer_lines.append(total_amount)
|
||||
counterpart_date = parser.get_move_vals().get("date") or fields.Date.today()
|
||||
transfer_line_count = len(transfer_lines)
|
||||
check_move_validity = False
|
||||
vals_list = []
|
||||
for amount in transfer_lines:
|
||||
transfer_line_count -= 1
|
||||
if not transfer_line_count:
|
||||
check_move_validity = True
|
||||
vals = self._prepare_counterpart_line(move, amount, counterpart_date)
|
||||
move_line_obj.with_context(check_move_validity=check_move_validity).create(
|
||||
vals
|
||||
vals_list.append(
|
||||
self._prepare_counterpart_line(move, amount, counterpart_date)
|
||||
)
|
||||
return vals_list
|
||||
|
||||
def _write_extra_move_lines(self, parser, move):
|
||||
def _get_extra_move_line_vals_list(self, parser, move):
|
||||
"""Insert extra lines after the main statement lines.
|
||||
|
||||
After the main statement lines have been created, you can override this
|
||||
@@ -158,9 +156,9 @@ class AccountJournal(models.Model):
|
||||
statement ID
|
||||
:param: context: global context
|
||||
"""
|
||||
move_line_obj = self.env["account.move.line"]
|
||||
global_commission_amount = 0
|
||||
commmission_field = parser.commission_field
|
||||
vals_list = []
|
||||
if commmission_field:
|
||||
for row in parser.result_row_list:
|
||||
global_commission_amount += float(row.get(commmission_field, "0.0"))
|
||||
@@ -203,9 +201,8 @@ class AccountJournal(models.Model):
|
||||
comm_values.update(
|
||||
{"analytic_account_id": self.commission_analytic_account_id.id}
|
||||
)
|
||||
move_line_obj.with_context(check_move_validity=False).create(
|
||||
comm_values
|
||||
)
|
||||
vals_list.append(comm_values)
|
||||
return vals_list
|
||||
|
||||
def write_logs_after_import(self, move, num_lines):
|
||||
"""Write the log in the logger
|
||||
@@ -255,7 +252,7 @@ class AccountJournal(models.Model):
|
||||
values.update(
|
||||
{
|
||||
"company_id": self.company_id.id,
|
||||
"currency_id": self.currency_id.id,
|
||||
"currency_id": self.currency_id.id or move.currency_id.id,
|
||||
"company_currency_id": self.company_id.currency_id.id,
|
||||
"journal_id": self.id,
|
||||
"account_id": account.id,
|
||||
@@ -266,8 +263,6 @@ class AccountJournal(models.Model):
|
||||
"reconciled": False,
|
||||
}
|
||||
)
|
||||
if self.currency_id and self.currency_id == self.company_id.currency_id:
|
||||
del values["currency_id"]
|
||||
values = move_line_obj._add_missing_default_values(values)
|
||||
return values
|
||||
|
||||
@@ -361,12 +356,13 @@ class AccountJournal(models.Model):
|
||||
parser_vals = parser.get_move_line_vals(line)
|
||||
values = self.prepare_move_line_vals(parser_vals, move)
|
||||
move_store.append(values)
|
||||
move_line_obj.with_context(check_move_validity=False).create(move_store)
|
||||
self._write_extra_move_lines(parser, move)
|
||||
move_store += self._get_extra_move_line_vals_list(parser, move)
|
||||
if self.create_counterpart:
|
||||
self._create_counterpart(parser, move)
|
||||
move_store += self._get_counterpart_vals_list(parser, move, move_store)
|
||||
# Check if move is balanced
|
||||
move._check_balanced()
|
||||
container = {"records": move}
|
||||
with move._check_balanced(container):
|
||||
move_line_obj.create(move_store)
|
||||
# Computed total amount of the move
|
||||
# move._amount_compute()
|
||||
# Attach data to the move
|
||||
|
||||
@@ -28,7 +28,7 @@ class TestInvoice(TestAccountReconciliationCommon):
|
||||
self.assertEqual(self.invoice_for_completion_1.state, "posted")
|
||||
self.assertEqual(
|
||||
self.invoice_for_completion_1.name,
|
||||
fields.Date.today().strftime("INV/%Y/%m/0001"),
|
||||
fields.Date.today().strftime("INV/%Y/00001"),
|
||||
)
|
||||
|
||||
self.demo_invoice_0 = self._create_invoice(
|
||||
@@ -41,7 +41,7 @@ class TestInvoice(TestAccountReconciliationCommon):
|
||||
)
|
||||
self.assertEqual(
|
||||
self.refund_for_completion_1.name,
|
||||
fields.Date.today().strftime("RINV/%Y/%m/0001"),
|
||||
fields.Date.today().strftime("RINV/%Y/00001"),
|
||||
)
|
||||
|
||||
# In order to test the banking framework, I first need to create a
|
||||
@@ -151,13 +151,13 @@ class TestInvoice(TestAccountReconciliationCommon):
|
||||
)
|
||||
# and add the correct name
|
||||
move_line_ci.with_context(check_move_validity=False).write(
|
||||
{"name": fields.Date.today().strftime("INV/%Y/%m/0001"), "credit": 210.0}
|
||||
{"name": fields.Date.today().strftime("INV/%Y/00001"), "credit": 210.0}
|
||||
)
|
||||
move_line_si.with_context(check_move_validity=False).write(
|
||||
{"name": "T2S12345", "debit": 65.0}
|
||||
)
|
||||
move_line_cr.with_context(check_move_validity=False).write(
|
||||
{"name": fields.Date.today().strftime("RINV/%Y/%m/0001"), "debit": 210.0}
|
||||
{"name": fields.Date.today().strftime("RINV/%Y/00001"), "debit": 210.0}
|
||||
)
|
||||
move_line_partner_name.with_context(check_move_validity=False).write(
|
||||
{"credit": 600.0}
|
||||
|
||||
Reference in New Issue
Block a user