콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
15705 화면

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,

}}

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

아바타
취소
베스트 답변

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.


아바타
취소

Hi Hilar,

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

베스트 답변

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


아바타
취소
관련 게시물 답글 화면 활동
2
4월 19
6445
0
2월 18
2976
2
1월 16
35722
1
8월 22
7709
1
8월 20
4787