我在odoo 12中使用了Contracts Management-Recurring模块,并且我正在编写一个模块,该模块创建一个名为“ leases”的模型,该模型使用_inherit从account.analytic.account继承。表单视图继承自contract.account_analytic_account_sale_form。效果很好,除了当我尝试从发票行添加产品时,我得到了错误
TypeError: Mixing apples and oranges: account.analytic.account(<odoo.models.NewId object at 0x07736650>,) & pmtest.leases(<odoo.models.NewId object at 0x07736650>,)
模型是:
class leases(models.Model):
_name = 'pmtest.leases'
_description = 'Leases - inherit from Contracts'
_inherit = 'account.analytic.account'
lease
name = fields.Char()
视图是
<record id="pmtest_leases_form" model="ir.ui.view">
<field name="name">pmtest.leases.form</field>
<field name="model">pmtest.leases</field>
<field name="inherit_id" ref="contract.account_analytic_account_sale_form"/>
<field name="mode">primary</field>
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="leasename" string="Lease Name"/>
</xpath>
</field>
</record>
全栈跟踪如下:
Odoo Server Error
Traceback (most recent call last):
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 654, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 312, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\tools\pycompat.py", line 87, in reraise
raise value
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 696, in dispatch
result = self._call_function(**self.params)
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 344, in _call_function
return checked_call(self.db, *args, **kwargs)
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\service\model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 337, in checked_call
result = self.endpoint(*a, **kw)
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 939, in __call__
return self.method(*args, **kw)
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 517, in response_wrap
response = f(*args, **kw)
File "c:\program files (x86)\odoo 12.0\server\odoo\addons\web\controllers\main.py", line 962, in call_kw
return self._call_kw(model, method, args, kwargs)
File "c:\program files (x86)\odoo 12.0\server\odoo\addons\web\controllers\main.py", line 954, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\api.py", line 749, in call_kw
return _call_kw_multi(method, model, args, kwargs)
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\api.py", line 736, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 5455, in onchange
record[name] = value
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 5097, in __setitem__
return self._fields[key].__set__(self, value)
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\fields.py", line 1002, in __set__
spec = self.modified_draft(record)
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\fields.py", line 1147, in modified_draft
lambda rec: rec if path == 'id' else rec._mapped_cache(path) & records
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 4866, in filtered
return self.browse([rec.id for rec in self if func(rec)])
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 4866, in <listcomp>
return self.browse([rec.id for rec in self if func(rec)])
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\fields.py", line 1147, in <lambda>
lambda rec: rec if path == 'id' else rec._mapped_cache(path) & records
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 5002, in __and__
raise TypeError("Mixing apples and oranges: %s & %s" % (self, other))
TypeError: Mixing apples and oranges: account.analytic.account(<odoo.models.NewId object at 0x04F49BB0>,) & pmtest.leases(<odoo.models.NewId object at 0x04F49BB0>,)
答案 0 :(得分:1)
我认为问题出在属性 _name 。
尝试删除 名称属性。
不同之处在于,如果添加 _name ,则将在数据库中创建一个新表。如果仅添加 _inherit 属性,则您创建的字段将被添加到表中,就像_inherit属性一样。
如果看到的话,该错误表明您无法将“ account.analytic.account”模型与“ pmtest.leases”模型进行比较,因为您使用_name定义了不同的模型。