我有 2 张one2many
关系表。在更改主表中的名称值后,我想在从表中创建一组记录。但我有一个错误:
文件“C:\odoo80\openerp\addons-custom\att\agreement.py”,第 18 行,在 _onchange_name
self.pool['att.agreement.line'].create({'agreement_id': id , 'name': str(x), 'qty': x * 100} )
文件“C:\odoo80\openerp\api.py”,第 250 行,在包装器中返回 old_api(self, *args, **kwargs)
TypeError: create() 至少需要 4 个参数(给定 2 个)
我的课程是:
class Agreement(models.Model):
_name = 'att.agreement'
line_id = fields.One2many('att.agreement.line','agreement_id', 'Lines', copy=True )
name = fields.Char(string='Name', required=True)
def create(self, cr, uid, values, context=None):
return super(Agreement, self).create(cr, uid, values, context)
@api.onchange('name')
def _onchange_name(self):
if (self.name):
for x in range(1,5,1):
self.pool['att.agreement.line'].create({'agreement_id': id , 'name': str(x), 'qty': x * 100} )
class AgreementLine(models.Model):
_name = 'att.agreement.line'
agreement_id = fields.Many2one('att.agreement', ondelete='cascade', select=True ) # required=True ,readonly = True
name = fields.Char(string='Name', required=True)
qty = fields.Integer(string = 'Qty')
def create(self, cr, uid, values, context=None):
id = super(AgreementLine, self).create(cr, uid, values, context)
return id
我的看法是:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<!-- form AGREEMENT -->
<record model="ir.ui.view" id="att_agreement_view_form">
<field name="name">Agreement</field>
<field name="model">att.agreement</field>
<field name="arch" type="xml">
<form string="Agreement">
<sheet>
<group colspan="4">
<group>
<field name="name"/>
</group>
</group>
<notebook>
<page string="Agreement Lines">
<tree string="Agreement Lines" create ='false'>
<field name="line_id" >
<field name = "id"/>
<field name="name"/>
<field name="qty"/>
</field>
</tree>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="att_agreement_view_tree">
<field name="name">List of agreement</field>
<field name="model">att.agreement</field>
<field name="arch" type="xml">
<tree string="List of agreements">
<field name="name"/>
</tree>
</field>
</record>
<!-- window action -->
<record model="ir.actions.act_window" id="att_agreement_list_action">
<field name="name">Agreement</field>
<field name="res_model">att.agreement</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="att_agreement_menuitem" name="Соглашения"
parent="att_menu_agreement"
action="att_agreement_list_action"/>
</data>
</openerp>
有谁能够帮我?