Python 2.7 根据odoo中的选择,寻找将记录从一个模型插入到另一个模型的最佳方法
我使用Query编写了从sou parts表到sou bo表的插入记录的代码……我如何使用ORM方法来完成这种工作。有没有其他(最好的)方法?这是我的密码` `Python 2.7 根据odoo中的选择,寻找将记录从一个模型插入到另一个模型的最佳方法,python-2.7,odoo-10,Python 2.7,Odoo 10,我使用Query编写了从sou parts表到sou bo表的插入记录的代码……我如何使用ORM方法来完成这种工作。有没有其他(最好的)方法?这是我的密码` ` 是的,有一个更好的方法,因为当你使用ORM时 方法还检查用户对以下内容的访问权限: 对于select查询: rec = self.env['my.depots.so'].search_read(['id', '=', so_p_id], ['so_work_authorization']) if rec: rec = rec[0
是的,有一个更好的方法,因为当你使用ORM时 方法还检查用户对以下内容的访问权限: 对于select查询:
rec = self.env['my.depots.so'].search_read(['id', '=', so_p_id], ['so_work_authorization'])
if rec:
rec = rec[0] # search_read return a list of dictionary
so_work_authorization = rec['so_work_authorization']
# and do what ever you want with the result
# to create
# call create method witch accept a dictionary
# field_name : value
new_rec = self.env['my.depots.so.bo'].create({
'so_bo_id': so_p_id, # many2one must be an integer value
'bo_sno': bo_nso_value,
'bo_number': value_of_number,
# ....
# ....
# add al field
}) # create return the new created record as model object
用于插入用法:self.env['model.name'].create(VAL)
更新使用:self.env['model.name'].write(VAL)
使用ORM方法可以确保用户不通过安全访问权限
希望您能理解请查看ORM API文档:
rec = self.env['my.depots.so'].search_read(['id', '=', so_p_id], ['so_work_authorization'])
if rec:
rec = rec[0] # search_read return a list of dictionary
so_work_authorization = rec['so_work_authorization']
# and do what ever you want with the result
# to create
# call create method witch accept a dictionary
# field_name : value
new_rec = self.env['my.depots.so.bo'].create({
'so_bo_id': so_p_id, # many2one must be an integer value
'bo_sno': bo_nso_value,
'bo_number': value_of_number,
# ....
# ....
# add al field
}) # create return the new created record as model object