Passing Context In Odoo

我是研究僧i 提交于 2019-12-10 11:47:03

问题


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>


回答1:


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}}

    }


来源:https://stackoverflow.com/questions/34217665/passing-context-in-odoo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!