これは私の構造体である:Odoo 10のオブジェクトからIDを取得するには?
class Imprint_Location(models.Model):
_name = 'imprint.location'
name = fields.Char()
product_id = fields.Many2one('product.template')
class Imprint_Charges(models.Model):
_name = 'imprint.charge'
_rec_name = 'location_id'
product_id_c = fields.Many2one('product.template', required=True)
location_id = fields.Many2one('imprint.location', required=True)
@api.multi
@api.onchange('product_id_c', 'location_id')
def product_filter(self):
res = {}
print '\n\n-------\n\n', self, self.product_id_c, '\n\n-------\n\n'
if self.product_id_c:
res['domain'] = {'location_id': [('product_id', '=', self.product_id_c.id)]}
print res
return res
class Product_Template(models.Model):
_inherit = 'product.template'
imprint_location_ids = fields.One2many('imprint.location', 'product_id')
sale_imprint_charge_ids = fields.One2many('imprint.charge', 'product_id_c')
は、今私はproduct.template
でページを定義し、ページ内<tree editable="bottom">
であるsale_imprint_charge_ids
あると私はproduct_id_c
フィールドを選択していないですした[また、このフィールドにはには表示されません。定義されたツリー]。
今ここに私の問題は、私がimprint.charge
のために正常に動作しますが、私はその後、product.template
から入力したときに、私は
TypeError: <odoo.models.NewId object at 0x7fbb8bc21b90> is not JSON serializable
product_filter
方法を定義し、フォームビューからこれを選択すると、
<odoo.models.NewId object at 0x7fbb8bc21b90>
を渡す場合はproduct.template
からですので、self.product_id_c
を印刷するとproduct.template(<odoo.models.NewId object at 0x7fbb8bc21b90>)
が出力されるので、これはシリアル化できません。私はself.product_id_c.ids
を実行して、空のリスト[]
を出力しようとしました。
したがって、オブジェクトからproduct.template
IDを取得するか、またはid
自体をいくつかのメソッドをオーバーライドして渡す必要があります。
私はフィールド 'location_id'をフィルタリングする必要があります...私はその製品のフィールドを表示したいだけです...結果はリストになる可能性があり、ユーザは選択する 'location_id'を選択します – maharshi
それでも 'product.template'から空のレコードセットを取得すると、' id'ではなく 'object'を渡します。 – maharshi