[英]One record in Many2one field having another multiple records in Many2one field in Odoo
Using python requests, I have requested an API form Zoho: 使用python请求,我已经请求了一个API格式Zoho:
tags = requests.get(' https://books.zoho.com/api/v3/setting/tags?organization_id=xx&authtoken=xxx ').json() 标签= request.get(' https://books.zoho.com/api/v3/setting/tags?organization_id=xx&authtoken=xxx ').json()
which return this data: 返回此数据:
"reporting_tag": {
"tag_id": "1717893000000000335",
"tag_name": "division",
"associated_with": "item",
"is_active": true,
"status": "active",
"tag_options": [
{
"tag_option_id": "1717893000000123005",
"tag_option_name": "A",
"is_active": true,
"status": "active"
},
{
"tag_option_id": "1717893000000123003",
"tag_option_name": "B",
"is_active": true,
"status": "active"
},
{
"tag_option_id": "1717893000000123007",
"tag_option_name": "C",
"is_active": true,
"status": "active"
}
]
from the above result, I need to store the (tag_name) and its (tag_option_name). 根据以上结果,我需要存储(tag_name)及其(tag_option_name)。 The API may result hundreds of tag_names and their tag_name_options.
API可能会导致数百个tag_names及其tag_name_options。
so far I have defined Many2one field to store only the tag_name: 到目前为止,我已经定义了Many2one字段来仅存储tag_name:
x_tag_name = fields.Many2one('zoho.tags', string="Tag Name") x_tag_name = fields.Many2one('zoho.tags',string =“Tag Name”)
so what I want to do is when I select a tag_name all its tag_option_name should appear in another Many2one field. 所以我想要做的是当我选择一个tag_name时,它的tag_option_name应该出现在另一个Many2one字段中。 Similar to one parent having multiple children.
类似于有多个孩子的父母一方。 I do not know if it is possible or not, I hope you can help me to do similar scenario.
我不知道是否有可能,希望您能帮助我做类似的情况。
class ZohoTags(models.Model): ZohoTags(models.Model)类:
_name = 'zoho.tags'
name = fields.Char(string="Tags")
tag_options = fields.Char(string='Options')
tag_id = fields.Char(string="Tag Id")
@api.multi
def tags_get(self):
token = ''
org_id = ''
setting_values = self.env['ir.config_parameter'].search([])
for keys in setting_values:
if keys.key == 'account.zoho_authtoken_module':
token = keys.value
print(keys.value)
if keys.key == 'account.zoho_organization_module':
org_id = keys.value
print(keys.value)
tags = requests.get('https://books.zoho.com/api/v3/settings/tags?organization_id=xxx&authtoken=xxx').json()
for data in tags['reporting_tags']:
tag_name = '%s' % (data['tag_name'])
tag_ids = '%s' % (data['tag_id'])
self.env.cr.execute("INSERT INTO zoho_tags (name, tag_id) VALUES ('%s', '%s')" % (tag_name, tag_ids))
self.env.cr.commit()
print(tag_name)
class TagsLine(models.Model): class TagsLine(models.Model):
_name = 'zoho.tags.line'
x_tag_name = fields.Many2one('zoho.tags', string='Analytic Account')
x_tags_options = fields.Char(string='Tags Option', related="x_zoho_tags.tag_options")
rules_id = fields.Many2one('hr.salary.rule')
Yeah your target is certainly achievable. 是的,你的目标肯定是可以实现的。
so what I want to do is when I select a tag_name all its tag_option_name should appear in another Many2one
所以我想要做的是当我选择一个tag_name时,它的tag_option_name应该出现在另一个Many2one中
Your tag_option_name
, let's suppose the model for this data is zoho.tags.line
, will have a Many2one
relation tag_id
with zoho.tags
, not the other way around. 你
tag_option_name
,假设此数据模型是zoho.tags.line
,将有一个Many2one
关系tag_id
与zoho.tags
,而不是周围的其他方式。 zoho.tags
will have a reverse One2many
relationship tag_option_ids
with the zoho.tags.line
, with inverse_key
set to tag_id
. zoho.tags
将与tag_option_ids
具有反向的One2many
关系zoho.tags.line
,其中inverse_key
设置为tag_id
。 So, for every zoho.tags
record, you will get multiple zoho.tags.line
record from the field tag_option_ids
, which can be shown in tree/list
within form view. 因此,对于每个
zoho.tags
记录,您将从字段tag_option_ids
获取多个zoho.tags.line
记录,该记录可以在表单视图中的tree/list
中显示。
_name = 'zoho.tags'
name = fields.Char(string="Tags")
tag_option_ids = fields.One2many(zoho.tags.line, tag_id, string='Options')
tag_id = fields.Char(string="Tag Id")
_name = 'zoho.tags.line'
tag_id = fields.Many2one('zoho.tags', string='Analytic Account')
x_tags_options = fields.Char(string='Tags Option', related="x_zoho_tags.tag_options")
rules_id = fields.Many2one('hr.salary.rule')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.