Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
12380 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Hi Mohammed,

I tried your code and it works.

Thank you very much

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
Non-dict expression Đã xử lý
2
thg 7 22
2853
0
thg 3 24
1062
3
thg 1 24
14440
2
thg 3 15
7336
2
thg 7 23
784