Anyone please help me,
i have a custom module related to purchase.order , i use this code to make additional tab in purchase.order here's the code :
approval.py
#I make this new form to save master data approval
class master(osv.osv):
_name="wtc.approval.matrixbiaya"
_columns = {
'form':fields.many2one('ir.model',string='Form',required=True),
'cabang_id':fields.many2one('res.partner',string='Branch',required=True),
'divisi_id':fields.selection([('t','Unit'),('s','Sparepart'),('u','Umum'),('f','Finance')],'Division',change_default=True,required=True),
'group_id':fields.many2one('res.groups',string='Group',required=True),
'limit': fields.float(digits=(8,2), string="Limit",required=True),
}
#i make this code to make a new tab called 'Approval' in purchase.order
class approval_po(osv.osv):
_inherit="purchase.order"
_columns={
'app_line': fields.one2many('apps.po','purchase_id',string="Table Approval"),
}
#this code is method to generate button approval
def wtc_approval(self, cr, uid, ids, context=None):
res = super(approval_po, self).wtc_approval(cr, uid, ids, context=context)
print "dffffffffffffffffffff"
return res
# This is create method
def create(self, cr, uid, vals, context=None):
vit = self.pool.get("wtc.approval.matrixbiaya").search(cr,uid,[("cabang_id","=",vals["cabang_id"]), ("form","=","purchase.order"), ("divisi_id","=",vals["divisi_id"])])
data = self.pool.get("wtc.approval.matrixbiaya").browse(cr,uid,vit)
approval = []
for x in data :
approval.append({
'group':x.group_id.id,
'cabang_id':x.cabang_id.id,
'wewenang':x.limit,
'sts':'1',
})
vals["app_line"] = approval
return super(approval_po, self).create(cr, uid, vals, context=context)
#this code is table for a new tab
class approval_po_line(osv.osv):
_name="apps.po"
_columns={
'purchase_id' :fields.many2one('purchase.order','Purchase'),
'group':fields.many2one('res.groups','Group', select=True),
'cabang_id': fields.many2one('res.partner','Branch',select=True),
'wewenang':fields.char('Wewenang', size=128),
'sts':fields.selection([('1','NO'),('2','OK')],'Status',change_default=True),
'pelaksana':fields.many2one('res.users','Pelaksana'),
'tanggal':fields.datetime('Tanggal'),
}
_defaults={
'sts' : '1'
}
---------------------------------------------------------------------------------------------------------------------------------------------------------
approval_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- this code for a new form Mater Approval -->
<record model="ir.ui.view" id="master_approval_tree_view">
<field name="name">master.approval.tree</field>
<field name="model">wtc.approval.matrixbiaya</field>
<field name="arch" type="xml">
<tree string="Approval Matrix Biaya">
<field name="form"/>
<field name="cabang_id"/>
<field name="divisi_id"/>
<field name="group_id"/>
<field name="limit"/>
</tree>
</field>
</record>
<record id="master_approval" model="ir.ui.view">
<field name="name">master.approval.view</field>
<field name="model">wtc.approval.matrixbiaya</field>
<field name="arch" type="xml">
<form string="Form Approval Matrix Biaya" version="7.0">
<group>
<field name="form" style="width: 25%%"/>
<field name="cabang_id" style="width: 30%%"/>
<field name="divisi_id" style="width: 10%%"/>
<field name="group_id" style="width: 45%%"/>
<field name="limit"/>
</group>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="approval_action">
<field name="name">Matrix Approval Biaya</field>
<field name="res_model">wtc.approval.matrixbiaya</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<!-- This code for a new Tab called 'Approval'-->
<record id="rules_approval_po" model="ir.ui.view">
<field name="name">master_approval_po_tab</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<button name="view_picking" position="after">
<button string="Approval" name="wtc_approval" type="object" class="oe_highlight"/>
</button>
<field name="partner_id" position="before">
<field name="cabang_id"></field>
<field name="divisi_id" style="width:35%%"></field>
</field>
<xpath expr="//page[@string='Deliveries & Invoices']" position="after">
<page string="Approval">
<field name="app_line">
<tree string="Approval" editable="bottom">
<field name="group" />
<field name="cabang_id"/>
<field name="wewenang"/>
<field name="sts"/>
<field name="pelaksana"/>
<field name="tanggal"/>
</tree>
</field>
</page>
</xpath>
</field>
</record>
<menuitem id="master_approval_menu" name="Approval Matrix Biaya" parent="base.menu_config" action="approval_action"/>
</data>
</openerp>
-----------------------------------------------------------------------------------------------------------------------------------------------------
when i create a new purchase order, the approval line doesn't show any record (that's what i want , and i want it to be read only it means it cannot add an item),
then when i save the current form purchase order , the approval line in Approval tab show some record that refer to Custom Form called 'Master Approval' , i got an error .. please help me