无法将 fields.Selection 添加到父模型
Failed to add fields.Selection to parent model
我正在研究对 res.partner 的访问限制。
目前我有两个问题:
1.Why 这段代码不会为继承模型创建新字段吗(第一个错误类似于“未知对象 _”,现在它消失了):(现在可以工作了,第一个问题已回答)
from odoo import models, fields
class partner(models.Model):
_inherit = 'res.partner'
privacy_visibility = fields.Selection([
('followers', _('On invitation only')),
('employees', _('Visible by all employees')),
#error was here. according to odoo documentation, here is a comma
#if you remove it, the code works: [![enter image description here][1]][1]([('',''),('',''),('','')])
],
string='Privacy', required=True,
default='employees',
help="Holds visibility of the partner that affects currently logged user:\n"
"- On invitation only: Employee may only see the followed partners\n"
"- Visible by all employees: Employee may see selected partner\n")
- 稍后,当我的限制被应用时,如何让选定的用户仍然访问所有的伙伴? (我的想法 - 1.to 隐藏“privacy_visibility”字段仅在开发人员模式下可见,因为它是为项目的“子任务项目”创建的。2.to 创建一个新组,但我不知道如何使用具有行级访问权限的访问组),您建议采用哪种方式?
第一个问题的答案:
选择字段语法不正确,请遵循此语法
示例:
gender = fields.Selection([('male', 'Male'), ('female', 'Female'), ('any', 'Any')], string='Gender')
您正在调用翻译对象(下划线“_”)来翻译您的选择值,但您没有导入它。
变化:
from odoo import models, fields
收件人:
from odoo import models, fields, _
我正在研究对 res.partner 的访问限制。 目前我有两个问题:
1.Why 这段代码不会为继承模型创建新字段吗(第一个错误类似于“未知对象 _”,现在它消失了):(现在可以工作了,第一个问题已回答)
from odoo import models, fields
class partner(models.Model):
_inherit = 'res.partner'
privacy_visibility = fields.Selection([
('followers', _('On invitation only')),
('employees', _('Visible by all employees')),
#error was here. according to odoo documentation, here is a comma
#if you remove it, the code works: [![enter image description here][1]][1]([('',''),('',''),('','')])
],
string='Privacy', required=True,
default='employees',
help="Holds visibility of the partner that affects currently logged user:\n"
"- On invitation only: Employee may only see the followed partners\n"
"- Visible by all employees: Employee may see selected partner\n")
- 稍后,当我的限制被应用时,如何让选定的用户仍然访问所有的伙伴? (我的想法 - 1.to 隐藏“privacy_visibility”字段仅在开发人员模式下可见,因为它是为项目的“子任务项目”创建的。2.to 创建一个新组,但我不知道如何使用具有行级访问权限的访问组),您建议采用哪种方式?
第一个问题的答案: 选择字段语法不正确,请遵循此语法
示例:
gender = fields.Selection([('male', 'Male'), ('female', 'Female'), ('any', 'Any')], string='Gender')
您正在调用翻译对象(下划线“_”)来翻译您的选择值,但您没有导入它。
变化:
from odoo import models, fields
收件人:
from odoo import models, fields, _