I need a button in tree view for all line. After clicking on the button I need get line id.
I'm trying, but not working:
*.xml
<button name="copy_line" class="text-right" icon="fa-files-o" type="object"/>
*.py
#api.multi
def copy_line(self):
print("Not come here!")
for r in self:
print(r.id)
object has no attribute 'copy_line'
To call the method on button click that record should be saved.
But in this case, Record was not saved so you are not able to call the method on button click.
Alternet way is, you can create a new line based on onchange or button in the footer and add self._cr.commit() to commit and raise ValidationError.
You define copy_line in the wrong model.
If your button is included inside a tree view defined for a One2Many field line_ids and that field is referencing object.line, you method copy_line should be created in that model.
For example:
line_ids = fields.One2Many('object.line', 'ref_id', string='Lines')
class ObjectLine(models.Model):
_name = 'object.line'
#api.multi
def copy_line(self):
print("Not come here!")
for r in self:
print(r.id)
Related
I'm creating a new sector on the settings page of my module, where I have a value and an update icon, which aims to update the field value when I click on the icon.
But when I call the function to execute the function, the page is reloaded and I never get the value, but the value is printed in the terminal with a logger, does anyone have any suggestions?
My XML code:
<button type="object" name="refresh_credits" class="btn-link" icon="fa-refresh"/>
<span class="btn-link">Credits</span>
<field name="new_credits"/>
My python code inside a class:
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
new_credits = fields.Integer()
def refresh_credits(self):
data_details_credits = self.env['show.credits'].content_credits_info()
_logger.info(self.env['show.credits'].content_credits_info()[4])
self.new_credits = data_details_credits[4]
You have to override set_values and get_values method to update the values in settings. We cannot directly update the values in general settings.
Below is the example:
def set_values(self):
super(ResConfigSettings, self).set_values()
self.env['ir.config_parameter'].sudo().set_param('MODULE_NAME.new_credits',
self.new_credits)
#api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
config = self.env['ir.config_parameter'].sudo()
config_key = config.get_param('MODULE_NAME.new_credits')
if config_zoom_key:
res.update(
field_name=config_key
)
return res
And also for better understanding, watch this video:
Add fields general settings
how can I hide the edit button when the state is "In Progress"
I tried doing ir.rule like this but it didn't work it only filter(domain) my treeview
I also tried to doing it in JavaScript but i can't find any odoo 11 sample
This can be done by inserting conditional CSS.
Frist add a html field with sanitize option set to False:
x_css = fields.Html(
string='CSS',
sanitize=False,
compute='_compute_css',
store=False,
)
Then add a compute method with your own dependances and conditions:
# Modify the "depends"
#api.depends('state_str_modify_me')
def _compute_css(self):
for application in self:
# Modify below condition
if application.state_str_modify_me= 'In Progress':
application.x_css = '<style>.o_form_button_edit {display: none !important;}</style>'
else:
application.x_css = False
Finally add it to the view:
<field name="x_css" invisible="1"/>
This might be a simple question.but,does any one know how to disable a button after clicking it in Odoo? Thanks for all your help.
Most of Odoo module use state for this kind of problem. the general idea of it that you must have a field and the button is displayed based on the value of that field.
Ex:
# in you model
bool_field = fields.Boolean('Same text', default=False)
In your view:
<button name="some_method"......... attrs="{'invisible': [('bool_field', '=', True)]}" />
...
...
...
<!-- keep the field invisible because i don't need the user to see
it, the value of this field is for technical purpuse -->
<field name="bool_field" invisible="1"/>
In your model:
#api.multi
def some_method(self):
# in this method i will make sure to change the value of the
# field to True so the button is not visible any more for user
self.bool_field = True
...
...
...
So if you all ready have a field that the button change it's value you can use it directly
or create a special field for this purpose.
I'm creating a new module where I want to put a button in kanban view of Contact screen. When any user click on that button I need active_id of the selected contact. It is possible to get for tree and form view but I don't know how to do that for kanban view.
Can anyone please help here?
Thanks
You need to use the contex dictionary variably for this purpose ,
If you click on the bu
<button string="Click Me" type="object" name="my_func" context="{'active' : active_id}" />
Method:
def my_func(self, cr, uid, ids, context={}):
# do stuff using the info passed in the context variable...
Here in my view i am using like this for deletion of record
<?php echo CHtml::link('Delete',"#", array("submit"=>array('delete', 'id'=>$data->id), 'confirm' => 'Are you sure?','class'=>'btn btn-danger icon_delete'));?>
if i am pressing the delete button it is generating the alert box then if i click ok no action deletion is perform that means (it is not going to the controller) can any one help
controller
public function actionDelete($id)
{
$this->loadModel($id)->delete();
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('view'));
}
The code for deleting the record is fine only. I think you should check controller, may be you have not defined the action 'delete'. Just check it.
I think you should change the code in the delete action as follow pattern:
$model = Your_modelClass name::model()->findByPk($id);
$model->delete();
$this->redirect(array('list'));
Here Your_modelClass name should be same as the model(or table, from where you want to delete the data). But make sure that you have created model also for your table.
And the 3rd line is optional, You can use it if want to redirect to any page(here list page).
Think it will help.