- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这些模块:
base_module
, module_1
base_module_extend
,module_2
。
这些模块有这样的依赖关系:
module_1
依赖于 base_module
。 base_module_extend
依赖于 base_module
。module_2
依赖于 base_module_extend
。如果 module_1
和 module_2
没有同时安装,那么一切正常,但如果安装了它们,那么依赖项会按照这些模块的安装顺序发生变化.
例如,如果我安装 module_2
,然后安装 module_1
,当我开始使用 module_2
时,您调用 super
在那个模块代码中,它首先找到在 base_module
而不是 base_module_extend
中定义的类,然后有些东西坏了,因为它没有找到一些定义的属性/参数在 base_module_extend
中。
如果我以相反的顺序安装:首先安装 module_1
和 module_2
,然后当我使用 module_2
时,它工作正常,因为它从 super
调用正确的类。
有没有办法让这些模块调用正确的父类,如果它们都被安装而不关心它们的安装顺序?
或者这是限制,您对此无能为力?..
更新
如果您以错误的顺序安装(第一种情况)会导致什么损坏的示例:
这是base_module
中定义的方法:
def export_data(self, export_time=fields.Datetime.now()):
"""
This method can be overridden to implement custom data exportation
"""
self.ensure_one()
res = []
return res
这是在 module_1
中更改的方法:
def export_data(self, export_time=fields.Datetime.now()):
res = super(SFTPImportExport, self).export_data(export_time)
if self.process == 'custom_qty_available':
res = self._export_qty_available(export_time)
elif self.process == 'custom_sale':
res = self._export_sale(export_time)
return res
这是在 base_module_extend
中更改的方法:
def export_data(
self, export_time=fields.Datetime.now(), external_data=False):
"""
Overrides export_data to be able to provide external_data that
is already generated and can be directly returned to be used in export
@param export_time: time of export
@param external_data: used to bypass specific export
method and directly use data provided
"""
res = super(SFTPImportExport, self).export_data(export_time)
return res
这是在 module_2
中更改的相同方法:
def export_data(self, export_time=fields.Datetime.now(), external_data=False):
"""
Adds support for custom_invoice process
"""
res = super(SFTPImportExport, self).export_data(export_time=export_time, external_data=external_data)
if self.process == 'custom_invoice':
res = external_data
return res
更新2
当执行最后一个方法版本(在 module_2
中定义的那个)时,我得到这个错误:
"/opt/odoo/projects/project/sftp_import_export_extend/models/sftp_import_export.py", line 47, in export_sftp
export_time=now, external_data=external_data)
ValueError: "export_data() got an unexpected keyword argument 'external_data'" while evaluating
u'invoice_validate()'
所以看起来它得到了错误的父类,没有这样的关键字参数的父类
最佳答案
super() 倾向于在 Python 中选择错误的(意外的)父级。作为替代方案,您可以使用从所需父类(super class)直接调用 Python 函数,而不是使用 super(),这是更可靠的方法。
我不知道您的 Odoo 模块的目录结构和源文件名,所以我将尝试大致猜测该结构并向您说明应该做什么。请根据您的情况进行调整(具有正确的模块名称、源文件名称等)。
如果所需的 python 类,例如命名为 SFTPImportExport
,其中包含所需的 export_data
方法,则在 base_module_extend
内的以下源文件中定义Odoo 模块(相对路径):base_module_extend/models/somefile.py
而不是使用 super()
,您可以直接调用它,如下所示:
导入所需的父类(super class):
from openerp.base_module_extend.models.somefile import SFTPImportExport as ParentSFTPImportExport
然后直接调用它的方法:
ParentSFTPImportExport.export_data(self, export_time=export_time, external_data=external_data)
在这种情况下,将调用您想要的确切函数,因为您直接引用它。我建议做同样的事情,即在两个模块中直接调用所需的函数,以确保它们永远不会混合目标函数。
关于python - Odoo/ python : modules dependencies gone wrong?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37461841/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
我想,如果我单击按钮,删除数据并返回 TreeView 。我可以使用 unlink 方法删除数据。但我不能重定向到 TreeView 。我该怎么做? 这是我的代码: def action_de
我最近安装了 Odoo 9.0。但是,我需要一个仅适用于 Odoo 8.0 的模块。 我想知道是否可以对此模块进行微小的更改以使其兼容 Odoo 9.0?新模块只是一个日历,仅使用 Web 界面:Li
嗨,我很难确定人类的权限Odoo10 的资源模块涉及休假管理工作流程。 我在休假类型中激活了双重验证。假设我有一个部门,拥有以下员工: Manager01 (Manager of the Depart
我正在尝试将 odoo 安装从 8.0 升级到 9.0。到目前为止,我所做的如下: 从生产系统备份 odoo 数据库 在我当前的系统中安装了备份数据库作为测试 复制了我系统文件夹中的 odoo 文件夹
如何在 odoo 8.0 (OpenERP) 上删除“Powered by Odoo”? 最佳答案 首先转到您的 Odoo Web 模块并打开以下文件。 addons => web => views
我开发了一个同时支持 odoo 10 和 odoo 11 的应用程序,我想在一个部署下部署这个应用程序。意思是如果我访问我的 odoo 应用程序,我应该看到一个应用程序而不是两个应用程序,当我从下拉列
我已经按照教程安装了 odoo+postgres当我尝试在我的 linux 终端中运行 ./odoo-bin 命令时,我得到了这个错误: 2019-09-15 08:48:30,765 5126 ER
我按照教程在 Odoo 8 中创建了一个模块。我在用户中激活了技术功能,然后更新了模块列表,但它没有出现在列表中。 我该怎么办? 最佳答案 跟踪以下内容: checkout __init__.py,
我需要将“Powered by Odoo”页脚中的“Powered”更改为“Made”, 所以我的 Odoo(以前的 OpenERP)版本 8.0-aab3d9f 的页脚将是“Made by Odoo
默认情况下,当我在 odoo 中创建新数据库时,表是在公共(public)模式中创建的。有没有办法更改此配置以及 odoo 创建和使用另一个定义的方案? 最佳答案 没有办法做到这一点,odoo 默认使
我正在尝试使用与 Django 相同的功能: 在 Odoo 中,我有: 如果“c.id = cat_id”,我需要附加“active”类 它是如何在 Odoo 中完成的? 我正在使用:
我已经发送了一些电子邮件营销事件,在“群发邮件”中,我有“电子邮件”按钮的详细信息。当我点击它时,我有“邮件 ID(技术)”、“消息 ID”、“已发送”等列。但是我看不到我发送的电子邮件。 我怎么能看
在 Odoo 中创建发票时,我想过滤“客户”的可用合作伙伴选择。具体来说,我想将合作伙伴联系记录限制为“发票地址”类型的记录,即 res_partner 上的域。的 [('type','=','inv
我是 ODOO 新手,正在寻找捕获 的方法考勤模块中的地理位置 ODOO 的。需要同时记录入住和退房地点 最佳答案 检查此模块,它捕获地理位置:https://odoo-community.org/s
Odoo 中的 Product Master 需要两个不同的表是什么? product.product 和 product.template 有何不同? 最佳答案 由于产品变体,Odoo 有两种产品模
在V11企业版中,部分机型有存档功能,但公司没有。如果我有多家公司,但有一家公司已经停业,我如何禁用或存档该公司,使其不会出现在所有模块中,甚至管理员也无法将其分配给任何用户?似乎一旦创建了公司,即使
是否有一种简单的方法将 OpenERP (oodo) 中的新自定义字段(在客户记录或订单项目中)与外部链接(即描述或 iframe)关联起来,以便它可以链接到不同的系统? 创建记录时,是否有一种简单的
我在odoo社区版中更改了我的公司数据,但它从未反射(reflect)出来,即使我在浏览器缓存中进行了更改。请帮忙enter image description here ODoo 最佳答案 你有两个
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 6 年前。 Improve th
我是一名优秀的程序员,十分优秀!