我正在尝试创建一个新向导,但我不太了解如何做到这一点:(在一些指南中我找到了这段代码:
<wizard
id="test_wizard"
keyword="client_action_multi"
model="product.product"
name="product.product.product_id"
string="Test wizard" />
在技术纪念品中,我发现了这一点:
<record id="action_idea_cleanup_wizard" model="ir.actions.act_window">
<field name="name">Cleanup</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">idea.cleanup.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
我应该使用哪种语法?
编辑:我试过做向导,代码如下:
蟒蛇文件:
from openerp.osv import osv
from openerp.osv import fields
class create_ean(osv.osv_memory):
_name='generate.ean'
_columns = {
'product_def_code' : fields.text('Product Default Code'),
'product_gen_code' : fields.text('Product Generated EAN13', readonly = True),
}
#defaults calls a function that will browse your main object and fill the field with the existing information
_defaults = {
'product_def_code': lambda self, cr, uid, context: self._get_product_id(cr, uid, context),
'product_gen_code': lambda self, cr, uid, context: self.generate_ean(),
}
def save_code(self, cr, uid, ids, context=None):
if 'active_id' in context:
info = self.browse(cr,uid,ids)
self.pool.get('ean13').write(cr,uid,context['active_id'],{'ean13': info[0].product_gen_code})
return {
'type': 'ir.actions.act_window_close',
}
def generate_ean(self):
return "ouhdeguosAB13"
def _get_product_id(self, cr, uid, context=None):
if 'active_id' in context:
return self.pool.get('product.product').browse(cr, uid, context['active_id'], context).product_id
create_ean()
XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- create a view with a unique id -->
<record id="view_generate_ean13_code_wizard" model="ir.ui.view">
<field name="name">generate_ean13_code.form</field>
<field name="model">product.product</field>
<field name="type">form</field>
<field name="arch" type="xml">
<!-- create a normal form view, with the fields you've created on your python file -->
<form string="Insert reformulation info" version="7.0">
<group >
<separator string="EAN13 Code Generator" colspan="2"/>
<field name="product_def_code" string="Product Default Code"/>
<field name="product_gen_code" string="Product EAN13 Generated Code"/>
<newline/>
</group>
<div style="text-align:right">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-ok" name="save_code" string="Save the code" type="object" />
</div>
</form>
</field>
</record>
<!-- your action window refers to the view_id you've just created -->
<record id="action_generate_ean" model="ir.actions.act_window">
<field name="name">Generate EAN13</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">generate.ean</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_generate_ean13_code_wizard"/>
<field name="target">new</field>
</record>
<act_window id="action_generate_ean"
name="Generate EAN13"
res_model="generate.ean"
view_mode="form"
target="new"
/>
</data>
</openerp>
我将解释我需要做什么,基本上我需要获取产品的 product_id 并生成 ean13,我为生成代码做了一个测试方法,但我不明白如何保存生成的代码在 ean13 字段中,以及如何使用我的方法通过将 product_id 传递给他来生成该代码