class product_pricelist_item(models.Model):
_inherit = 'product.pricelist.item'
myfield = fields.Boolean(string="CheckMark")
product.pricelist.item
にブールフィールドを追加した今product.pricelist.item
内に複数の行があります。
(バリデーション) 私は、ユーザーがTrue
複数のフィールドを一度にTrue
することができmyfield
一対一を行うことが許可されていないことを望みます。
product.pricelist.item
でこれを試してみましたが、これにカウンタを付けてmyfields
という数字のTrue
を渡してみました。
これは私にエラーを与えています。
global name '_get_counter' is not defined
def _get_counter(self):
for r in self:
p=[]
p= r.env['product.pricelist.item'].search_read([('myfield', '=', True)], ['myfield'])
counter = len(p)
return counter
@api.constrains('myfield')
def _check_myfield(self):
counter = _get_counter(self)
for r in self:
if counter > 1:
raise exceptions.ValidationError("Multiple myfield In a PriceList of a Product is not allowed.")
今、2番目の質問は次のとおりです。 -
あなたが価格表項目を作成し、それがデータベース内のデータを反映しない価格表に保存する]をクリックすると。あなたがpricelistをクリックすると、それはデータを反映します...なぜこれがそうですか?
エラー: - '_get_counter()は正確に1つの引数(2与えられます)' – maharshi
'counter = self._get_counter()'うまく動作します。 – maharshi