Skip to Content
Menu
This question has been flagged

In Odoo 17 purchase.order has invoices:

invoice_ids = fields.Many2many('account.move', compute="_compute_invoice", string='Bills', copy=False, store=True)

and each account.move has a purchase:

purchase_id = fields.Many2one('purchase.order', store=False, readonly=False,
string='Purchase Order',
help="Auto-complete from a past purchase order.")

I added a simple field in Purchase:

class PurchaseOrder(models.Model):
_inherit = "purchase.order"
accounting_note = fields.Char()

and want to show this field's value in each related Invoice, too:

class AccountMove(models.Model):
_inherit = "account.move"
accounting_note = fields.Char(readonly=True)

So far I tried to compute it in AccountMove, but failed:

accounting_note = fields.Char(compute="_compute_accounting_note")

@api.depends("purchase_id")
def _compute_accounting_note(self):
for record in self:
record.accounting_note = record.purchase_id.accounting_note

and to set it onchange in PurchaseOrder (write is not allowed here, according to docs), but failed too:

@api.onchange("accounting_note")
def _update_accounting_notes(self):
for record in self:
for invoice in record.invoice_ids:
invoice.accounting_note = record.accounting_note

In Purchase Order the value is fine, but it never appeared in the Invoices.
I suppose this due to certain limitations of the store/computed M2M/O2M fields.
How do I get this right?

Avatar
Discard

Hello,
Have you tried in below method?
def _prepare_invoice(self):
res = super()._prepare_invoice()
res["accounting_note"] = self.accounting_note
return res
Keep acounting_note field as it is in account.move

Author

This would only set the field for new (created) invoices.
I would prefer to fill/get this field's value for all invoices on change, not only new ones.

You can configure schedule action for old records. Is it feasible for your customization?

Related Posts Replies Views Activity
2
Jul 24
3382
1
May 25
3952
2
Jul 19
3258
0
May 16
3940
2
Apr 16
5974