Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
101 Zobrazení

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
Zrušit

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

Autor

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 Odpovědi Zobrazení Aktivita
2
čvc 24
3387
1
kvě 25
3957
2
čvc 19
3261
0
kvě 16
3941
2
dub 16
5976