コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2505 ビュー

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

アバター
破棄
関連投稿 返信 ビュー 活動
1
2月 24
1615
0
7月 22
60
1
7月 22
2475
2
12月 23
33064
3
5月 21
3580