2
votes

I have some problem with tree/form view in Odoo.

My model have such classes: https://yadi.sk/d/sCLVo3gHtbVEu

class URLList(models.Model):
    _name = 'webvisitorcalc.url_list'

    url = fields.Char(string="URL", required=True)
    url_parametes = fields.Char(string="URL parameters") #пераметры URLб всё что идёт после ?

    target_session_id = fields.One2many('webvisitorcalc.session_visitor', 'target_url_ids', string='Target URL')

    site_trip_prevouse_id = fields.One2many('webvisitorcalc.site_trip', 'url_prevouse_ids', string='Prevouse URL')
    site_trip_current_id = fields.One2many('webvisitorcalc.site_trip', 'url_current_ids', string='Current URL')


    remote_sites_id = fields.One2many('webvisitorcalc.remote_sites', 'site_url_ids', string='Remote site page with URL')
    remote_sites_target_url_id = fields.One2many('webvisitorcalc.remote_sites', 'target_url_ids', string='URL on remote site page')

    @api.multi
    def url_exist(self, cr, SUPERUSER_ID, urlForCheck):
        _logger.error("Check URL exist in DB ")
        result = False
        if (self.search_count(cr, SUPERUSER_ID, [('url', '=', urlForCheck)])>0):
            result = True
        return result

class SiteTrip(models.Model):
    _name = 'webvisitorcalc.site_trip'

    session_ids = fields.Many2one('webvisitorcalc.session_visitor', string='Session ID', index=True)
    url_prevouse_ids = fields.Many2one('webvisitorcalc.url_list', string='Prevouse URL', index=True)
    url_current_ids = fields.Many2one('webvisitorcalc.url_list', string='Current URL', index=True)

Template for this model: https://yadi.sk/d/Ob0o65PutbVFA

<record model="ir.actions.act_window" id="site_trip_list_action">
    <field name="name">Site trip</field>
    <field name="res_model">webvisitorcalc.site_trip</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
    <field name="help" type="html">
        <p class="oe_view_nocontent_create">Create the first record for site trip
        </p>
    </field>
</record>
<record model="ir.actions.act_window" id="url_list_list_action">
    <field name="name">URL list</field>
    <field name="res_model">webvisitorcalc.url_list</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
    <field name="help" type="html">
        <p class="oe_view_nocontent_create">Create the first url
        </p>
    </field>
</record>

<record model="ir.ui.view" id="site_trip_tree_view">
    <field name="name">site_trip.tree</field>
    <field name="model">webvisitorcalc.site_trip</field>
    <field name="arch" type="xml">
        <tree string="URL list tree">
            <field name="session_ids"/>
            <field name="url_prevouse_ids" string="PrevURL">
            </field>
            <!--<field name="url_prevouse_ids"/>-->
            <field name="url_current_ids"/>
        </tree>
    </field>
</record>

<record model="ir.ui.view" id="url_list_tree_view">
    <field name="name">url_list.tree</field>
    <field name="model">webvisitorcalc.url_list</field>
    <field name="arch" type="xml">
        <tree string="URL list tree">
            <field name="url"/>
            <field name="url_parametes"/>
        </tree>
    </field>
</record>

<menuitem id="site_trip_menu" name="Site trip" parent="webvisitorcalc_menu"
          action="site_trip_list_action"/>

<menuitem id="url_list_menu" name="URL list" parent="webvisitorcalc_menu"
          action="url_list_list_action"/>

Screenshots are here:

Tree view for class SiteTrip http://i.stack.imgur.com/FjRDK.png

Form view for class SiteTrip http://i.stack.imgur.com/uDbOp.png

Tree view for class URLList http://i.stack.imgur.com/tXzqL.png

Form view for class URLList http://i.stack.imgur.com/oVnqg.png

As you see URLList displayed fine. For class SiteTrip present problem. Field is displaying not data from URLList. This is field stored element such webvisitorcalc.url_list.ID (array?). How I can display real data in this field (for example URL: http://some-site.com/page.html)? URL in URLList must be uniq. SiteTrip must have stored only ID of URLList record.

UPD:

class RemoteSites(models.Model):
    _name = 'webvisitorcalc.remote_sites'

    site_id = advert_company_id = fields.One2many('webvisitorcalc.site_list', 'remote_sites_ids', string='Site')
    site_url_ids = fields.Many2one('webvisitorcalc.url_list', string='URL page ')
    target_url_ids = fields.Many2one('webvisitorcalc.url_list', string='URL target page')
1
include your code here on stackoverflow, it makes it easier for others to help youdanidee
I can not do it. Every time parser is reporting about error.Skif
it's incredible. Now working fine. I lost one hour try to public this post with code.Skif
where is the code for the model webvisitorcalc.remote_sitesdanidee

1 Answers

1
votes

You obviously have no name field on your webvisitorcalc.url_list model. Odoo needs this to use it as name in webclient wherever you use this model as e.g. many2one field or in the breadcrumb navigation.

So either you define a name field or you set _name on your class with another field identifier.

You can also (re-)define the method display_name on your model (enough examples in Odoo code) where you can do more cool stuff with the record display name :-)