コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
21729 ビュー

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?


アバター
破棄
著作者 最善の回答

Akhil,

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
execute(self.server.app)
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
update_module)
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
load_openerp_module(package.name)
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... 


SOLVED WITH:

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.

著作者

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'

著作者

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'

最善の回答

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!

関連投稿 返信 ビュー 活動
2
2月 25
1390
1
11月 22
3261
5
12月 19
8562
0
3月 25
1399
1
11月 16
11141