0

以前の値を使用して関数フィールドの値を計算したい ( = 以前の ID を持つレコードの値)

'testrest' : fields.function(get_reste, method=True, string='Restant',type='integer'),

 def get_reste(self, cr, uid, ids, field_name, arg, context):
    x = {}
    for record in self.browse(cr, uid, ids ,context):
            if record.statut !=  'entree': 
                x[record.id]= a + record.entree_nbr # a should be the same field for the previous record

どうやってやるの?ありがとうございました

4

2 に答える 2

1

ここでの最初のポイントOE 6.1+fields.function()methodパラメータはもう必要ありません[Server rev 3495 revid odo@openerp.com-20110701232328-flgxulxva70vnyxr and addons rev 4844]。したがって、「method」パラメータはもう使用しないでください。

ここで、前の値に基づいて値を計算したいので、store=Trueここでparamを使用して、前の値をデータのデータに格納し、レコードの計算で前の値を読み取り、新しい値を計算して返すことができます。

'testrest' : fields.function(get_reste, store=True, string='Restant',type='integer'),

 def get_reste(self, cr, uid, ids, field_name, arg, context):
    x = {}
    for record in self.browse(cr, uid, ids ,context):
            if record.statut !=  'entree': 
                x[record.id]= record.testrest + record.entree_nbr
    return x

ここで文字列の利点は、OEの外部または外部のレポートツールのどこでもこの値を使用でき、このフィールドを公開することもできることです。

これがお役に立てば幸いです。

もう少しコード:

'price': fields.function(_price_get, method=True, string="Price", store=True),
于 2012-07-03T11:04:18.770 に答える
1
def get_reste(self, cr, uid, ids, field_name, arg, context):
    x = {}
    a = 0.0
    for record in self.browse(cr, uid, ids ,context):
            if record.statut !=  'entree': 
                x[record.id]= a + record.entree_nbr 
                a =record.testrest
    return x

必要に応じて、ID のリストを並べ替えることができます。ids.sort()

于 2012-07-03T12:52:11.310 に答える