Skip to content

Instantly share code, notes, and snippets.

@sehrishnaz
sehrishnaz / progressbar_widget_odoo.py
Created May 12, 2022 08:40
How to use and implement ProgressBar widget in Odoo
class gym_body_parts_config(models.Model):
_name = 'gym.body.parts.config'
sequence = fields.Integer(default=10,help="Gives the sequence order when displaying a list of records.")
name = fields.Char(string="Name", required=True)
progress_bar = fields.Integer(compute='_compute_progress_bar')
@api.depends('name','sequence')
def _compute_progress_bar(self):
for u in self:
@sehrishnaz
sehrishnaz / remove_fold_delete_add_new_column_from_task_odoo.xml
Created May 10, 2022 05:30
Remove Fold, Edit Stage, Delete, Archive All and Add New Column From Task Kanban View
<record id="inherit_view_task_kanban" model="ir.ui.view">
<field name="name">inherit.project.task.kanban</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_kanban" />
<field name="arch" type="xml">
<xpath expr="//kanban" position="attributes">
<attribute name="group_create">0</attribute>
<attribute name="group_delete">0</attribute>
<attribute name="group_edit">0</attribute>
<attribute name="archivable">0</attribute>
@sehrishnaz
sehrishnaz / inherit_task_form_view.xml
Created May 9, 2022 06:27
How to inherit task form view in Odoo
<record id="inherit_project_task_view_form" model="ir.ui.view">
<field name="name">project.task.view.inherit.form</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project_enterprise.project_task_view_form"/>
<field name="arch" type="xml">
<xpath expr="//label[@for='planned_date_begin']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//div[hasclass('w-100')]" position="attributes">
<attribute name="invisible">1</attribute>
@sehrishnaz
sehrishnaz / inherit_task_tree_view.xml
Created May 9, 2022 06:26
How to inherit task tree view in Odoo
<!--Inherit task tree view -->
<record id="inherit_project_task_tree" model="ir.ui.view">
<field name="name">project.task.tree.inherit</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_tree2"/>
<field name="arch" type="xml">
<xpath expr="//tree" position="attributes">
<attribute name="delete">1</attribute>
</xpath>
@sehrishnaz
sehrishnaz / inherit_task_search_view.xml
Created May 9, 2022 06:25
How to inherit task search view in Odoo
<!--Inherit task search view -->
<record id="inherit_task_search_view" model="ir.ui.view">
<field name="name">project.task.search.form</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_search_form"/>
<field name="arch" type="xml">
<!--Below example shows how to visible invisible fields in search view -->
<xpath expr="//search/field[@name='name']" position="attributes">
<attribute name="string">You can change string or label of a field</attribute>
@sehrishnaz
sehrishnaz / inherit_project_search_view.xml
Created May 9, 2022 06:24
How to inherit project and task form, tree and search view in Odoo
<record id="inherited_view_project_project_filter" model="ir.ui.view">
<field name="name">inherited.project.project.select</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_project_filter"/>
<field name="arch" type="xml">
<!--Below example shows how to visible invisible fields in search view -->
<xpath expr="//search/field[@name='user_id']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
@sehrishnaz
sehrishnaz / duplicate_records_on_button_click_odoo.py
Last active April 29, 2022 05:20
How to use .copy() and .copy_data() function in Odoo15
class your_model(models.Model):
_name = "your.model"
def copy_data(self, default=None):
defaults = super().copy_data(default=default)
if 'from_duplicate' in self.env.context and self.env.context.get('from_duplicate'):
return [{k: v for k, v in default.items()} for default in defaults]
else:
return [{k: v for k, v in default.items() if k in self.SELF_READABLE_FIELDS} for default in defaults]
@sehrishnaz
sehrishnaz / override_builtin_button_method_odoo.py
Created March 3, 2022 05:48
Override Built-in Modules Button Method in Odoo
class account_voucher(models.Model):
_inherit = 'account.voucher'
# By using old api
def button_proforma_voucher(self,cr, uid, ids, context=None):
obj = super(account_voucher, self).button_proforma_voucher(cr, uid, ids, context=None)
# add your custom functionality here
return obj
# By using new api
@sehrishnaz
sehrishnaz / override_builtin_button_method_odoo.py
Created March 3, 2022 05:46
Override Built-in Modules Button Method in Odoo
class account_voucher(models.Model):
_name = 'account.voucher'
def button_proforma_voucher(self, cr, uid, ids, context=None):
self.signal_workflow(cr, uid, ids, 'proforma_voucher')
return {'type': 'ir.actions.act_window_close'}
@sehrishnaz
sehrishnaz / create_django_dynamic_sitemap.py
Created February 10, 2022 08:07
Create Dynamic Sitemap in Django Using Multiple Models Slug
from django.contrib.sitemaps import Sitemap
from .models import Your_Model_Name
class MySitemap(Sitemap):
changefreq = "weekly"
priority = 0.8
protocol = 'http'
def items(self):