Thursday, August 24, 2023

multi views for one model in odoo

To explain how to create multi views for one model in Odoo

let us say that we create estate module which is depends on the project standard module and we want to store the estate project data inside the 'project.project' model from project module but it has different fields and view than the standard projects so 

first : we will inherit the "project.project" model and add selection field which we will use as domain inside the actions views 

# -*- coding: utf-8 -*-
from odoo import fields, models, api, _

class projectProject(models.Model):
    _name = 'project.project'
    _inherit = ['project.project','mail.thread']
    _description = 'Project models inherit'

    project_type = fields.Selection([
        ('project','Project'),
        ('estate_project','Estate Project')],
        default='project',
        string="Type"
    )

 

second : we will over write the standard projects action view to add domain in-order to display the records with "project_type = "project"

<record id="project.open_view_project_all" model="ir.actions.act_window">
            <field name="name">Projects</field>
            <field name="res_model">project.project</field>
            <field name="domain">[('project_type','=','project')]</field>
            <field name="context">{'default_project_type':'project'}</field>
            <field name="view_mode">kanban,form</field>
            <field name="view_id" ref="project.view_project_kanban"/>
            <field name="search_view_id" ref="project.view_project_project_filter"/>
            <field name="target">main</field>
            <field name="help" type="html">
                <p class="o_view_nocontent_smiling_face">
                    No projects found. Let's create one!
                </p><p>
                    Projects regroup tasks on the same topic and each have their own dashboard.
                </p>
            </field>
        </record> 


Third : we will create the estate project own views as bellow 

<record id="estate_project_form_view" model="ir.ui.view">
            <field name="name">auction.form</field>
            <field name="model">project.project</field>
            <field name="arch" type="xml">
                <form string="Estate Project">
                </form>
            </field>
        </record>

        <record id="estate_project_tree_view" model="ir.ui.view">
            <field name="name">estate.project.tree</field>
            <field name="model">project.project</field>
            <field name="arch" type="xml">
                <tree string="Estate Projects">
                </tree>
            </field>
        </record>

        <record model="ir.ui.view" id="estate_project_kanban_view">
            <field name="name">project.project.kanban</field>
            <field name="model">project.project</field>
            <field name="arch" type="xml">
                <kanban>
                </kanban>
            </field>
        </record>

        <record id="estate_project_act_window" model="ir.actions.act_window">
            <field name="name">Estate Projects</field>
            <field name="res_model">project.project</field>
            <field name="view_mode">kanban,tree,form</field>
            <field name="view_ids" eval="[(5, 0, 0),
                (0, 0, {'view_mode': 'tree', 'view_id': ref('estate_project_tree_view')}),
                (0, 0, {'view_mode': 'kanban', 'view_id': ref('estate_project_kanban_view')}),
                (0, 0, {'view_mode': 'form', 'view_id': ref('estate_project_form_view')})]"/>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">
                    There is no examples click here to add new Auction.
                </p>
            </field>
            <field name="domain">[('project_type','=','estate_project')]</field>
            <field name="context">{'default_project_type':'estate_project'}</field>
        </record>

        <menuitem
            name="Estate Projects"
            id="estate_project_menu"
            action="estate_project_act_window"
        />


ImportError: cannot import name 'utils'


 

     if you face this problem (ImportError: cannot import name 'utils') when you try to run odoo , you can fix it by using the commands bellow

pip install checkov

pip3 install checkov

python3.9 -m pip install checkov // for specific python version "3.9 as an example"

send chat message in odoo 16

In this blog we will explain how to send chat message in odoo 16 programmatically

#Sending direct chatting message in odoo mail , means send message in private channel that has "chat" type , so we have to create private channel with "chat"type for the user that we want to send him a message just as bellow

def action_send_chat_message(self,partner_id):
        odoobot = self.env.ref('base.partner_root')
        channel_name = odoobot.name+"/"+partner_id.name[0]+partner_id.name[1]+partner_id.name[2]+partner_id.name[3]+partner_id.name[4]+str(partner_id.id)
        mail_channel_id = self.env['mail.channel'].search([('name','=',channel_name)])
        if not mail_channel_id:
            mail_channel_id = self.env['mail.channel'].create({
                    'name': channel_name,
                    'channel_type':'chat',
                    'channel_partner_ids': [(4,odoobot.id),(4,partner_id.id)]
                })
        self.env['mail.message'].create({
            'email_from': self.env.user.partner_id.email,
            'author_id': self.env.user.partner_id.id,
            'model': 'mail.channel',
            'message_type':'comment',
            'subtype_id': self.env.ref('mail.mt_comment').id,
            'subject': _('Direct Chatting'),
            'body': 'This is a private direct message',
            'res_id':mail_channel_id.id,
            'partner_ids': [(4, partner_id.id)]
        })

#note : we must pass value for "channel_ids" field in odoo 14

 

RTL with odoo 14

To fix the problem of RTL with odoo 14 in Ubuntu , you have to open the terminal then run the commands bellow one by one

  • sudo apt install nodejs
  • sudo apt install npm
  • sudo apt  install curl
  • curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh  
  • nano nodesource_setup.sh
  • sudo bash nodesource_setup.sh
  • sudo apt install nodejs
  • sudo apt install build-essential
  • sudo npm install -g rtlcss

Monday, August 21, 2023

how to send email programmatically in odoo

In this blog we will explain how to send email programmatically in odoo

First : we have to create our email template just as bellow  

<?xml version="1.0" ?>
<odoo>
    <data noupdate="1">
        <record id="email_template_id" model="mail.template">
            <field name="name">Custom_Email_Template</field>
            <field name="model_id" ref="module_name.model_your_model_name"/>
            <field name="email_from">iap@odoo.com</field>
            <field name="partner_to">${object.partner_id.id}</field>
            <field name="subject">${object.company_id.name}</field>
            <field name="body_html" type="html">
                <div style="margin: 0px; padding: 0px;">
                    Email body
                </div>
            </field>
        </record>
    </data>
</odoo>

Second : create the python function that will send the email

def action_mail_send(self):
        template_id = self.env['mail.template'].search([('name', '=', 'Custom_Email_Template')])

        ctx = {
            'default_model': 'model_name',
            'default_res_id': record_id,
            'default_use_template': bool(template_id.id),
            'default_template_id': template_id.id,
            'default_composition_mode': 'comment',
            'mark_so_as_sent': True,
            'custom_layout': "mail.mail_notification_paynow",
            'proforma': self.env.context.get('proforma', False),
            'force_email': True,
            'default_check_value': True,
            'default_is_log': True,
        }
        self.env['mail.compose.message'].with_context()._action_send_mail()

 

The above code works for odoo 16 & 15 but in case we are work on odoo 14 we can use the code bellow

template_id = self.env.ref('hr_recruitment.email_template_data_applicant_congratulations')
        template_id.send_mail(self.id, force_send=True)

Tuesday, July 25, 2023

check report orientation in odoo

In this blog we will explain how to check report orientation in odoo programmatically 

First : check if report orientation = Portrait

<t t-if="env['ir.actions.report'].search([('report_name', '=',xmlid)]).paperformat_id.orientation == 'Portrait'">
 

Second : check if report orientation = Landscape

<t t-if="env['ir.actions.report'].search([('report_name', '=', xmlid)]).paperformat_id.orientation == 'Landscape'">

Saturday, June 17, 2023

Reports Custom Header & Footer Odoo App

Reports Custom Header & Footer

This is an Odoo module gives users 4 options to set header or footer or both over company and these options are


(1) Default Odoo's Header & Footer

(2) Image as Header & Image as Footer

(3) Text in the middle of the line as Header or Footer

(4) Xml Template as Header & Xml Template as Footer



Module Configuration

After installing the module go to Setting/Users & Companies/Companies and select your company , you will fine new page with the name
Reports Header and Footer , here you can set the type of header or footer
(default, Text , Image or XML Template)
fater that you have to click on apply button and to will set the selected
Header and Footer for all report of this company

/



Use Images as Header or Footer

form Header Type field select image option , it will display
new field by the name Header Image you have to add your image here
in order to use it as report's header over this company reports
and you have to follow repeat these steps to add image as Footer too

/



Use Text as Header or Footer

form Header Type field select Text option , it will display
new field by the name Header Text you have to add your Text here
in order to use it as report's header over this company reports
and you have to follow repeat these steps to add Text as Footer too

/



Use XML Template as Header or Footer

form Header Type field select xml Header option , it will display
new field by the name Header Template you have to choose one of the created xml header templates
in order to use it as report's header over this company reports
and you have to follow repeat these steps to add xml template as Footer too




! You have to click on apply button after making ang change on the Header anf Footer Configuration





XML Templates

This module allows you to create new xml templates to use on of them as
default header or footer
also it provides 8 Demo Templates
to manage templats go to Setting > Technical > Header/Footer Templates menu

/



Demo XML Templates

On the xml templates list view you will find 4 Header XML Templates
and 4 Footer XML Templates on draft state
and you must confirm each template to be able to set it
as default Header or default footer

/



Create New XML Template

To create your own templates , you have to click on create button
select the type of your template where it's a header template
or footer template
then you have to add the xml template code , click on save button
and confirm your template




The Header XML demo Template


header / 0001
header / 0002
header / 0003
header / 0004






The Footer XML demo Template

footer / 0005
footer / 0006
footer / 0007
footer / 0008







Watch Demo

Donwload The module


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...