I have created a button in jobs by using inheritance in (hr.recruitment form view) , how could I open another module("Resumes and Letters -sub menu in Human Resource " ) form_view during buttons click event is done.my aim is that I just want open that form when this click event done.
Is it possible to solve? Need help please
yes, it is possible to open another window. you have to do like this.
#api.multi
def button_method(self):
return {
'type': 'ir.actions.act_window',
'name': 'form name',
'res_model': 'object name',
'res_id': id ,
'view_type': 'form',
'view_mode': 'form',
'target' : 'new',
}
but it is possible when record save. if you want to open wizard before save record you have to code in js like this.
in js file:
openerp.module_name = function(instance) {
var QWeb = openerp.web.qweb;
_t = instance.web._t;
instance.web.View.include({
load_view: function(context) {
var self = this;
var view_loaded_def;
$('#oe_linking_e').click(this.on_preview_view_button);
//this is button class which call method for open your form.
return self._super(context);
},
//method which open form
on_preview_view_button: function(e){
e.preventDefault();
this.do_action({
name: _t("View name"),
type: "ir.actions.act_window",
res_model: "object",
domain : [],
views: [[false, "list"],[false, "tree"]],
target: 'new',
context: {},
view_type : 'list',
view_mode : 'list'
});
}
},
});
};
in xml file add button and give id="oe_linking_e" whatever you give in js code.
you can return form in this manner.
In your button method return this dictionary. It will open the target form in a pop-up window ,
def button_method(...........):
return {
'name': _(some name),
'view_type': 'form',
"view_mode": 'form',
'res_model': model-name,
'type': 'ir.actions.act_window',
'target': 'new',
}
you can pass <br> 'res_id': target_id in the above dictionary to open a particular record
Related
I'm trying to update the body field from the payrun_chatter_log() but it won't update. any idea on how to do this? This is what I did:
def payrun_chatter_log(self):
subtype = self.env['mail.message.subtype'].search([('id','=', '2')])
vals = {
'date': fields.datetime.now(),
'email_from': self.env.user.email_formatted,
'author_id': self.env.user.id,
'message_type': 'notification',
'subtype_id': subtype.id,
'is_internal': True,
'model': 'custom.module',
'res_id': self.id,
'body': 'Test'
}
self.env['mail.message'].create(vals)
def custom_button(self):
chatter = self.env['mail.message'].search([('res_id', '=', self.id)])
message = 'Custom Message here'
chatter.update({'body': message})
return super(CustomModule, self).custom_button()
Your below line of code in custom_button will return multi record because res_id will be repeated for more than one model
chatter = self.env['mail.message'].search([('res_id', '=', self.id)])
You need to add the model to search:
chatter = self.env['mail.message'].search([('model', '=', self._name), ('res_id', '=', self.id)])
The message body should be updated, you need to refresh the page to see the changes.
Try to return the following client action:
return {
'type': 'ir.actions.client',
'tag': 'reload',
}
The chatter has an One2many relation to mail.message model. Your function will update all messages
I've created a wiz to get the product which are in the field "catagory_select" please look the code below:
class CategorySelect(models.TransientModel):
_name = 'product.group'
category_select = fields.Many2many('product.category', string='Category')
def start_search_product(self):
wiz_form = self.env.ref('product_filter.get_products_form_all', False)
for rec in self.category_select:
product_res = self.env['product.product'].search([('categ_id', '=', rec.ids)])
print('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^', product_res)
return {
'type': 'ir.actions.act_window',
'name': "Product Filtered",
'res_model': 'product.selection',
'target': 'new',
'view_id': wiz_form.id,
'view_mode': 'form',
}
}
here what i done is i have created a method which returns a wizard but i am not getting a way that how shoud i pass the "product_res" to a many2many field in another wizard which is called the return menu.
"Any help will be appreciated"
You can set on context with default fields set with your values.
ctx = self._context.copy()
ctx.update({'default_m2m_fields': [(6, 0, IDS)]}) # on new wizard the m2m fields set with default on context
You can pass the product_res to another wizard using context
1/ Update your start_search_product to pass the product_res ids:
def start_search_product(self):
product_res_ids = [p.id for p in product_res]
context = {'product_ids': product_res_ids}
return {
'type': 'ir.actions.act_window',
'name': "Product Filtered",
'res_model': 'product.selection',
'target': 'new',
'view_id': wiz_form.id,
'view_mode': 'form',
'context': context,
}
}
2/ Get the product ids in function default_get of ProductSelection wizard:
product_ids = fields.Many2many('product.product', 'Products')
#api.model
def default_get(self, default_fields):
res = super(ProductSelection, self).default_get(default_fields)
product_ids = self._context.get('product_ids')
res.update({'product_ids': [(6, 0, product_ids)]})
return res
currently when I DELETE an item which is being referenced by. I can still delete it. I would like to prohibit this giving an error. I couldn't find anything on http://docs.python-eve.org or google.
say I have the following two schemas:
foos = {
...
'schema' : {
...,
'bar': {
'type': 'string',
'required': true,
'data_relation': {
'resource': 'bars',
'field': 'name',
'embeddable': True
}
}
}
}
bars = {
...
'schema' : {
...,
'name': {
'type': 'string',
'required': true,
}
}
}
if I delete now an item from bars which is still being referenced by >=1 items in foos. How could I return an error instead of deleting the bars item?
Would i need to write a
on_delete_item
def event(resource_name, item)
and how? Any help is appreciated.
I am trying to make a response card in amazon lex to give out a response card that has a button that leads to another website. Below is the code that I have used in aws lambda python. I have published the chatbot on facebook messenger. But whenever I select the button in fb messenger, the link in the button does not seem to bring me to the website. Is there any way to make the response card button turn into hyperlink button?
def location(intent_request):
session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
return {
'dialogAction': {
'type': 'Close',
'fulfillmentState': 'Fulfilled',
'message': {
'contentType': 'PlainText',
'content': 'Here is a map'
},
'responseCard': {
'version': '17',
'contentType': 'application/vnd.amazonaws.card.generic',
'genericAttachments': [
{
'title': 'Here is a list of hospitals',
'subTitle': 'Below is a map',
"buttons":[
{
"text":"Show Google Maps",
"value":"https://www.google.com/maps/search/?api=1&query=nearby+hospitals"
}
]
}
]
}
}
}
As of now you cannot do that using the buttons. The buttons have two parameters text and value. When you click on a button, the value of button is sent to the servers and the text is appended to the chat. So it will just send the value back to Lex but cannot open function as hyperlink.
However you can use image in the response card for the same functionality. imageUrl is the url of the image to be displayed, and attachmentLinkUrl is the url which you want to open. So I would suggest you to remove buttons and use an image of map to be shown and provide your hyperlink in attachmentLinkUrl.
Also, if you want to show multiple hyperlink, you can show multiple cards (upto 10) in a single responseCard.
Below is a sample code:
return {
'dialogAction': {
'type': 'Close',
'fulfillmentState': 'Fulfilled',
'message': {
'contentType': 'PlainText',
'content': message
},
'responseCard': {
'version': '0',
'contentType': 'application/vnd.amazonaws.card.generic',
'genericAttachments': [
{
'title': 'Here is a list of hospitals',
'subTitle': 'Below is a map',
'attachmentLinkUrl': 'https://www.google.com/maps/search/?api=1&query=nearby+hospitals',
'imageUrl': 'https://images.sftcdn.net/images/t_optimized,f_auto/p/95612986-96d5-11e6-af7c-00163ec9f5fa/3771854867/google-maps-screenshot.png'
},
{
'title': 'Here is a list of medical shops',
'subTitle': 'Below is a map',
'attachmentLinkUrl': 'https://www.google.com/maps/search/?api=1&query=nearby+medical+shops',
'imageUrl': 'https://images.sftcdn.net/images/t_optimized,f_auto/p/95612986-96d5-11e6-af7c-00163ec9f5fa/3771854867/google-maps-screenshot.png'
}
]
}
}
}
You can check this as well for details about response cards.
Hope it helps.
I am writing a method that it first will retrieve the current context from the model then using context.update() to add on new values for the context. I also tried to use the current method self.with_context() but still no success since the context values seem frozen and could not be passed in. I read online from some source that there is a way to override the name_get(). But the source only briefly reference, there would be no clear instruction so that i can follow. I am new in Odoo and the problem between v7 and v8 its killing me. Please help me revise my following source code:
def get_print_report(self):
domain = [('effective_date', '>=', self.from_date),
('effective_date', '<=', self.to_date),
('employee_id', 'in', self.employee_ids.ids),
('department_id', '=', self.department_id.id),
('job_id', '=', self.job_id.id)]
list_view = self.env.ref(
'trainingwagekp.payroll_wage_hist_wizard_tree_view')
context = self._context.copy()
if context is None:
context = {}
if context.get('order_by', False):
context.update({'default_order': self.order_by + ' desc'})
self.with_context(context)
print '===============', self._context
return{'name': 'Wage History Report',
'view_type': 'form',
'view_mode': 'tree',
'view_id': list_view.id,
'res_model': 'trobz.payroll.wage.history',
'type': 'ir.actions.act_window',
'context': context,
'domain': domain,
}
Please also let me know which is the best way to modify context in Odoo 8. Thanks
You already passing new context in return. Just remove self.with_context(context) line. As per below code.
def get_print_report(self):
domain = [('effective_date', '>=', self.from_date),
('effective_date', '<=', self.to_date),
('employee_id', 'in', self.employee_ids.ids),
('department_id', '=', self.department_id.id),
('job_id', '=', self.job_id.id)]
list_view = self.env.ref(
'trainingwagekp.payroll_wage_hist_wizard_tree_view')
context = self._context.copy()
if context is None:
context = {}
if context.get('order_by', False):
context.update({'default_order': self.order_by + ' desc'})
return{'name': 'Wage History Report',
'view_type': 'form',
'view_mode': 'tree',
'view_id': list_view.id,
'res_model': 'trobz.payroll.wage.history',
'type': 'ir.actions.act_window',
'context': context,
'domain': domain,
}
I think if you check the type of context, you will find that it is a frozen dict. You shall change it to a dict context = dict(self._context) then do all the alteration you need then turn it back into a frozen dict and give