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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Contabilidad
- Inventario
- PoS
- Project
- MRP
Se marcó esta pregunta
2490
Vistas
¿Le interesa esta conversación? ¡Participe en ella!
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
InscribirsePublicaciones relacionadas | Respuestas | Vistas | Actividad | |
---|---|---|---|---|
|
1
feb 24
|
1594 | ||
|
0
jul 22
|
60 | ||
|
1
jul 22
|
2458 | ||
|
2
dic 23
|
33054 | ||
|
3
may 21
|
3577 |