Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda

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
Buang

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

Penulis

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?

Post Terkait Replies Tampilan Aktivitas
2
Jul 24
3399
1
Mei 25
3959
2
Jul 19
3263
0
Mei 16
3947
2
Apr 16
5980