Skip to Content
Menu
This question has been flagged
5 Replies
1883 Views

I have a related many2one field in my stock operations. It is related from the purchase order; ex: if your PO has the project NARANJA, the picking from that PO will have NARANJA inherted.


The problem is that when I create I move WITHOUT PO, the analytic_account_id is not saved correctly.

EXAMPLE

The code from the field:


class Picking(models.Model):
_inherit = 'stock.picking'

analytic_account_id = fields.Many2one(
comodel_name='account.analytic.account', string='Project', related='purchase_id.analytic_account_id',
store=True,)
Avatar
Discard
Author Best Answer

The problem was that I added readonly. Than you al for your attention.

Avatar
Discard
Best Answer

Sorry I wanted to comment but I'm really new in forum.

Can you in any way (for me with psql shell) see that your project still exist in PSQL database (before and after the problem occur) ?

And perhaps you can provide all models code that is related to the problem? Maybe there's a loophole in there somewhere that people could see.

Avatar
Discard

I'm really sorry but for some reason I can't recreate the problem since the module doesn't show the Project field when I create delivery note in my odoo. Maybe others can recreate the problem and find a solution.

Perhaps this is nothing but in your analytic_account_id's many2one method I don't see an ondelete parameter. See the link to know what I meant: https://www.odoo.com/documentation/12.0/howtos/backend.html#relations-between-models

Author

I'm sure at 99% that the problem is tat is a related field and, when Odoo reads that the field has no relation, heputs it to 0. Do you know how to create an exception if the related field ahs no relation save it anyway?¡