如何覆盖odoo 10中TransientModel的字段?

如何覆盖odoo 10中TransientModel的字段?,odoo,odoo-10,Odoo,Odoo 10,我已经这样做了,在旧的奥多版本中,它是这样工作的! 无法在日志文件中看到此“kecske”信号。没有错误消息。如果我在super之前写了一些代码,它没有任何效果 有什么想法吗?这条路对吗 类演示向导(models.TransientModel): _名称='demo.wizard' name=fields.Char(string='name') @api.model 定义字段\u视图\u获取(self,view\u id=None,view\u type='form',toolbar=False

我已经这样做了,在旧的奥多版本中,它是这样工作的! 无法在日志文件中看到此“kecske”信号。没有错误消息。如果我在super之前写了一些代码,它没有任何效果

有什么想法吗?这条路对吗

类演示向导(models.TransientModel):
_名称='demo.wizard'
name=fields.Char(string='name')
@api.model
定义字段\u视图\u获取(self,view\u id=None,view\u type='form',toolbar=False,submenu=False):
log=logging.getLogger('demo.wizard.fields\u view\u get()'))
log.debug('kecske')
返回超级(DemoWizard,self).fields\u view\u get(视图id,视图类型,工具栏,子菜单)

这是来自Odoo10的源代码。该文件位于匿名插件中
odoo/addons/anonymization/wizard/anonymize\u wizard.py
。请注意对super()的调用以及与位置参数相对应的关键字参数的使用

除此之外,您的代码看起来是正确的

在您的示例中,您使用不同的技术初始化了日志记录。尝试初始化记录器,如下所示

log = logging.getLogger(__name__)
log.info("My Log Message")
或用于调试

log.debug("My debug message")
信息、调试、警告、错误
可用于记录不同严重程度的日志消息

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
    state = self.env['ir.model.fields.anonymization']._get_global_state()
    step = self.env.context.get('step', 'new_window')
    res = super(IrModelFieldsAnonymizeWizard, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
    eview = etree.fromstring(res['arch'])
    placeholder = eview.xpath("group[@name='placeholder1']")
    if len(placeholder):
        placeholder = placeholder[0]
        if step == 'new_window' and state == 'clear':
            # clicked in the menu and the fields are not anonymized: warn the admin that backuping the db is very important
            placeholder.addnext(etree.Element('field', {'name': 'msg', 'colspan': '4', 'nolabel': '1'}))
            placeholder.addnext(etree.Element('newline'))
            placeholder.addnext(etree.Element('label', {'string': 'Warning'}))
            eview.remove(placeholder)
        elif step == 'new_window' and state == 'anonymized':
            # clicked in the menu and the fields are already anonymized
            placeholder.addnext(etree.Element('newline'))
            placeholder.addnext(etree.Element('field', {'name': 'file_import', 'required': "1"}))
            placeholder.addnext(etree.Element('label', {'string': 'Anonymization file'}))
            eview.remove(placeholder)
        elif step == 'just_anonymized':
            # we just ran the anonymization process, we need the file export field
            placeholder.addnext(etree.Element('newline'))
            placeholder.addnext(etree.Element('field', {'name': 'file_export'}))
            # we need to remove the button:
            buttons = eview.xpath("button")
            for button in buttons:
                eview.remove(button)
            # and add a message:
            placeholder.addnext(etree.Element('field', {'name': 'msg', 'colspan': '4', 'nolabel': '1'}))
            placeholder.addnext(etree.Element('newline'))
            placeholder.addnext(etree.Element('label', {'string': 'Result'}))
            # remove the placeholer:
            eview.remove(placeholder)
        elif step == 'just_desanonymized':
            # we just reversed the anonymization process, we don't need any field
            # we need to remove the button
            buttons = eview.xpath("button")
            for button in buttons:
                eview.remove(button)
            # and add a message
            placeholder.addnext(etree.Element('field', {'name': 'msg', 'colspan': '4', 'nolabel': '1'}))
            placeholder.addnext(etree.Element('newline'))
            placeholder.addnext(etree.Element('label', {'string': 'Result'}))
            # remove the placeholer:
            eview.remove(placeholder)
        else:
            raise UserError(_("The database anonymization is currently in an unstable state. Some fields are anonymized,"
                              " while some fields are not anonymized. You should try to solve this problem before trying to do anything else."))
        res['arch'] = etree.tostring(eview)
    return res

这是来自Odoo10的来源。该文件位于匿名插件中
odoo/addons/anonymization/wizard/anonymize\u wizard.py
。请注意对super()的调用以及与位置参数相对应的关键字参数的使用

除此之外,您的代码看起来是正确的

在您的示例中,您使用不同的技术初始化了日志记录。尝试初始化记录器,如下所示

log = logging.getLogger(__name__)
log.info("My Log Message")
或用于调试

log.debug("My debug message")
信息、调试、警告、错误
可用于记录不同严重程度的日志消息

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
    state = self.env['ir.model.fields.anonymization']._get_global_state()
    step = self.env.context.get('step', 'new_window')
    res = super(IrModelFieldsAnonymizeWizard, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
    eview = etree.fromstring(res['arch'])
    placeholder = eview.xpath("group[@name='placeholder1']")
    if len(placeholder):
        placeholder = placeholder[0]
        if step == 'new_window' and state == 'clear':
            # clicked in the menu and the fields are not anonymized: warn the admin that backuping the db is very important
            placeholder.addnext(etree.Element('field', {'name': 'msg', 'colspan': '4', 'nolabel': '1'}))
            placeholder.addnext(etree.Element('newline'))
            placeholder.addnext(etree.Element('label', {'string': 'Warning'}))
            eview.remove(placeholder)
        elif step == 'new_window' and state == 'anonymized':
            # clicked in the menu and the fields are already anonymized
            placeholder.addnext(etree.Element('newline'))
            placeholder.addnext(etree.Element('field', {'name': 'file_import', 'required': "1"}))
            placeholder.addnext(etree.Element('label', {'string': 'Anonymization file'}))
            eview.remove(placeholder)
        elif step == 'just_anonymized':
            # we just ran the anonymization process, we need the file export field
            placeholder.addnext(etree.Element('newline'))
            placeholder.addnext(etree.Element('field', {'name': 'file_export'}))
            # we need to remove the button:
            buttons = eview.xpath("button")
            for button in buttons:
                eview.remove(button)
            # and add a message:
            placeholder.addnext(etree.Element('field', {'name': 'msg', 'colspan': '4', 'nolabel': '1'}))
            placeholder.addnext(etree.Element('newline'))
            placeholder.addnext(etree.Element('label', {'string': 'Result'}))
            # remove the placeholer:
            eview.remove(placeholder)
        elif step == 'just_desanonymized':
            # we just reversed the anonymization process, we don't need any field
            # we need to remove the button
            buttons = eview.xpath("button")
            for button in buttons:
                eview.remove(button)
            # and add a message
            placeholder.addnext(etree.Element('field', {'name': 'msg', 'colspan': '4', 'nolabel': '1'}))
            placeholder.addnext(etree.Element('newline'))
            placeholder.addnext(etree.Element('label', {'string': 'Result'}))
            # remove the placeholer:
            eview.remove(placeholder)
        else:
            raise UserError(_("The database anonymization is currently in an unstable state. Some fields are anonymized,"
                              " while some fields are not anonymized. You should try to solve this problem before trying to do anything else."))
        res['arch'] = etree.tostring(eview)
    return res

我将发布一个来自Odoo10源代码的示例。我还没有测试过。它看起来非常接近你所拥有的。我能看到的唯一区别是,在Odoo对super()的调用中,它们使用关键字参数,而不是位置参数。我还没有测试过。它看起来非常接近你所拥有的。我能看到的唯一区别是,在Odoo对super()的调用中,它们使用关键字参数,而不是位置参数。正如我所说,日志仍然不包含我在返回之前写的内容。这两种调用方法是相同的。但是谢谢你善意的回答。关于你。通常情况下,我会看到这样初始化的记录器
log=logging.getLogger(\uuuu name\uuuuu)
你能试试看你的日志是否出现了吗?另外,在你的conf或服务器启动脚本中,你是在调试级别进行日志记录的吗?验证您正在以代码输出日志的级别进行日志记录。如果您的开始脚本使用的是
info
,那么您应该使用
log.info('Hello World')
uuuuuuh您说的
getLogger(\uuu name\uuuuuuuuuuuuuuuuuuuuuuuuuu)
:O(日志级别正确)在旧版本中,此getLogger运行良好。我真丢脸。但是,当我调用类似于
self.myFunction()
的函数,并且该方法包含
getLogger(\uuu name\uuuu)
和方法顶部的log.debug('kamion')时,它仍然不在日志文件中。请尝试使用信息级日志记录
log.info('Hello')
不确定为什么这对您不起作用。不幸的是,这并不能解决我的问题。正如我所说,日志仍然不包含我在返回之前写的内容。这两种调用方法是相同的。但是谢谢你善意的回答。关于你。通常情况下,我会看到这样初始化的记录器
log=logging.getLogger(\uuuu name\uuuuu)
你能试试看你的日志是否出现了吗?另外,在你的conf或服务器启动脚本中,你是在调试级别进行日志记录的吗?验证您正在以代码输出日志的级别进行日志记录。如果您的开始脚本使用的是
info
,那么您应该使用
log.info('Hello World')
uuuuuuh您说的
getLogger(\uuu name\uuuuuuuuuuuuuuuuuuuuuuuuuu)
:O(日志级别正确)在旧版本中,此getLogger运行良好。我真丢脸。但是,当我调用类似于
self.myFunction()
的函数,并且该方法包含
getLogger(\uuu name\uuuu)
和方法顶部的log.debug('kamion')时,它仍然不在日志文件中。请尝试使用信息级日志记录
log.info('Hello')
不确定为什么这对您不起作用。