Skip to Content
Menu
This question has been flagged
2 Replies
11299 Views

Hello,

In a personal module, I want to do something special.

When I click on the menuitem, I want to show a form view where I have one field. This field is a many2one field.

When I select a value for this field, I want to click on a button (not the create button, so I don't want to create a record) and after the click, I want to show a pivot view depending of the value of the field selected.


There are my codes :

class miadi_tarifs(models.Model):
    _name = 'miadi.tarifs'
    
    code = fields.Char(string='Code', default='', required=True)
    libelle = fields.Char(string='Libellé', default='', required=True)
class miadi_lignesTarifs(models.Model):
    _name = 'miadi.lignestarifs'
    
    code_tarif = fields.Many2one('miadi.tarifs', 'Price Code', default='', required=True, ondelete='cascade')
    produit_id = fields.Many2one('product.product', 'Product', required=True, ondelete='cascade')
    conditionnement_id = fields.Many2one('miadi.packaging', 'Packaging', required=True, ondelete='cascade')
    prix_unitaire = fields.Float('Unit Price', default=0)

Actually, in the pivot view return by a function, I have in first column the "code_tarif", in second column the "produit_id", in row the "conditionnement_id" and that is display for the cases is the "prix_unitaire". What I want is to display the pivot view with only the "produit_id" in column depending the "code_tarif" value selected in the previous for view.

I hope you will understand me and you will be able to help me.

I'm on Odoo 10

Thanks

Avatar
Discard
Author Best Answer

Hi Mohammed,

I tried your code and it works.

Thank you very much

Avatar
Discard
Best Answer

Hi,

I hope what you want is a wizard before you want to open pivot view.

You can use a transient model if you don't want to save the record(it is used in case of wizards).

class WizardModel(models.TransientModel):
_name = 'wizard.model.name'

your_many2one= fields.Many2one('ref.model')

    @api.multi
    def open_pivot_view(self):
        print self.your_many2one
      return {
      'type': 'ir.actions.act_window',
    'name': 'Name of view',
    'res_model': 'model.tobe.opened',
    'domain': [],
      'view_mode': 'pivot',
      'context': {}
    }

then action for your menu from which this wizard needs to be called should be:

<act_window id="launch_the_wizard"
            name="Launch the Wizard"
            src_model="context.model.name"
            res_model="wizard.model.name"
            view_mode="form"
            target="new"
            key2="client_action_multi"/>

then define a normal form view for your wizard(wizard.model.name) with a button name=open_pivot_view

You can give domain and context according to your many2one field

Avatar
Discard
Related Posts Replies Views Activity
2
Jul 22
1662
0
Mar 24
245
3
Jan 24
13207
2
Mar 15
6450
2
Jul 23
784