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
Dette spørgsmål er blevet anmeldt
5600
Visninger
Kan du lide at diskutere? Læs ikke bare med, deltag aktivt i debatten!
Opret en konto i dag for at få glæde af eksklusive funktioner, og bliv en del af vores skønne fællesskab!
Tilmeld dig| Relaterede indlæg | Besvarelser | Visninger | Aktivitet | |
|---|---|---|---|---|
|
|
1
feb. 24
|
4145 | ||
|
|
0
jul. 22
|
60 | ||
|
|
1
jul. 22
|
5120 | ||
|
|
2
dec. 23
|
35879 | ||
|
|
3
maj 21
|
5813 |