이것은 계산 된 필드를 사용하여 얻을 수있는 최상의 방법입니다. 여기
<field name="uom_id" position="replace">
<!-- The category_id.name is really only used to filter when islocaluom=True. The result is that if a uom_class is used, only uom's from that class can be selected. Otherwise, the default uom's are present -->
<field name="uom_id" groups="product.group_uom" domain="['&',('islocaluom','=',calcislocaluom),'|',('islocaluom','=',False),('category_id','=',calccatidname)]" options="{'no_create' : True},{'no_create_edit' : True}" />
</field>
지금 난 그냥 가게 = true를 사용하여 일부 계산 필드를 생성 한 다음, 계산 기능에서 그들을 설정, 내 코드 내 XML에서
에서 예 솔루션입니다. 충분한 하드 실제로 내가 그들을가하고 싶은 일을하고, 데이터에 따라 동적으로 역할을 정적으로 정의 도메인을 만들 수 있기 때문에
class ProductTemplate(models.Model):
_inherit = 'product.template'
#This field will let us choose if we are using per product uom on the product
uom_class = fields.Many2one('productuom.class', 'Per Product UOM Conversion Class', ondelete='restrict',required=False, help="Unit of Measure class for Per Product UOM")
#These computed fields are for calculating the domain on a form edit
calcislocaluom = fields.Boolean('Find if its a localuom',compute='_computelocaluom', store=True, default=False)
calccatidname = fields.Char('Find the name of the category id', compute='_computecatidname', store=True,default=True)
#[...] other code removed
@api.one
@api.depends('uom_class')
def _computelocaluom(self):
if (self.uom_class):
self.calcislocaluom = True
return True
else:
self.calcislocaluom = False
return False
@api.one
@api.depends('uom_class')
def _computecatidname(self):
if (self.uom_class):
self.calccatidname = self.uom_class.name
return self.uom_class.name
else:
#Due to the conditions we later impose within the view, we need to specify a category name that will always be there
self.calccatidname = "Unsorted/Imported Units"
return True
나는, 정답으로이 마킹에 보류거야 ... 하지만 이러한 복잡한 문장을 역 폴란드 표기법으로 작성해야하는 것은 고문에 불과합니다.
필드 y가 필드 x에 의존적 인 경우 x가 변경되지 않으면 어떻게 필드 y의 변경이 트리거 될 수 있습니까? * 동적 * (변경 사항) 도메인은 변경되는 내용을 기반으로해야합니다. 나는 당신이 기본 도메인을 원한다고 생각하지만 당신이 명확히 할 때까지 나는 결코 알 수 없다. – danidee
음, 분명하게 말하면, 나는 질문에서 설명한 것을 수행하는 onchange가 있습니다. 새 레코드를 만들 때 잘 작동합니다. 그러나 레코드를 저장하고 다시 돌아가 편집하면 도메인이 기본값으로 다시 설정됩니다. 사용자의 관점에서 볼 때 이는 실제로 의미가 없습니다. 그들이 레코드를 만들 때 "좋아하는 장난감"을 위해 선택한 선택은 그들이 선택한 동물에 따라 다릅니다. 이제 그들은 "좋아하는 장난감"을 바꾸려고했지만 Odoo는 다른 선택 영역을 제시합니다. 그들은 마지막으로했던 것과 동일한 선택을보아야합니다. – Nross2781
자, 계산 된 필드를 만들고 그 변수를 도메인에 설정하는 것을 돕기 위해 아이디어를 얻었습니다 ....하지만 내 삶에 대해 계산 된 필드를 데이터베이스에 저장할 수는 없습니다. store = True 인 경우에도 값은 저장되지 않습니다. 맹세코, 최신 API가 화를냅니다. v7에서 작동하는 이러한 모든 솔루션을 볼 수 있지만 v9에서 동일한 작업을 수행 할 수있는 방법은 없습니다. – Nross2781