在Odoo中传递上下文 [英] Passing Context In Odoo

查看:111
本文介绍了在Odoo中传递上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将ratecard_multiple中的schedule_for传递给ratecard_sin_radio中的Scheduled,以便可以在radio_sin_radio函数action_four_weeks_schedule_form中使用它 在这里,我添加了所有正在使用的代码

How can i pass this scheduled_for in ratecard_multiple to scheduled in ratecard_sin_radio so that i can use it in the radio_sin_radio function action_four_weeks_schedule_form Here i have added all the code that am using

class ratecard_multiple(models.Model):
    # pudb.set_trace()
    _name = 'ratecard.multiple'
    _rec_name = 'display_name'
    name = fields.Char(string='Multiple RateCard Product  Name ', required=True)
    code = fields.Char(string='Multiple RateCard Code ', readonly=True)
    scheduled_for = fields.Integer(string='SCHEDULED FOR', default=1, track_visibility='always', store=True)
    # scheduled_for  = fields.Integer(string='SCHEDULED FOR',  compute='_compute_scheduled_for',default=1 ,track_visibility='always',store=True)
    min_weeks = fields.Integer(string="MINIMUM NO OF WEEKS", default=1, store=True)
    max_weeks = fields.Integer(string="Maximum NO OF WEEKS", default=1, track_visibility='always', store=True)

    multiple_ratecard_id = fields.Many2many(comodel_name='ratecard.sin.radio',
                                            relation='ratecard_multiple_singular_rel',
                                            column1='ratecard_multiple_id',
                                            column2='ratecard_sin_radio_id',
                                            string='RATECARDS')

class ratecard_sin_radio(models.Model):
    _name = 'ratecard.sin.radio'
    _description = 'RATECARD SINGULAR RADIO  '

    code = fields.Char(string='RADIO SINGULR RATECARD CODE', readonly=True)
    name = fields.Char(string='NAME')
    outlet_id = fields.Many2one(comodel_name='outlet', string='Outlet')
    timeband_id = fields.Many2one(comodel_name='timeband', string='TimeBand')

    def action_four_weeks_schedule_form(self,cr,uid,ids,context):
        order_obj = self.pool.get('ratecard.multiple').browse(cr,uid,ids)[0]
        return {
            'name':_("Four  Week Schedule to Process"),
            'view_mode': 'form',
            'view_id': False,
            'view_type': 'form',
            'res_model': 'four.weeks.schedule',
            'context':{'default_scheduled_for': order_obj.scheduled_for, 'default_code': order_obj.code},
            'type': 'ir.actions.act_window',
            'nodestroy': True,
            'target': 'new',
            'domain': '[]',
            'flags': {'form': {'action_buttons': True}}

    }



class FourWeeksSchedule(models.Model):
    _name = 'four.weeks.schedule'

    code = fields.Char(  string='RateCard Code ',)
    scheduled_for = fields.Integer(string='SCHEDULED FOR', track_visibility='always', store=True)
    from_date = fields.Date(
        'From Date', required=True, default=lambda self: fields.Date.today())
    to_date = fields.Date(
        'To Date', required=True, default=lambda self: fields.Date.today())

    monday = fields.Integer(string='MON')
    tuesday = fields.Integer(string='TUE')
    wednesday = fields.Integer(string='WED')
    thursday = fields.Integer(string='THUR')
    friday = fields.Integer(string='FRI')
    saturday = fields.Integer(string='SAT')
    sunday = fields.Integer(string='SUN')
    spot_total = fields.Integer(compute='compute_totalspots', string='SPOTS TOTAL', readonly=True, store=True)



In  the  view  of the  ratecard.multiple i  have this  


   <tree  editable="bottom">
                                                <group colspan="2"  col="2" >
                                                    <field name="name"/>
                                                     <field name='display_name'/>
                                                    <field name='code'/>
                                                    <field name="validity_date"/>
                                                    <field name="scheduled_for"/>
                                                    <field name="min_weeks"/>
                                                    <field name="max_weeks"/>
                                                    <!--<field name="multiple_ratecard_id_count"/>-->
                                                    <field name="multiple_ratecard_id_count" widget="statinfo"/>


                                                     <!--<field name="allocate_schedule_count"/>-->
                                                     <!--<field name='company_id'/>-->
                                                      </group>
                                                <field name='multiple_ratecard_id' nolabel="1" options="{'reload_on_button': true}">  <!-- widget="many2many"-->
                                                <tree  string="ALLOCATE SPOTS" editable="bottom" >
                                                         <button name="action_four_weeks_schedule_form" string="CREATE SCHEDULE" type="object" />

                                                                   <field name="code"/>
                                                                    <field name="name"/>
                                                                    <field name="outlet_id" on_change="onchange_outlet(outlet_id)" placeholder="OUTLET"/>
                                                      </tree>
                                              </field>
                                           </tree>

推荐答案

def action_four_weeks_schedule_form(self,cr,uid,ids,context):
    order_obj = self.pool.get('ratecard.multiple').browse(cr,uid,ids)[0]
    return {
        'name':_("Four  Week Schedule to Process"),
        'view_mode': 'form',
        'view_id': False,
        'view_type': 'form',
        'res_model': 'four.weeks.schedule',
        'context':{'default_scheduled_for': order_obj.scheduled_for, 'default_code': order_obj.code},
        'type': 'ir.actions.act_window',
        'nodestroy': True,
        'target': 'new',
        'domain': '[]',
        'flags': {'form': {'action_buttons': True}}

    }

这篇关于在Odoo中传递上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆