OCA/account-financial-tools

[14.0, 15.0] account_move_name_sequence: default of account.journal field 'refund_sequence' not respected in method 'create'

azoellner opened this issue · 6 comments

In module "account_move_name_sequence" (of branches "14.0" and "15.0"), the default of account.journal field refund_sequence is changed to True. (Compare e.g. the original in module "account" of branch "14.0"). But this changed default value then is not taken into account in the overwritten method create().

Expected behavior

There should actually be a refund_sequence_id whenever the refund_sequence is True.

Current behavior

If not explicitly providing the refund_sequence (and also no explicit refund_sequence_id) when creating an account.journal record of type "sale" or "purchase", no refund_sequence_id will get created, but refund_sequence will be True.

Causes

In module "account", the value of field refund_sequence is explicitly added to the argument vals during create(), by calling _fill_missing_values(): For "sale" and "purchase" journals, it will be True, and False for all other journal types.
But here in module "account_move_name_sequence", this super method create() is called (and correctly so) only after the creation of the sequences.
As a consequence, if not explicitly providing refund_sequence (and also no refund_sequence_id) when creating an account.journal record of type "sale" or "purchase", no refund_sequence_id will get created (because vals.get("refund_sequence") will be False). But then during the super call, field refund_sequence will be set to True.

Proposed fix

As a fix, do add True as the explicit default when getting refund_sequence from the vals:

             vals["sequence_id"] = self._create_sequence(vals).id
         if (
             vals.get("type") in ("sale", "purchase")
-            and vals.get("refund_sequence")
+            and vals.get("refund_sequence", True)
             and not vals.get("refund_sequence_id")
         ):
             vals["refund_sequence_id"] = self._create_sequence(vals, refund=True).id

In general, getting a value from the vals should always be done with the same default as the field's definition.

Same bug in V16.0 i am resolve it in PR #1510 in commit df45bac

@moylop260 do you have this issue?

@rafaelbn

No, I was not aware

@RodrigoBM
Could you fix it in v14.0 and v15.0, please?

@moylop260 close this issue, thanks

Fixed from #1520 and #1521