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
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
2478
Views
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Feb 24
|
1571 | ||
|
0
Jul 22
|
60 | ||
|
1
Jul 22
|
2446 | ||
|
2
Dec 23
|
33027 | ||
|
3
May 21
|
3558 |