Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


[SOLVED] How to correctly add a field with fields.related on pos module?

on 5/6/15, 2:19 PM 2,046 views

I'm trying to link the pos_category_id field from model product_template to pos.order.line model. (point_of_sale.py) but I was unable to link correctly.

'pos_categ_id': fields.related('XXXXX, 'pos_categ_id', type='many2one', relation='product.template', string='Pos Category', select=True, store=True),

Where 'XXXXX' shuld be the other(s) field(s) to add.

Any clue?

On 5/7/15, 6:05 PM


tried right now. didn't go well. 

I've substituted on point_of_sale.py (one of the first lines) the string

from openerp import tools 

with the new

from openerp import models, fields, api, exceptions, tools 

Then I've added the new inherit at the very end

class pos_order_line(models.Model):
_inherit = 'pos.order.line'
pos_categ = fields.Many2one(related='product_id.pos_categ_id', string="POS Category")

Sadly, I've got the following errors:

2015-05-07 22:02:21,150 2150 ERROR Divina_DB1 werkzeug: Error on request:
Traceback (most recent call last):
File "/home/effe/.local/lib/python2.7/site-packages/werkzeug/serving.py", line 177, in run_wsgi
File "/home/effe/.local/lib/python2.7/site-packages/werkzeug/serving.py", line 165, in execute
application_iter = app(environ, start_response)
File "/home/effe/odoo/openerp/service/server.py", line 281, in app
return self.app(e, s)
File "/home/effe/odoo/openerp/service/wsgi_server.py", line 216, in application
return application_unproxied(environ, start_response)
File "/home/effe/odoo/openerp/service/wsgi_server.py", line 202, in application_unproxied
result = handler(environ, start_response)
File "/home/effe/odoo/openerp/http.py", line 1280, in __call__
return self.dispatch(environ, start_response)
File "/home/effe/odoo/openerp/http.py", line 1412, in dispatch
ir_http = request.registry['ir.http']
File "/home/effe/odoo/openerp/http.py", line 339, in registry
return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None
File "/home/effe/odoo/openerp/modules/registry.py", line 353, in get
File "/home/effe/odoo/openerp/modules/registry.py", line 384, in new
openerp.modules.load_modules(registry._db, force_demo, status, update_module)
File "/home/effe/odoo/openerp/modules/loading.py", line 351, in load_modules
force, status, report, loaded_modules, update_module)
File "/home/effe/odoo/openerp/modules/loading.py", line 255, in load_marked_modules
loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
File "/home/effe/odoo/openerp/modules/loading.py", line 143, in load_module_graph
File "/home/effe/odoo/openerp/modules/module.py", line 315, in load_openerp_module
__import__('openerp.addons.' + module_name)
File "/home/effe/odoo/openerp/modules/module.py", line 80, in load_module
mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
File "/home/effe/odoo/addons/point_of_sale/__init__.py", line 24, in <module>
import point_of_sale
File "/home/effe/odoo/addons/point_of_sale/point_of_sale.py", line 1467
pos_categ = fields.Many2one(related='product_id.pos_categ_id', string="POS Category")
IndentationError: unexpected indent

Back to square one... 


class pos_order_line (osv.Model):
_inherit = 'pos.order.line'
    _columns = {
        'product_categ_name': fields.related('product_id', 'categ_id', 'name', type='char', string='Product Category', store=True, readonly=True),

Hi Federico, from the error you can see that, the problem is with indentation on that line of defining the field "pos_categ". Just correct the indentation and try. Python is strict about indentation.

Akhil P Sivan
on 5/7/15, 10:32 PM

Done, but even with this correction the server is not starting: 2015-05-08 12:22:22,414 2652 INFO Divina_DB1 openerp.modules.loading: loading 72 modules... 2015-05-08 12:22:22,570 2652 CRITICAL Divina_DB1 openerp.modules.module: Couldn't load module point_of_sale 2015-05-08 12:22:22,570 2652 CRITICAL Divina_DB1 openerp.modules.module: 'module' object has no attribute 'Many2one'

on 5/8/15, 8:24 AM

More details: File "/home/effe/odoo/addons/point_of_sale/point_of_sale.py", line 1484, in class pos_order_line(models.Model): File "/home/effe/odoo/addons/point_of_sale/point_of_sale.py", line 1487, in pos_order_line pos_categ = fields.Many2one(related='product_id.pos_categ_id', string="POS Category") AttributeError: 'module' object has no attribute 'Many2one'

on 5/8/15, 1:23 PM

Akhil P Sivan

--Akhil P Sivan--
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 5/7/15, 12:09 AM

Hi Federico,

Try like this using the new api, since you are working in v8:

from openerp import models, fields, api, exceptions, tools 
class pos_order_line(models.Model):
    _inherit = 'pos.order.line'
    pos_categ = fields.Many2one(related='product_id.pos_categ_id', string="POS Category")

Interesting, I don't know well how the new API works. I'm building a new server right now then I'll install a brand new odoo for testing and I'll test your solution. Thanks!

on 5/7/15, 1:02 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 5/6/15, 2:19 PM
Seen: 2046 times
Last updated: 5/8/15, 2:55 PM