콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
4785 화면

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)
아바타
취소

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

베스트 답변

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 

아바타
취소
작성자

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

관련 게시물 답글 화면 활동
2
9월 21
5492
1
7월 19
2921
7
11월 15
14215
4
10월 22
5024
2
9월 21
3013