Thursday, August 24, 2023

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


Tuesday, October 18, 2022

domain many2many fields in odoo 14


In this blog we will explain how to set domain many2many fields in Odoo 14

So let us say that we have four models (restaurants model, food category model, food model and orders model) the restaurant contains many categories, the category can contain many foods , as bellow 

 

class restaurants(models.Model):
    _name = "res.restaurants"
    category_ids = fields.Many2many('res.category', string="categories")
 

 

class Foods(models.Model):
    _name = "res.foods"
    category_id = fields.Many2one('res.category', string="Category")


class Orders(models.Model):
    _name = "res.orders"
    restaurant_id = fields.Many2one('res.restaurants', string="Restaurant")
    foods_ids = fields.Many2many('res.foods', string="Foods")


To create order the user must select the restaurant then select foods , but the system must show the food with category_id in  order.restaurant_id.category_ids

So we can do it by creating function in order model called on-change restaurant_id and this function will set the domain for foods , just as bellow

 

@api.onchange('restaurant_id')
    def _set_foods_domain(self):
        res = {}
        if self.restaurant_id:
            ids_lis = []
    
        food_ids = self.env['res.foods'].search([])
            for food_id in self.category_ids:
                if food_id.id in self.restaurant_id.mapped("category_ids").ids:
                    ids_lis.append(food_id.id)
            res['domain'] = {'food_ids': [('id', 'in', ids_lis)]}
        return res

ValueError: odoo.addons.web.__spec__ is None

 

I was trying to install Odoo 15 in Ubuntu 18.4, but when I was trying to run the odoo server I faced this error

 ValueError: odoo.addons.web.__spec__ is None

and to fix it just I run the command bellow 

sudo pip3 install Jinja2==2.10.1

 

amount in words in odoo 14

 


In this blog we will crate function to convert number amount to words in Odoo 14 

so the input of this function will be (amount as numbers, language code), and the output will be the amount as words , now let us create the function with the name amount_as_text()

def amount_as_text(self,amount,lang):
        text = _(str(self.currency_id.with_context(lang=lang).amount_to_text(amount)))
        return text

 

We can call the function in report templates with Arabic language as bellow

<t t-set="amount_text" t-value="o.amount_as_text(o.amount_total,'ar_001')"/>

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