我正在处理这个Odoo任务。我必须制作一个自定义模块,其中的要求是这样的。
有一个表格说"笔记本电脑"它包含一个来自&hr; hr.employee'即很多人。此表单将包含的下一个内容是一个包含3列(质量,分数,注释)的表。现在,Qualities必须是一个包含许多品质名称的主表。
我以SalesOrder表单的方式完成此任务,即对于特定的销售订单,有多个销售线。
但是我希望所有的素质都存在于默认分数值为0的表格上。
这是代码
请告诉我决议
class qualities_fields(models.Model):
_name = "ayda.qualities.fields"
_description = "Contains only Attributes"
@api.multi
def name_get(self):
data = []
for rows in self:
value = ''
value += rows.quality_name
data.append((rows.id, value))
return data
quality_name = fields.Char(string="Quality Name")
class qualities_data(models.Model):
_name = "qualities.data"
_description = "All points mandatory to be filled"
quality_id = fields.Many2one('notebook', string="Quality IDs")
quality_name = fields.Many2one('qualities.fields', string="Quality Name")
score = fields.Integer(string="Score")
comment = fields.Char(string="Comment")
class notebook(models.Model):
_name = "notebook"
_description = "Checking one2many of qualities"
def createRecords(self):
cr = self.pool.cursor()
quantity_fields = self.pool.get('qualities.fields').search(cr, self.env.uid, [])
quantity_lines = []
for field in quantity_fields:
quality_data = {
'quality_id' : self.id,
'quality_name' : field.id,
'score' : 0,
'comment' : ''
}
quantity_lines.append(quality_data)
return quantity_lines
name = fields.Many2one('hr.employee', string="Name")
qualities_line = fields.One2many('qualities.data', 'quality_id', string="Qualities Line", default=createRecords)
答案 0 :(得分:0)
有一种更简单的方法,在字段定义上将默认分数设置为0
score = fields.Integer(string="Score", default=0)
这样,所有得分在创建时都会为零