Hi. I have this following module : https://github.com/NaN-tic/trytond-sale_invoice_grouping_period/blob/5.2/party.py , wich i want to make sale_invoice_grouping_period field searchable inside tree view of parties. Here is my code:
from trytond.pool import PoolMeta
from trytond.model import ModelSQL, fields
from trytond.pool import Pool
class Party(metaclass=PoolMeta):
'Party Sales Period Searcher'
__name__ = 'party.party'
sale_period = fields.Function(fields.Char('Sale Periods', help="This is a test"),
getter='get_periods',
searcher='searcher_sale_period')
@classmethod
def searcher_sale_period(cls, name, clause):
return [
('party.sale_period', clause[1])
]
def get_periods(self, name):
p = Pool()
SaleMethod = p.get('party.party.sale_invoice_grouping_method')
if SaleMethod.sale_invoice_grouping_method:
return SaleMethod.sale_invoice_grouping_period **# How to get the field value ???**
return None
My party.xml
defined like this:
<?xml version="1.0"?>
<tryton>
<data>
<record model="ir.ui.view" id="party_sales_period_list">
<field name="model">party.party</field>
<field name="inherit" ref="party.party_view_tree"/>
<field name="name">party_period_list</field>
</record>
</data>
</tryton>
my list view
<?xml version="1.0"?>
<data>
<xpath expr="/tree/field[@name='code']" position="after">
<field name="sale_period"/>
</xpath>
</data>
I get the following error:
Traceback (most recent call last):
File "/trytond-5.2.20-py3.6.egg/trytond/wsgi.py", line 104, in dispatch_request
return endpoint(request, **request.view_args)
File "/trytond-5.2.20-py3.6.egg/trytond/protocols/dispatcher.py", line 48, in rpc
request, database_name, *request.rpc_params)
File "/trytond-5.2.20-py3.6.egg/trytond/wsgi.py", line 72, in auth_required
return wrapped(*args, **kwargs)
File "/trytond-5.2.20-py3.6.egg/trytond/protocols/wrappers.py", line 131, in wrapper
return func(request, pool, *args, **kwargs)
File "/trytond-5.2.20-py3.6.egg/trytond/protocols/dispatcher.py", line 217, in _dispatch
response = app.make_response(request, result)
File "/trytond-5.2.20-py3.6.egg/trytond/wsgi.py", line 123, in make_response
response = cls.response(data, request)
File "/trytond-5.2.20-py3.6.egg/trytond/protocols/jsonrpc.py", line 160, in response
response, cls=JSONEncoder, separators=(',', ':')),
File "/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/trytond-5.2.20-py3.6.egg/trytond/protocols/jsonrpc.py", line 61, in default
return marshaller(obj)
File "/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'Selection' is not JSON serializable
I understand that JSON is a dictionary, and what i want to get is inside a list of tuples. I think i’m quite wrong about how i should do this… Can someone help me please ?
Database frame: i do have stored the following lines :
id | party | sale_invoice_grouping_method | sale_invoice_grouping_period
-----+-------+------------------------------+------------------------------
1 | 178 | standard | weekly-0
2 | 179 | standard | weekly-0
3 | 180 | standard | monthly
4 | 181 | standard | daily
5 | 182 | standard | weekly-0
6 | 183 | standard | weekly-0
7 | 184 | standard | weekly-0
8 | 185 | standard | weekly-0
9 | 186 | standard | weekly-0
10 | 187 | standard | weekly-0
11 | 188 | standard | monthly