Reputation: 33
I have odoo 12 with the module Contracts Management - Recurring" and I'm writing a module that creates a model called "leases' that inherits from account.analytic.account using _inherit. The form view inherits from contract.account_analytic_account_sale_form. It works very well except that when I try to add products from invoice lines, I get the error
TypeError: Mixing apples and oranges: account.analytic.account(<odoo.models.NewId object at 0x07736650>,) & pmtest.leases(<odoo.models.NewId object at 0x07736650>,)
The model is:
class leases(models.Model):
_name = 'pmtest.leases'
_description = 'Leases - inherit from Contracts'
_inherit = 'account.analytic.account'
lease
name = fields.Char()
The view is
<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>
full stack trace follows:
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>,)
Upvotes: 3
Views: 2239
Reputation: 136
I think the problem is in the attribute _name.
Try to delete the _name attribute.
The difference is that if you add _name, you will create a new table in the database. If you only add an _inherit attribute, the fields that you create will be added to the table named like the _inherit attribute.
If you see, the error says that you can´t compare 'account.analytic.account' model with 'pmtest.leases' model, because you define with the _name that are different models.
Upvotes: 2