Skip to content

Instantly share code, notes, and snippets.

@aannganyelne
aannganyelne / odoo_set_default_get_form_wizard.py
Created October 11, 2022 09:37
Odoo Set Default Get Form Wizard
@api.model
def default_get(self, fields):
res = super(PresentationWizard, self).default_get(fields)
crm_lead_id = self.env.context.get('active_id')
crm_lead = self.env['crm.lead'].browse(crm_lead_id)
if 'attachment_doc' in fields:
res.update({'attachment_doc': crm_lead.file_prospect})
return res
@aannganyelne
aannganyelne / odoo_force_save_readonly_field.md
Created October 11, 2022 08:12
Odoo Force Save Readonly Field

use attribute force_save="1" in view to save value of readonly field.

<field name="payment_type" readonly="1" force_save="1"/>

it will save value of payment_type field when onchange trigger.

@aannganyelne
aannganyelne / get_label_of_fields_select.py
Created October 11, 2022 06:22
Get Label Of fields.Select
dict(self._fields['your_field'].selection).get(self.your_field)
@aannganyelne
aannganyelne / odoo12_tz.py
Created September 27, 2022 20:36
Odoo 12 Add Timezone Field
...
date_tz = fields.Selection('_tz_get', string='Timezone', required=True,
default=lambda self: self.env.user.tz or 'UTC')
@api.model
def _tz_get(self):
return [(x, x) for x in pytz.all_timezones]
...
@aannganyelne
aannganyelne / select_all_table_name.sql
Created September 27, 2022 12:49
MySQL Select All Table Name
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'database_name'
ORDER BY table_name ASC;
@aannganyelne
aannganyelne / odoo_12_domain_by_parent.md
Created September 10, 2022 07:33
Odoo 12 Domain By Parent
[('x_partners','=',parent.partner_id)]
@aannganyelne
aannganyelne / odoo_12_field_with_custom_view.md
Created September 10, 2022 06:52
Odoo 12 Field With Custom View
<field name="journal_ids" context="{'tree_view_ref':'module_name.my_joural_tree_view'}" />
@aannganyelne
aannganyelne / odoo12_handling_one2many_field.md
Last active September 9, 2022 08:38
Odoo 12 Handling One2Many Field
(0, 0,  { values })    link to a new record that needs to be created with the given values dictionary
(1, ID, { values })    update the linked record with id = ID (write *values* on it)
(2, ID)                remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
(3, ID)                cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)
(4, ID)                link to existing record with id = ID (adds a relationship)
(4, [ID])                link to existing record with id = ID (adds a relationship)
(5)                    unlink all (like using (3,ID) for all linked records)
(6, 0, [IDs])          replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)
(5, 0, 0) unlink all
@aannganyelne
aannganyelne / uninstall_odoo12_module_from_command_line.md
Created September 8, 2022 14:54
Uninstall Odoo 12 Module From Command Line

Run from Terminal:

python3 odoo-bin shell -d mydb --addons-path=/your/addons/path

Run from python console:

self.env['ir.module.module'].search([('name', '=', 'crm')]).button_immediate_uninstall()
@aannganyelne
aannganyelne / add_value_to_selection_field.py
Last active September 6, 2022 02:01
Odoo 12 Add value to selection field
class ModelA(models.Model):
_name = "model.a"
alias_contact = fields.Selection([
('everyone', 'Everyone'),
('partners', 'Authenticated Partners'),
('followers', 'Followers only')], default='everyone',
string='Alias Contact Security', required=True,
help="Policy to post a message on the document using the mailgateway.\n"
"- everyone: everyone can post\n"