Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
9882 Zobrazení

Hi, 

i have a model called shift with status field, it can be open or closed, and it has a field called closing balance 

i want to create a button (close shift) that will be shown in tree view of the shifts, and when i click on it i should go to a form that will ask me to fill closing balance for this shift and when i click save the status of the shift will be changed to closed

Any when can help me please or give some guidelines for how to create this form and button and i will be thankful 

Avatar
Zrušit
Nejlepší odpověď
Please try this

@api.multi

def close_shift(self):

name = _('Close Shift')

view_mode = 'tree,form'

return {

'name': name,

'view_type': 'form',

'view_mode': view_mode,

'res_model': 'Your Model Name',

'type': 'ir.actions.act_window',

'target': 'current',

}

if you want to specify which shift then you can pass it by res_id tag in it.
Avatar
Zrušit

Hello, I am getting the following error in V13

werkzeug.exceptions.BadRequest: 400 Bad Request: <function Home.web_client at 0x7f1fb58217b8>, /web: Function declared as capable of handling request of type 'http' but called with a request of type 'json'

My function is

def open_child(self):

return {

'type': 'ir.actions.act_window',

'name': 'Child',

'view_type': 'form',

'res_model': self._child_model,

'res_id': self._child_id,

'view_mode': 'form',

'views': [(False,'form')],

'target': 'current',

}

Can you help me with this please?

Did you applied @api.multi decorator in open_child function?

That decorator does not exist in V13, but I will try to debug around that to see what "self" actually is

Are you accessing through controller?.

@Vishnu Vanneri well it turned out to be a logic error on my side. The self._child_id and model were not set and I was hiding the button with the opposite logical rule. After using the button on the correct records it works fine. Thanks your your reply :)

Nejlepší odpověď

Hi Ali,

You can return action in your button and redirect it any form view you want,

for example refer this code


return {             'name': 'name',
                    'view_type': 'form',
                    'view_mode': 'form',
                    'view_id': [res_id],
                    'res_model': 'model_id',
                    'context': "{}",
                    'type': 'ir.actions.act_window',
                    'nodestroy': True,
                    'target': 'current',     
                     }
pass the view_id to load specific form. if you need a pop up window you can give target = 'new'.
Avatar
Zrušit
Autor

Thanks but what do you mean by inv_id? what does it represent ?

I've updated my answer, res_id is used when you need load a specific record in that model. You can pass model_id as res_id if you want to load a specific model

Related Posts Odpovědi Zobrazení Aktivita
2
úno 21
2561
1
dub 19
11637
1
čvn 24
2837
4
kvě 24
7405
1
dub 24
2315