Dear All,
I am trying to add a field in purchases to display all the Partners from the Sale Orders that are linked to the Purchase.
I have the following code, and I am facing an issue:
When I do not use “store=True“ the function works correctly and displays the partners. However, in order to save the Partners in Purchases that are not linked to any sale order (since I have a compute method in my field), I set “store=True“ but then the first case does not work.
In other words, when I do not use store, the function works correctly and the customer is displayed. However, when I set store, the function does not work, and the related partners do not appear, although the new partners are saved correctly in the Purchase.
What am I missing, and how can I fix this?
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
name_ids = fields.Many2many(comodel_name='res.partner',compute='_compute_customer_names',
string="Customers",store=True)
def _compute_customer_names(self):
for purchase in self:
sale_order_ids = purchase._get_sale_orders()
for sale_order in sale_order_ids:
purchase.name_ids = sale_order.partner_id