您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在onchange事件中加载一个到多个孩子?

5b51 2022/1/14 8:20:30 python 字数 9320 阅读 459 来源 www.jb51.cc/python

我有一个选择领域(多对一分区) 如果我选择一个部门需要在“笔记本部分”加载其“员工”. 如何在openerp 7中实现这一点? 如果我选择相关的房地产ID,则需要加载相关的部门.如果部门选择则需要在后续阶段加载相关的工人 <record model="ir.ui.view" id="bpl_work_offer_form"> <field name="name">bpl.work.offer.fo

概述

如果我选择相关的房地产ID,则需要加载相关的部门.如果部门选择则需要在后续阶段加载相关的工人

<record model="ir.ui.view" id="bpl_work_offer_form">
<field name="name">bpl.work.offer.form</field>
<field name="model">bpl.work.offer</field>
<field name="arch" type="xml">
<form string='bpl_work_offer' version='7.0'>
<sheet>

<group>
    <group>
        <field name='bpl_estate_id' />
        <field name='bpl_division_id' />
        <field name='user_id' />
    </group>
    <group>
        <field name='date_of_offer' />
        <field name='payment_type' />
        <field name='select_by' />
        <field name='no_of_workers' attrs="{'invisible':[('select_by','=','by_name')]}" />
        <field name='work_type' />

    </group>
</group>
<div name="Worker Selection"></div>
<separator string='Select workers' />
<notebook attrs="{'invisible':[('select_by','by_count')]}">
    <page string="Tea Workers" attrs="{'readonly':[('work_type','!=','tea')]}">
        <field name='selected_tea_workers_line_ids' nolabel='1'>
            <tree string='List' editable='bottom'>
                <field name='worker_id' />
                <field name='is_selected' />
            </tree>
        </field>
        <group class='oe_subtotal_footer oe_right'>
            <field name='total_workers' />
        </group>
        <br />
        <br />
    </page>
    <page string="Rubber Workers" attrs="{'readonly':[('work_type','rubber')]}">
        <field name='selected_rubber_workers_line_ids' nolabel='1'>
            <tree string='List' editable='bottom'>
                <field name='worker_id' />
                <field name='is_selected' />
            </tree>
        </field>
        <group class='oe_subtotal_footer oe_right'>
            <field name='total_workers' />
        </group>
        <br />
        <br />
    </page>
    <page string="Sundry Workers" attrs="{'readonly':[('work_type','sundry')]}">
        <field name='selected_sundry_workers_line_ids' nolabel='1'>
            <tree string='List' editable='bottom'>
                <field name='worker_id' />
                <field name='is_selected' />
            </tree>
        </field>
        <group class='oe_subtotal_footer oe_right'>
            <field name='total_workers' />
        </group>
        <br />
        <br />
    </page>
</notebook>
</sheet>
</form>
</field>
</record>

<record model="ir.actions.act_window" id="bpl_work_offer_action">
<field name="name">bpl.work.offer.action</field>
<field name="res_model">bpl.work.offer</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
</record>

型号代码

class company_new_registration(osv.osv):
    _name = "bpl.company.n.registration"
    _description = "Company"
    _columns = {
                'name': fields.char('Company Name',size=128,required=True),'estates': fields.one2many('bpl.estate.n.registration','company_id','Estate')                                        
    }
# Bill of Material
company_new_registration()

class estate_new_registration(osv.osv):
    _name = "bpl.estate.n.registration"
    _description = "Estates"
    _columns = {
        'name': fields.char('Estate Name','company_id': fields.many2one('bpl.company.n.registration','Company Name',select=True),'divisions': fields.one2many('bpl.division.n.registration','estate_id','Division')
    }

estate_new_registration()

class division_new_registration(osv.osv):
    _name = "bpl.division.n.registration"
    _description = "Divisions"
    _columns = {
        'name': fields.char('Division Name','estate_id': fields.many2one('bpl.estate.n.registration','Estate Name',}

division_new_registration()

并且需要为该工作提供的映射(种植园项目)

class bpl_work_offer(osv.osv):
    _name = "bpl.work.offer"
    _description = "BPL Work Offer"
    _columns = {
        'user_id': fields.many2one('res.users','User Name'),'date_of_offer': fields.date('Date'),'bpl_estate_id':fields.many2one('bpl.estate.n.registration','Estate',help='Estate'),'bpl_division_id':fields.many2one('bpl.division.n.registration','Division',help='Division'),'payment_type': fields.selection([('normal_work','Normal Work'),('cash_work','Cash Work')],'Payment Type'),'select_by': fields.selection([('by_name','By Names'),('by_count','By Count')],'Select  By'),'no_of_workers': fields.integer('No of Workers'),'work_type': fields.selection([('tea','Tea'),('rubber','Rubber'),('sundry','Sundry')],'Work Type'),'total_workers': fields.integer('Total Workers'),'selected_tea_workers_line_ids': fields.one2many('bpl.selected.tea.workers.line','worker_id','Tea Workers',ondelete="cascade"),'selected_rubber_workers_line_ids': fields.one2many('bpl.selected.rubber.workers.line','Rubber Workers','selected_sundry_workers_line_ids': fields.one2many('bpl.selected.sundry.workers.line','Sundry Workers',}

bpl_work_offer()

class selected_tea_workers_line_ids(osv.osv):
    _name = 'bpl.selected.tea.workers.line'
    _description = 'BPL Selected Tea Workers line'
    _columns = {
        'worker_id':fields.many2one('bpl.worker','Tea Worker',ondelete='cascade',help='Worker'),'is_selected': fields.boolean('Select',help="Selected or not"),}

selected_tea_workers_line_ids()

class selected_rubber_workers_line_ids(osv.osv):
    _name = 'bpl.selected.rubber.workers.line'
    _description = 'BPL Selected Rubber Workers line'
    _columns = {
        'worker_id':fields.many2one('bpl.worker','Rubber Worker',}

selected_rubber_workers_line_ids()

class selected_sundry_workers_line_ids(osv.osv):
    _name = 'bpl.selected.sundry.workers.line'
    _description = 'BPL Selected Sundry Workers line'
    _columns = {
        'worker_id':fields.many2one('bpl.worker','Sundry Worker',}

selected_sundry_workers_line_ids()
def onchange_partner_id(self,cr,uid,ids,type,partner_id,\
        date_invoice=False,payment_term=False,partner_bank_id=False,company_id=False):
    res = super(account_invoice,self).onchange_partner_id(cr,date_invoice=date_invoice,payment_term=payment_term,partner_bank_id=partner_bank_id,company_id=company_id)

    invoice_lines = []
    product_ids = self.pool.get('product.product').search(cr,[],limit=5)
    for p in self.pool.get('product.product').browse(cr,product_ids):
        invoice_lines.append((0,{'product_id':p.id,'name':p.name,'account_id':p.categ_id.property_account_income_categ.id,}))#this dict contain keys which are fields of one2many field 
    res['value']['invoice_line']=invoice_lines
    return res

如果只有一行要添加
RES [ ‘值’].更新({
‘one2many_fieldmname’:[(0,{ ‘field1的’:值1,‘FIELD2’:值2,‘字段N’:值N})]
})

在上面的例子中,我正在搜索5个产品,这些产品被添加到invoiceline中.因此,在您的onchange功能中,您还必须搜索该部门下的员工.

在您的代码中,以“bpl_work_offer_form”的形式在字段bpl_division_id中添加onchange函数.(在我的示例中,partner_id是many2one字段,invoice_line是one2many字段.)

使用onchange加载one2many字段时需要更加小心.在onchange函数中,您必须首先取消链接在many2one字段中加载的所有记录.因为如果保存记录,那么如果再次加载onchange,则会创建一个新行.所以你需要正确管理它.

参考:http://doc.openerp.com/trunk/developers/server/06_misc_on_change_tips/

总结

以上是编程之家为你收集整理的如何在onchange事件中加载一个到多个孩子?全部内容,希望文章能够帮你解决如何在onchange事件中加载一个到多个孩子?所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶