Hello all,
I am already spending hours trying to find a solution to my problem.
I hope that I can be helped here.
I want to display information about sale products of the customer in the res.partner view. The needed information should be computed.
I have placed a computed many2many field in res.partner, which references my custom model, with the fields to be filled by the compute function. These fields should then be displayed in the view.
However, the model with the computed fields should not be stored in the database.
I use odoo v16
---- Custom Model to cache data for view
from odoo import fields, models
class CustomerProductTest(models.AbstractModel):
_name = 'customer.product.test'
product_name = fields.Char(
string="Product Name"
)
---- res.partner inherit
class ResPartner(models.Model):
_inherit = 'res.partner'
customer_products = fields.Many2many('customer.product.test', compute="_compute_customer_products_test", store=False)
def _compute_customer_products_test(self):
for record in self:
sale_lines = self.env['sale.order.line'].search(['&',('order_partner_id','=',record.id),('invoice_status', '!=', 'no')])
for sale_line in sale_lines:
product_values = {
'product_name': sale_line.product_id.name
}
cust_prod = self.env['customer.product.test'].new(product_values)
record.customer_products = [(6, 0 ,cust_prod)]
----
I have tried with new or create and other variants of assignment. However, there is no data in the view. Only if I use Model instead of AbstractModel with create I get data, but then also the temporarily needed model is stored in the database, which I don't want.
For any tips I am grateful
Many thanks
Denna fråga har flaggats
5778
Vyer
Njuter du av diskussionen? Läs inte bara, delta också!
Skapa ett konto idag för att ta del av exklusiva funktioner och engagera dig i vår fantastiska community!
Registrera dig| Relaterade inlägg | Svar | Vyer | Verksamhet | |
|---|---|---|---|---|
|
|
1
feb. 24
|
4325 | ||
|
|
0
juli 22
|
60 | ||
|
|
1
juli 22
|
5230 | ||
|
|
2
dec. 23
|
35975 | ||
|
|
3
maj 21
|
5868 |