2017-09-12 4 views
1

나는사용자 정의 필드를 작성 모드에서 저장할 수없는 이유는 odoo의 쓰기 모드에 저장 되었습니까?

partnumber = fields.Char(
     'Part Number', compute='_compute_partnumber', 
     inverse='_set_partnumber', store=True) 

은 내가 성공적으로 추가

@api.depends('product_variant_ids', 'product_variant_ids.partnumber') 
def _compute_partnumber(self): 
    unique_variants = self.filtered(lambda template: len(template.product_variant_ids) == 1) 
    for template in unique_variants: 
     template.partnumber = template.product_variant_ids.partnumber 
    for template in (self - unique_variants): 
     template.partnumber = '' 

@api.one 
def _set_partnumber(self): 
    if len(self.product_variant_ids) == 1: 
     self.product_variant_ids.partnumber = self.partnumber 

내부 참조 코드와 같은 함수를 작성 제품 템플릿 모델의 부품 번호 필드를 추가 이름에 대한 방법보다 사용 제품 form.I에서 부품 번호 취득 (제품 설명에서 부품 번호를 얻으려면)

제 부품 번호는 입니다. 생성 방법은입니다. 필드는 편집 모드에만 저장됩니다.

+1

당신은 product_variants에서 len을 만들었습니까? – dccdany

+0

@dccdany : 의견을 주셔서 감사합니다. 제품 변형의 수표와 길이는 0입니다. 마침내 여기에 설정되지 않을지 이해합니다. – aslamsha22

답변

1

"dccdany"가 이미 그의 의견에서 말했듯이, 생성 순서는 템플릿에 약간 까다 롭습니다. 당신은 그것을 in the code으로 볼 수 있습니다. 먼저 템플릿이 생성됩니다. 파트 번호는 설정되지 않습니다. 그 시점에 변형이 없기 때문입니다. 템플릿을 만든 후에 변형이 부품 번호없이 만들어지고 (한 줄 나중에) 템플릿을 만든 후 부품 번호가 없습니다.

무엇을 할 수 있습니까? 그냥 product.template 같은 create()를 덮어 씁니다 :

@api.model 
def create(self, vals): 
    template = super(ProductTemplate, self).create(vals) 
    if 'partnumber' in vals and len(template.product_varient_ids) == 1: 
     template.partnumber = vals.get('partnumber') 
    return template 
+0

감사 Czoeliner, 완벽하게 작동합니다. – aslamsha22