Inherit search view filter from stock picking to contacts models - Odoo v13 Community

1.2k views Asked by At

I'm trying to add a filter from stock picking (Ready, Done ...), into Contacts filter.

Specifically, trying to inherit from stock.picking the filter that i need, to add it into res.partner (search view contacts).

So, I've created a new model.   

Like this .. (.py):

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields, api

class StockPicking(models.Model):
    _inherit = 'stock.picking'

    available = fields.Many2one('res.partner',
                             string="Available",
                             domain="[('state', 'in', ('assigned', 'partially_available'))]")
    done = fields.Many2one('res.partner',
                                string="Done",
                                domain="[('state', '=', 'done')]")

view (.xml)

<?xml version="1.0" encoding="utf-8"?>
<odoo>

        <record model="ir.ui.view" id="view_res_partner_filter_inherit">
            <field name="name">res.partner.filter.inherit</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_res_partner_filter"/>
            <field name="arch" type="xml">
                <search>
                    <filter name="available" string="Ready" domain="[('state', 'in', ('assigned', 'partially_available'))]" help="Assigned Moves"/>
                    <filter name="done" string="Done" domain="[('state', '=', 'done')]" help="Pickings already processed"/>
                </search>
            </field>
        </record>

</odoo>

image:

The filter has been added ...

But, An error occurred while selecting the filter

Erreur:
Odoo Server Error

Traceback (most recent call last):
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\http.py", line 624, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\http.py", line 310, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\tools\pycompat.py", line 14, in reraise
    raise value
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\http.py", line 669, in dispatch
    result = self._call_function(**self.params)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\http.py", line 350, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\service\model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\http.py", line 339, in checked_call
    result = self.endpoint(*a, **kw)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\http.py", line 915, in __call__
    return self.method(*args, **kw)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\http.py", line 515, in response_wrap
    response = f(*args, **kw)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\addons\web\controllers\main.py", line 1280, in search_read
    return self.do_search_read(model, fields, offset, limit, domain, sort)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\addons\web\controllers\main.py", line 1299, in do_search_read
    return Model.web_search_read(domain, fields, offset=offset, limit=limit, order=sort)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\addons\web\models\models.py", line 39, in web_search_read
    records = self.search_read(domain, fields, offset=offset, limit=limit, order=order)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\models.py", line 4841, in search_read
    records = self.search(domain or [], offset=offset, limit=limit, order=order)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\models.py", line 1618, in search
    res = self._search(args, offset=offset, limit=limit, order=order, count=count)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\addons\base\models\res_partner.py", line 710, in _search
    count=count, access_rights_uid=access_rights_uid)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\models.py", line 4386, in _search
    query = self._where_calc(args)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\models.py", line 4115, in _where_calc
    e = expression.expression(domain, self)
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\osv\expression.py", line 675, in __init__
    self.parse()
  File "C:\Program Files (x86)\Odoo 13.0\server\odoo\osv\expression.py", line 856, in parse
    raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
ValueError: Invalid field 'state' in leaf "<osv.ExtendedLeaf: ('state', 'in', ['assigned', 'partially_available']) on res_partner (ctx: )>"

I'm not really sure, but it seems like it enters into a neverending loop when I call it from the search view.

So, I don't really know what's wrong with it.

Any ideas on how to accomplish this?

Thanks in advance!

1

There are 1 answers

7
Neural On BEST ANSWER

I don't know exactly what you want but try this.Add state field in res.partner model.

class respartner(models.Model):
    _inherit= "res.partner"

    state = fields.Selection([('draft','Draft'),
            ('waiting','Waiting'),
        ],default='draft'
        )
<odoo>
<data>
<record model='ir.ui.view' id='view_res_partner_filter'>
    <field name='name'>res.partner.select.inherit.base.partner.filter</field>
    <field name='model'>res.partner</field>
    <field name='inherit_id' ref='base.view_partner_form'/>
    <field name='arch' type='xml'>
        <field name="category_id" position="after">
            <field name="state"/>
    </field>
  </field>
</record>
<record id="view_res_partner_filter_inherit" model="ir.ui.view">
        <field name="name">view.res.partner.filter.inherit</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_res_partner_filter"/>
        <field name="arch" type="xml">
            <filter name="salesperson" position="before">
                <filter string="Draft" name="state" domain="[('state', '=', 'draft')]"/>
                <filter string="waiting" name="state" domain="[('state', '=', 'waiting')]"/>
            </filter>
        </field>
    </record>
  </data>
</odoo>