Skip to Content
Menú
This question has been flagged
2 Respostes
3460 Vistes

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 0x07317B90>,) & property_manager.leases(<odoo.models.NewId object at 0x07317B90>,)
The model is:

from odoo import models, fields, api

class leases(models.Model):
_name = 'property_manager.leases'
_description = 'Leases - inherit from Contracts'
_inherit = 'account.analytic.account'
leasename = fields.Char()
leaseStart = fields.Date()
leaseExpire = fields.Date()
depositReq = fields.Date()
depositBal = fields.Date()
lateFeePolicy_id = fields.Many2one("property_manager.late_fee_policies")
key_id = fields.Many2one('property_manager.keys')
mkey_id = fields.Many2one('property_manager.keys')
unit = fields.Many2many('property_manager.units','lease_id')
tenant = fields.Many2one('res.partner')
view is:
    <record id="property_manager_lease_form" model="ir.ui.view">
<field name="name">property_manager.leases.form</field>
<field name="model">property_manager.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="unit" string="Units"/>
<tree string="Units">
</tree>
<field name="leaseExpire" string="Lease Expires"/>
<field name="depositReq" string="Deposit Required"/>
<field name="depositBal" string="Deposit Balance"/>
<field name="lateFeePolicy_id" string="Late Fee Policy"/>
<field name="key_id" string="Key"/>
<field name="mkey_id" string="Master key"/>
</xpath>
</field>
</record>
How can I fix this?


Avatar
Descartar

Hello @Sherman,

It seems that the field and views are defined properly. The error might may be from the compute field or other custom code. So can you please provide more detail.

Regards,

Aktiv software

Autor Best Answer

 For debugging, I simplified so there is only one model (leases) and associated views.  The entire leases.py and leases.xml files are below. Only 2 modules are installed (besides the one I am creating), Odoo 12 Accounting by Odoo Mates, Odoo SA and Contracts Management - Recurring by OpenERP SA, Tecnativa, LasLabs, Odoo Community Association (OCA). The only files in the module I am creating are menu.xml, templates.xml, ir.model.access.csv, __init__.py, __manifest__.py, leases.py and leases.xml. I am still getting the exact same error when attempting to select a product from an invoice line.

leases.py (in its entirety)

# -*- coding: utf-8 -*-

from odoo import models, fields, api

class leases(models.Model):
_name = 'pmtest.leases'
_description = 'Leases - inherit from Contracts'
_inherit = 'account.analytic.account'
leasename = fields.Char()
leases.xml (in its entirety)
<odoo>
<!--leases list view-->
<record id="pmtest_leases_list" model="ir.ui.view">
<field name="name">pmtest.leases.list</field>
<field name="model">pmtest.leases</field>
<field name="arch" type="xml">
<tree string="">
<field name="leasename"/>
</tree>
</field>
</record>



<!-- explicit lease form view definition (inherited contract) -->
<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>


<!--window actions-->
<record id="pmtest.action_leases" model="ir.actions.act_window">
<field name="name">Leases</field>
<field name="res_model">pmtest.leases</field>
<field name="view_mode">tree,form</field>
</record>
</odoo>

Avatar
Descartar