Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
41788 มุมมอง

I've created a simple module to extend stock.production.lot model, so I would be able to attach some extra information to each product via unique Serial Number. I'm only starting to work with Odoo and this is an early version of a module I would use..

Extra question: how would I make products searchable by these fields I added? I.e. if I wanted to find a product with 'Full' Toner Level.

The module:

from odoo import models, fields, api

class x_wh(models.Model):
_name = "stock.production.lot"
_inherit = 'stock.production.lot'

x_toner = fields.Char(
'Toner Level', index=True
)
x_print_count = fields.Integer(
'Print Count', index=True
)
x_description = fields.Text(
'Description'
)
x_condition = fields.Char(
'Product Condition', index=True
)




<odoo>
<data>

<record id="view_production_lot_form" model="ir.ui.view">
<field name="model">stock.production.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_form" />
<field name="arch" type="xml">
<field name="ref" position="after" >
<field name="x_toner" />
<field name="x_print_count" />
<field name="x_description" />
<field name="x_condition" />
</field>
</field>
</record>
<record id="view_production_lot_form_simple" model="ir.ui.view">
<field name="model">stock.production.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_form_simple" />
<field name="arch" type="xml">
<field name="ref" position="after" >
<field name="x_toner" />
<field name="x_print_count" />
<field name="x_description" />
<field name="x_condition" />
</field>
</field>
</record>

</data>
</odoo>

The module installs without any errors, but if I reload Odoo it crashes with the error I include here.



File "C:\Projects\Odoo2\odoo\odoo\modules\loading.py", line 274, in load_marked_modules
perform_checks=perform_checks, models_to_check=models_to_check
File "C:\Projects\Odoo2\odoo\odoo\modules\loading.py", line 146, in load_module_graph
model_names = registry.load(cr, package)
File "C:\Projects\Odoo2\odoo\odoo\modules\registry.py", line 250, in load
model = cls._build_model(self, cr)
File "C:\Projects\Odoo2\odoo\odoo\models.py", line 428, in _build_model
raise TypeError("Model %r does not exist in registry." % name)
TypeError: Model 'stock.production.lot' does not exist in registry.
อวตาร
ละทิ้ง

adding module that i inherited to dependincies in manifest has helped me solve the same issue

คำตอบที่ดีที่สุด

Hi,

Make sure that the stock module is added in the depends on the custom module. And also do one thing,

class XWH(models.Model):
_name = "stock.production.lot"
_inherit = 'stock.production.lot'


remove the name from the above class and make it like this,

class XWH(models.Model):
_inherit = 'stock.production.lot'


Thanks

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

adding module that i inherited to dependincies in manifest has helped me solve the same issue

อวตาร
ละทิ้ง

this solved my issue

คำตอบที่ดีที่สุด

Hi

If you use
_inherit : It will use the same table that you mention in the quotes. 

Class SaleOrder(models.Model):
_inherit = 'sale.order'


_name : It will create a new table.

Class SaleOrder(models.Model):
_name = 'new.table.name'


If you create a class with both _name and _inherit: It will generate a new table with the name. table contains all the fields and property that we inherit. 

Class SaleOrder(models.Model):
_name = 'new.table.name'
_inherit = 'sale.order'

Thanks

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Thanks, that worked. I didn't realise that any time I am extending a certain class I need to make a reference in the manifest..

What does the removal of the name do in the module?

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ค. 19
3637
Product name to One2Many + แก้ไขแล้ว
2
ธ.ค. 22
4264
0
พ.ค. 21
2891
Odoo11 Community: Salary แก้ไขแล้ว
1
ก.พ. 19
2637
0
ธ.ค. 18
2886