This question has been flagged

I am working on a project where the customer would like to create his own fields for quality purposes depending on the product category. 

The fields can be integers, strings, dates or booleans. (For example the serial number of a machine or the count number on a printer. 

I have created a model where the user can input the name of the field, the type of the field, the quality category and a checkbox if this field should be mandatory. 
I have created another model for the quality categories, which has a many2many relation with the quality fields. 

I have also created an extra model to put these together and have the ability for the user to enter a value. 

This would be fine if we do not have to worry about the different categories and the field types. 

This is the code I have so far:

quality.py

# -*- coding utf-8 -*-

from openerp import models, fields, api


class QualityFields(models.Model):
_name = 'quality.fields'
name = fields.Char("Name")
type = fields.Selection([("int", "Numerical"),("string","Alfanumerical"), ("boolean", "Checkbox"), ("date", "Date")])
mandatory = fields.Boolean("Mandatory field")
display_order = fields.Integer("Display Order")
quality_categories = fields.Many2many("quality.categories", string="Quality categories")
quality_fields_lot_number = fields.One2many("quality.fields.lot.number","quality_fields",string="Quality fields lot number")


class QualityCategories(models.Model):
_name = "quality.categories"
name = fields.Char("Name")
quality_fields = fields.Many2many("quality.fields", string="Quality fields")


# Tussentabel voor Qualityfields en Lot/Serial Numbers
class QualityFieldsLotNumber(models.Model):
_name = "quality.fields.lot.number"
lot_number = fields.Many2one("stock.production.lot",string="Lot/Serial numbers")
quality_fields = fields.Many2one("quality.fields",string="Quality fields")
value = fields.Char("Value")
stock.py


# -*- coding utf-8 -*-

from openerp import models, fields, api


class Name(models.Model):
_inherit = "stock.production.lot"
quality_fields_lot_number = fields.One2many("quality.fields.lot.number","lot_number" ,string="Quality fields")
stock_view.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_production_lot_form_inherited" model="ir.ui.view">
<field name="name">stock.production.lot.form.inherited</field>
<field name="model">stock.production.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_form"/>
<!--<field name="priority">10</field>-->
<field name="arch" type="xml">
<page string="Products" position="after">
<page string="quality">
<field name="quality_fields_lot_number" nolabel="1">
<tree string="quality" editable="bottom">
<field name="quality_fields" t-if="quality_categories.id == product_id.categ_id.quality_category.id"/>
<field name="value"/>
</tree>
</field>
</page>
</page>
</field>
</record>
</data>
</openerp>
Could anyone help me to get this done. 
First of all I do not think I have to use a tree to do this because I think there can be only one field type per column in the tree. 

I think I would be better to be able to just generate new fields on the fly, add the category and show them with the corresponding lot/serial numbers. 

Thanks a lot if you can help me with this. 

Avatar
Discard