Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Ability for user to create custom fields for quality on lot/serial numbers

By
Johan Vergeer
on 8/6/15, 6:40 AM 394 views

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. 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 8/6/15, 6:40 AM
Seen: 394 times
Last updated: 8/6/15, 6:40 AM