Thursday, September 28, 2023

Table rows scroll in odoo

 

In this blog we will explain how to create table rows scroll in odoo web view so 

First : create the table as bellow
    <table class="tb_00">
        <tr class="tr_00">
            <th class="td_001">
                  <b class="th_01">
                       Date
                  </b>
            </th>
            <th class="td_002">
                  <b class="th_01">
                       Name
                  </b>
            </th>
            <th class="td_003">
                  <b class="th_01">
                        Manager
                  </b>
            </th>
            <th class="td_004">
                   <b class="th_01">
                         Description
                   </b>
            </th>
         </tr>
   </table>
   <br></br>
        <div class="scroll">
        <table class="tb_01">
            <t t-foreach="all_model_main_data" t-as="model">
                <tr class="tr_02">
                    <td class="td_01">
                        <span t-esc="model['model_date']" class="model_date_01"/>
                    </td>
                    <td class="td_02">
                        <t t-set="allowed" t-value="0"/>
                        <t t-if="request.env.user.has_group('canv_models_website.model_details_puser_r_per')">
                            <t t-set="allowed" t-value="1"/>
                        </t>
                        <t t-if="request.env.user.has_group('canv_models_website.model_details_puser_rw_per')">
                            <t t-set="allowed" t-value="1"/>
                        </t>
                        <t t-if="allowed == 1">
                            <a t-att-href="model['model_id'].get_portal_url()">
                                <span t-esc="model['model_name']" class="model_name_02"/>
                            </a>
                        </t>
                        <t t-if="allowed == 0">
                            <span t-esc="model['model_name']" class="model_name_02"/>
                        </t>
                    </td>
                    <td class="td_03">
                        <span t-esc="model['supervisor_name']" class="auct_visor_name_02"/>
                    </td>
                    <td class="td_04">
                        <span t-esc="model['description']" class="model_desc_02"/>
                    </td>
                </tr>
            </t>
        </table>
    </div>

Second : ass the css styles as bellow 

    .tb_00{
      width:100%;
    }
    .tb_01{
      width:100%;
    }
    .scroll{
      max-height: 500px;
      overflow: auto;
      margin-bottom:30px;
    }
    .tr_00{
      width: 100%;
      font-size: 17px;
    }
    .td_001{
      width: 15%;
      font-family: Amiri-Regular;
      font-size: 17px;
    }
    .td_002{
      width: 20%;
      font-family: Amiri-Regular;
      font-size: 17px;
    }
    .td_003{
      width: 20%;
      font-family: Amiri-Regular;
      font-size: 17px;
    }
    .td_004{
      width: 45%;
      font-family: Amiri-Regular;
      font-size: 17px;
    }
    .tr_01{
      width: 100%;
      font-size: 17px;
    }
    .td_01{
      width: 15%;
      font-family: Amiri-Regular;
      font-size: 17px;
    }
    .td_02{
      width: 20%;
      font-family: Amiri-Regular;
      font-size: 17px;
    }
    .td_03{
      width: 20%;
      font-family: Amiri-Regular;
      font-size: 17px;
    }
    .td_04{
      width: 45%;
      font-family: Amiri-Regular;
      font-size: 17px;
    }
    .th_01{
      font-family: Amiri-Regular;
      font-size: 20px;
    }
    .model_desc_02{
      font-family: Amiri-Regular;
      font-size: 17px;
    }
    .tr_02{
      margin-top: 5px;
      width: 100%;
    }

 


Thursday, September 14, 2023

portal view for model in odoo

In this blog we will define the steps to create portal view for model in odoo

So

Step 1 : inherit "portal.mixin" model inside your model as bellow 

    class ClassName(models.Model):
        _name = "model.name"
        _inherit = ['model.name','portal.mixin']
        //for old models

    class ClassName(models.Model):
        _name = "model.name"
        _inherit = ['model.name','portal.mixin']
        //for new models

Step 2 : set value for access_url field inside your model by inheriting the get_portal_url() function as bellow 

    def _compute_access_url(self):
        super(productTemplate, self)._compute_access_url()
        for rec in self:
            rec.access_url = '/model/name/%s' % rec.id

Step 3 : add another function to define the portal url for each record from your model as bellow

    def get_portal_url(self, suffix=None, report_type=None, download=None, query_string=None, anchor=None, view_name=None):
        self.ensure_one()
        url = self.access_url + '%s?access_token=%s%s%s%s%s' % (
            suffix if suffix else '',
            self._portal_ensure_token(),
            '&report_type=%s' % report_type if report_type else '',
            '&download=true' if download else '',
            query_string if query_string else '',
            '#%s' % anchor if anchor else ''
        )
        return url

Step 4 : create your controller which must inherit the "CustomerPortal" controller as bellow 

    # -*- coding: utf-8 -*-

    from odoo import http, _
    from odoo.exceptions import AccessError, MissingError
    from odoo.http import request
    from odoo.addons.portal.controllers.portal import CustomerPortal, pager as               portal_pager
    from odoo.tools import groupby as groupbyelem
    from odoo.osv.expression import OR

    class CustomerPortal(CustomerPortal):

        @http.route(['/model/name/<int:record_id>'], type='http', auth="public", website=True)
        def my_model_portal(self, record_id=None, access_token=None, **kw):
            try:
                model_name_sudo = self._document_check_access('model.name', record_id, access_token)
            except (AccessError, MissingError):
               return request.redirect('/my')
            values = {}
            return request.render("module_name.template_id", values)

Step 5 : create the template view as bellow

    <?xml version="1.0" encoding="UTF-8"?>
    <odoo>
        <template id="template_id" name="Template Name">
            <t t-call="website.layout">
                <form action='/form/name'>
                </form>
            </t>
        </template>
    </odoo>

Step 6 : call the portal view for specific model record as bellow

    <a t-att-href="record_id.get_portal_url()"></a>

python function to return multi views in odoo

In this blog we will explain how to create python function to return multi views in odoo for one model

For an example created custom tree view , custom form view and custom kanban view for the "res.partner" model with the bellow ids

tree view id = "res_partner_custom_tree_view"
form view id = "res_partner_custom_form_view"
kanban view id = "res_partner_custom_kanban_view"

and we created smart button on another model view which must call python function to open "res.partner" model with the previous views , so this function can be just like bellow  

def display_partners(self):
        tree_view_id = self.env.ref('module_name.res_partner_custom_tree_view')
        form_view_id = self.env.ref('module_name.res_partner_custom_form_view')
        kanban_view_id = self.env.ref('module_name.res_partner_custom_kanban_view')

        return {
            'type': 'ir.actions.act_window',
            'name': "string",
            'res_model': 'res.partner',
            'domain': [('id', 'in',self.get_partner_ids().ids)],
            'view_mode': 'tree,form',
            'views':[(tree_view_id.id,'tree'),(form_view_id.id,'form'),(,(form_view_id.id,'form').id,'kanban')],
            'target': 'current',
        }

Thursday, August 31, 2023

specific view for many2one field in odoo

 


In this blog we will explain how to add specific view for many2one field in odoo 

so to explain that let us say we created custom form view for the product unit of measure and we want to open it from uom_id field in product view just like at the image , so we must inherit the product from view , then add context attribute to uom_id field , just like bellow 

<xpath expr="//field[@name='uom_id']" position="attributes">
     <attribute name="context">
          {'form_view_ref':'custom_module_name.custom_form_view_id'}
     </attribute>
</xpath>


default view filter in odoo

 

 

In the blog we will explain how to add default view filter in odoo , just like the apps default filter in odoo apps view

Firstly :  inside the search view you must define your default filter with the right domain , for example let us say we want to add default filter in product view to display products that can be sold only , just as bellow

<filter name="can_be_sold" string="Can Be Sold" domain="[('sale_ok', '=', ture)]"/>

Secondly : pass you filter to view you want using context , just as bellow

<field name="context">{'search_default_can_be_sold':1}</field>

Thursday, August 24, 2023

ModuleNotFoundError: No module named 'psutil'

 
 I got this problem (ModuleNotFoundError: No module named 'psutil') when I was trying to run Odoo so I run the command bellow in-order to fix it
python -m pip install psutil

How to set postgresql password

 

In this blog we will explain How to set postgresql password

In order to set password for postgresql you have to open the terminal and run the comands bellow 

First :

    sudo -u postgres psql

Second

    \password postgres

Third : it will ask you to enter password then to enter it again , just like in         the image bellow 


 

 

Odoo Invoice Qr code issues

There are two main issues must of us facing with the QR code in Odoo invoice & these issues are 1/ QR code displayed as broken image w...