Skip to Content
Menu
This question has been flagged
from odoo import models, fields, api

class AccountMove(models.Model):
​_inherit='account.move'
​invoice_cash_rounding_id=fields.Many2one('account.cash.rounding', compute='_compute_rounding_id', store=True)

​@api.depends('move_type', 'state', 'line_ids.display_type')
​def_compute_rounding_id(self):
​roundoff_id=self.env.ref('round_off.inv_roundoff')
​for move in self:
​if move.move_type =='out_invoice' and move.state not in ('posted', 'cancel'):
​# Check if any line has display_type set to 'rounding'
​has_rounding_line=any(line.display_type =='rounding' for line in move.line_ids)
​if not has_rounding_line:
​move.invoice_cash_rounding_id =roundoff_id

I have created a custom module to compute the invoice_cash_rounding_id when creating invoice, but the method is trying to delete posted entries and calls this method :
https://github.com/odoo/odoo/blob/0000bfd406d057cfa5d7b6cbbb070b7ecd556bc0/addons/account/models/account_move_line.py#L1536
and then this raises a user error and user is unable to open the invoice


Avatar
Discard
Related Posts Replies Views Activity
1
May 23
2751
0
Feb 24
1775
1
Feb 24
4292
0
Feb 24
2079
0
Jul 23
2061