Skip to content

Commit

Permalink
[FIX] l10n_br_account: create with original order
Browse files Browse the repository at this point in the history
create should return the records in the initial order
of the vals_list to avoid side effects.
  • Loading branch information
rvalyi committed May 13, 2024
1 parent ecf1bb9 commit 418020b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions l10n_br_account/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,30 @@ def create(self, vals_list):
# fiscal document (which is a manipulated vals_list), it results in erroneous
# associations.
if len(vals_list) > 1 and self.env.company.country_id.code == "BR":
# Store the original order using a copy of the data
original_vals_list = list(vals_list)
# Add index to each dictionary in vals_list
indexed_vals_list = [(idx, val) for idx, val in enumerate(vals_list)]

# Reorder vals_list for processing based on the presence of
# 'fiscal_operation_line_id'
vals_list = sorted(
vals_list,
key=lambda x: x.get("fiscal_operation_line_id") is False,
sorted_indexed_vals_list = sorted(
indexed_vals_list,
key=lambda x: x[1].get("fiscal_operation_line_id") is False,
)
original_indexes = [idx for idx, _ in sorted_indexed_vals_list]
vals_list = [val for _, val in sorted_indexed_vals_list]

# Create the records
results = super(
result = super(
AccountMoveLine, self.with_context(create_from_move_line=True)
).create(vals_list)

return results
if len(vals_list) > 1 and self.env.company.country_id.code == "BR":
sorted_result = self["account.move.line"]
for i in original_indexes:
sorted_result |= result[i]
result = sorted_result

return result

def write(self, values):
if values.get("product_uom_id"):
Expand Down

0 comments on commit 418020b

Please sign in to comment.