Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3569 Widoki

I have added a field in product.template named 'model' in my custom module and added this field in my view. But the problem is it is showing product list in the drop down when creating record.

Here is my 

models.py

class Product(models.Model):
_name = "product.template"
_inherit = "product.template"

model = fields.Char(string="Product Model", required=False)

class GearManufacturing(models.Model):
_name = 'gear.manufacturing'
product_id = fields.Many2one("product.product", 'Product',required=True)
model = fields.Many2one('product.template', 'Model',required=True)
product_to_dispatch = fields.Integer('Products to Dispatch',required=True)
dispatch_date = fields.Date('Dispatch Date', copy=False, default=fields.Date.today(), index=True, required=True)
views.xml
<record id="gear_manufacturing_tree" model="ir.ui.view">
<field name="name">gear.manufacturing.tree</field>
<field name="model">gear.manufacturing</field>
<field name="arch" type="xml">
<tree>
<field name="product_id"/>
<field name="product_to_dispatch"/>
<field name="model"/>
<field name="dispatch_date"/>
</tree>
</field>
</record>

The field model is showing me Products in dropdown however, it should display nothing since there are no records of it. Where am I going wrong? 


Update:

When I upgrade my module, I am getting this error too:


019-11-24 05:34:14,321 27436 ERROR db_test odoo.sql_db: bad query: b"\n                INSERT INTO ir_model_data (module, name, model, res_id, noupdate, date_init, date_update)\n                VALUES ('gear_manufacturing', 'access_gear_manufacturing_gear_manufacturing', 'ir.model.access', 616, false, now() at time zone 'UTC', now() at time zone 'UTC'), ('gear_manufacturing', 'access_gear_manufacturing_gear_manufacturing', 'ir.model.access', 617, false, now() at time zone 'UTC', now() at time zone 'UTC')\n                ON CONFLICT (module, name)\n                DO UPDATE SET date_update=(now() at time zone 'UTC') \n            "
ERROR: ON CONFLICT DO UPDATE command cannot affect row a second time
HINT: Ensure that no rows proposed for insertion within the same command have duplicate constrained values.

2019-11-24 05:34:14,321 27436 ERROR db_test odoo.addons.base.models.ir_model: Failed to insert ir_model_data
('gear_manufacturing', 'access_gear_manufacturing_gear_manufacturing', 'ir.model.access', 616, False)
('gear_manufacturing', 'access_gear_manufacturing_gear_manufacturing', 'ir.model.access', 617, False)
Awatar
Odrzuć

it seems there is an issue with metadata (ir_model_data). I think it will solve when you create a new database (if feasible)

Najlepsza odpowiedź

above example works as it should there is no issue with code.

I think you need new model for product model instead of inheriting it from product.template 
add product model as many2one with gear.manufacturing like

class ProductModel(models.Model):
    _name = 'product.model'
    name = fields.Char('Product Model')

class GearManufacturing(models.Model):
    ......
   model_id = fields.Many2one('product.model', 'Model',required=True)

if you need a product model on product.tempalate you can also add many2one relation there 

Awatar
Odrzuć
Autor

Ravi, Updated my question. I am getting error while upgrading my module. Maybe this pertain with the question I have posted

Powiązane posty Odpowiedzi Widoki Czynność
2
wrz 21
4308
1
lip 19
2032
7
lis 15
12640
4
paź 22
3938
2
wrz 21
2308