Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
15722 Lượt xem

I have an onchange method describe in the model and based on that values i want to store values in the read-only fields, its happen buts while saving its gone.
######################################

@api.onchange('product_id')

def onchange_product_id(self):

cr = self.env.cr

desc = ''

uom = -1

for rec in self:

cr.execute('''SELECT

product_uom.id AS uom,

product_template.name AS desc,

product_hsn_tax_code.hsn_name AS hsn_code,

product_hsn_tax_code.tax_percentage AS gst_value

FROM

product_uom JOIN

product_template ON

product_uom.id=product_template.uom_id JOIN

product_product ON

product_template.id=product_product.product_tmpl_id JOIN

product_hsn_tax_code ON

product_hsn_tax_code.id=product_template.hsn_id

WHERE

product_product.id = cast(%s AS INTEGER)''', ((rec.product_id.id),))

for line in cr.dictfetchall():

uom = line['uom']

desc = line['desc']

return {'value' :{

'uom_id':uom,

'description':desc,

}}

########################################

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

onchange method doesn't store the read-only field values on the database.To do so you have to update the values dict of create and write methods. So better option is to store value inside the fields dict before the actual create method invokes.

override create and write function and do the same operation or store the value on the read-only field.


Ảnh đại diện
Huỷ bỏ

Hi Hilar,

can you help how to update the values dict? What would the the overridden write function look like?

Câu trả lời hay nhất

You can do this using overriding create and write method of odoo. Here the question is why we need to override these (create, write and unlink) methods.

The answer is to add or remove additional functionality we use overriding. For example if I want to check some constraints before creating, editing or deleting our record than we may use Odoo override methods.

There are basically three methods which we can override.

  1. Create

  2. Write

  3. Unlink


To complete code and code description read: http://learnopenerp.blogspot.com/2017/11/how-to-override-odoo-functions.html


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 4 19
6462
0
thg 2 18
2988
2
thg 1 16
35729
1
thg 8 22
7721
1
thg 8 20
4793