Skip to Content
Menu
This question has been flagged
The question has been closed for reason: off-topic or not relevant
by BRAHIM El-houcine on 04/15/2024 04:04:02
1486 Views

I am working with Odoo and facing an issue where changes made to the journal_id in the account.move model's default_get method are not reflected in the UI for credit notes, although the debug shows that the changes are applied. This problem does not occur with invoices when removing a specific condition. Here is the code snippet:

class AccountMove(models.Model):
    _inherit = 'account.move'

    @api.model
    def default_get(self, fields_list):
        res = super().default_get(fields_list)
        journal = self.env.company.credit_notes_journal_id
        context = self._context.get('default_move_type')
        if 'journal_id' in res and journal and context == 'out_refund':
            res['journal_id'] = journal.id
        return res

he journal_id is correctly set when the condition meets for credit notes (out_refund), as verified by debugging. However, the UI does not reflect this change and shows a different journal than the one specified.

I have ensured that:

  • There are no other overrides of default_get causing conflicts.
  • There isn't an unnoticed @api.onchange method that might affect this behavior.
  • This setup works as expected for invoices but not for credit notes.

Question:

Is there a mechanism or method prior to default_get that sets or overrides the value of journal_id before the form view is loaded? Or am I missing an @api.onchange decorator that is required for the UI to reflect the changes made in default_get? Additionally, why does this approach work for invoices but not for credit notes?

Additional Context:

This behavior is consistent across all custom modules; there is no modification of the journal elsewhere. Debugging suggests that this default_get method is the last to execute before the form view is rendered.

Any guidance or insights into this issue would be greatly appreciated. Thank you!


Avatar
Discard
Related Posts Replies Views Activity
0
Feb 24
781
1
Jun 23
5550
0
Apr 23
1502
0
Feb 23
1556
1
Jan 22
2469