0

I have a task that has been giving head ache , kindly really appreciate some help .
TASK :

  • Model A to Model B have a many2many relation .
  • In Model B which has a many2many relation,i have a Integer field.
  • If the field integer is 3 or more , for each line of the line items added using the many2many items , generate dynamically weekly schedules meaning if the integer value is 3 generate three weeks dynamically for all the line items in the many2many if the field is 4 for each line items generate 4 week to schedule on .

I have tried using a wizard to no avail . Ways of solving i think could be of help but i havent been able successfully make it work is using the fields_view_init() , fields_view_get() , using context where i pick the value of the integer fields in model B of the many to many relation and using @api.onchange and @api.depends -- pull the value of the integer field and may be using the fields_view_get() dynamically create the two weeks schedule or the 3 three weeks depending on the integer value .

How can i achieve , please some code examples are highly appreciated . This code below will help understand what i mean above

class  ratecard_sin_radio(models.Model):
    code  = fields.Char(string='SINGULAR 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')


class  ratecard_multiple(models.Model):
    #pudb.set_trace()
    _name = 'ratecard.multiple'
    scheduled_for  = fields.Integer(string='SCHEDULED FOR',default=1 ,track_visibility='always',store=True , readonly=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') 

Sample part of the view i have :

  <group colspan="4"  col="4" >
<tree  editable="bottom">
        <group colspan="2"  col="2" >
             <field name='name'/>

            <field name="scheduled_for"/>
              </group>

        <field name='multiple_ratecard_id' nolabel="1" options="{'reload_on_button': true}">  <!-- widget="many2many"-->
        <tree  string="ALLOCATE SPOTS" editable="bottom">
                            <!--<field name="week_id" widget="one2many_list"/>-->
                         <button name="scheduler" string="SCHEDULE" type="object" class="oe_highlight"/>
                           <field name="code"/>
                            <field name="name"/>
                            <field name="outlet_id" on_change="onchange_outlet(outlet_id)" placeholder="OUTLET"/>
                             <field name="outlet_type_id" domain="[('outlet_id', '=' ,outlet_id)]" placeholder="OUTLET TYPE" />

                             <field name='monday'/>
                            <field name='tuesday'/>
                            <field name='wednesday'/>
                            <field name='thursday'/>
                            <field name='friday'/>
                            <field name='saturday'/>
                             <field name='sunday'/>
                             <field name="spot_total"/>
                             <field name="noofweeks"/>
                           <field name='allocate_subtotal'/>
                           <field name="rates_total"/>
                          <field name="total_cost"/>
        </tree>
      </field>

The button scheduler is a function that now depends on scheduled_for to dynamically generate the weekly views that is if scheduled_for is 3
then dynamically i generate mon- sun mon - sun mon-sun . if
4 then i generate mon -sun mon-sun mon-sun mon-sun

On the <button name="scheduler" string="SCHEDULE" type="object" class="oe_highlight"/>

calls this function which creates a week. Problem i need to control this week to be generated according to the scheduled_for value such that if scheduled_for is 3 i return a week calendar model that have 3 weeks that is mon-sun , mon-sun , mon -sun if it the scheduled_for is 4 then i return mon-sun , mon-sun , mon -sun , mon-sun

@api.multi
def scheduler(self):
    view_id = self.env.ref('ragtimeorder.view_week_form').id
#   context = self._context.copy()
    return {
            'name':_('SCHEDULE RATECARD'),
            'view_type': 'form',
            'view_mode': 'form',
            'views': [(view_id, 'form'), ],
            'res_model': 'week',
           # 'context': self._context,
            'type': 'ir.actions.act_window',
            'target': 'new',
            'flags': {'action_buttons': True},
}

Problem with this scheduler function is static which it is required to be dynamic

danielmwai
  • 305
  • 1
  • 6
  • 24
  • Please edit your question and add: 1. Your code/your attempts 2. Your input, current output and expected output. – Bhavesh Odedra Dec 02 '15 at 13:50
  • I do not understand: do you have a form for model A which shows a field of model B? In the form of model B you have another many2many field for model, say C? depending of rows of C (say ROWS) and integer field (say N), you need to create ROWS x N weeks of schdeuling? – Alessandro Ruffolo Dec 02 '15 at 13:52
  • @Odedra,@Alessandro , kindly i have added the code for better understanding – danielmwai Dec 02 '15 at 14:59
  • what's in the 'monday' field etc.? – Alessandro Ruffolo Dec 02 '15 at 15:27
  • @AlessandroRuffolo the monday field contains can be a date or a 0 or 1 , mon-sun -- i use this to schedule – danielmwai Dec 03 '15 at 06:47
  • @danielmwai so you need to generate the rows in multiple_ratecard_id depending on field! Am I right? – Alessandro Ruffolo Dec 03 '15 at 08:34
  • @AlessandroRuffolo , not the rows , the scheduler button that calls the function scheduler returns a view with a model week , kindly i have made an edit , please check ,Now on the scheduler takes the value of the schedule_for value such that if its 3 it will dynamically create 3 weeks in the view when the button is clicked if the value of the schedule_for is changed to 4 then it dynamically creates a 4 weeks and that will happen for each row in the multiple_ratecard_id – danielmwai Dec 03 '15 at 08:49

1 Answers1

0

@danielmwai

Their are multiple possible solution possible here, that you can employee:

1) Every time you schedule you create a database record for all possible event (sold and persistent solution but lot of over head)

2) You can virtually create records using read/search_read methods, every time some one ask for record you read that record and create virtual record pass in the view as views re dump it will render values and return according and when you get back data for write then over ride write method and remove virtual record and handle them on code. (fast but can misbehaves some times)

3) You can write web module and let JS do the magic and do all event rendering though website interface module.

Bests

ifixthat
  • 6,137
  • 5
  • 25
  • 42