Thursday, 23 November 2023

Odoo 17 New Features

 

Odoo 17 new Features

1) Duplicate  multiple records from List view.

Please have look below screenshots

first you need to select records then click in action you can see duplicate options is there.

2) You also create invoices without click in action. In odoo17 this version they provide new button for create invoices




3) Smart button will move on top middle

Please have look below customer form.



4)  Products can select in the sale order line to the catalog view itself
  • List view you may also select easily with the keyboard using the Shift + down arrow in the list view




Friday, 1 September 2023

How to open wizard from action in Odoo

 In Odoo, to open a wizard from an action, you need to define and configure the action correctly.

Follow the steps:

1) Create Wizard Model

class MyCustomWizard(models.TransientModel): _name = 'my.custom.wizard' _description = 'My Custom Wizard Description'

# Define fields for your wizard here product_id = fields.Many2many('product.product', string='Product') product_old_price = fields.Float(string='Product Old Price') internal_ref = fields.Char(string='Product')

2) Create Wizard View

<record id="wizard_id" model="ir.ui.view">
<field name="name">confirm.wizard.form</field>
<field name="model">my.custom.wizard</field>
<field name="arch" type="xml">
<form>
               # Define fields for your wizard here
        </form>
</field>
</record>

3) Create Server action from where you need to define action


<record id="custom_product_action_server" model="ir.actions.server">
<field name="name">Open Wizard</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="product.model_product_product"/>
<field name="binding_model_id" ref="product.model_product_product"/>
<field name="state">code</field>
<field name="code">
action = model.action_open_wizard()
</field>
</record>

4) Now Define server action function in Model
def action_open_wizard(self):
product_product_ids = self.env['product.product'].browse(self._context.get('active_ids', False))
lines = []
    # This is sample code you may change your code as per your requirements
    #You need to add one2many field like line_ids in your wizard and then when you select multiple product
    #from product.product and open wizard then you may see all selected lines display in your wizard one2many
for product in product_product_ids:
vals = (0, 0, {
'product_id': product.id,
'product_old_price': product.lst_price,
'internal_ref': product.default_code,
})
lines.append(vals)
return {'type': 'ir.actions.act_window',
'name': _('Product Wizard'),
'res_model': 'my.confirm.wizard',
'target': 'new',
'view_id': self.env.ref('module_name.wizard_id').id,
'view_mode': 'form',
'context': {'default_line_ids': lines}
}

Wednesday, 23 August 2023

How To Install wkhtmltopdf 0.12.5 (with patched qt) for Odoo/Openerp/Python

 How to Install Wkhtmltopdf 0.12.5 For Odoo/Openerp 


Download the package

wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb


Install the package

sudo dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb


Fix dependencies

sudo apt install -f

Tuesday, 11 July 2023

required_if_provider In Odoo

In Odoo, the "required_if_provider" parameter is used in fields to make them required based on the selected value of another field that represents a provider.

When defining fields in an Odoo model, you can set the "required_if_provider" parameter on a field to specify that it should be required if a specific provider is selected. This parameter is typically used in combination with related fields or selection fields representing providers. 

Here's an example to illustrate the usage of "required_if_provider":

from odoo import fields, models


class MyModel(models.Model):

    _name = 'my.model'


    provider = fields.Selection([

        ('provider1', 'Provider 1'),

        ('provider2', 'Provider 2'),

        ('provider3', 'Provider 3')

    ], string='Provider')

    field1 = fields.Char(string='Field 1')

    field2 = fields.Char(string='Field 2', required_if_provider='provider1')

    field3 = fields.Char(string='Field 3', required_if_provider='provider2')


In this example, we have a model called my.model with three fields: "provider", "field1", "field2", and "field3". The "provider" field is a selection field representing different providers.

  • If the value of the "provider" field is set to "provider1", the "field2" becomes a required field, meaning that the user must provide a value for field2 to successfully save the record.

  • If the value of the "provider" field is set to "provider2", the "field3" becomes a required field, and the user must provide a value for "field3"  to save the record.

The "required_if_provider" parameter allows you to conditionally enforce field requirements based on the selected provider value, providing flexibility in data validation based on specific conditions in your Odoo models.

Wednesday, 28 June 2023

Factorial Python Program

Here's a small Python example that calculates the factorial of a given number using recursion def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) # Example usage number = 5 result = factorial(number) print("The factorial of {number} is: ",result)





Description : In this example, the factorial function takes an integer 'n' as input and calculates its factorial recursively. The base case is when 'n' is equal to 0, in which case the function returns 1. Otherwise, it multiplies 'n' by the factorial of n-1. The example then demonstrates the usage of the factorial function by calculating the factorial of 5 and printing the result. When executed, the output will be: ('The factorial of {number} is: ', 120)

Tuesday, 29 January 2019

Get all month start date and end date in python

from datetime import datetime, timedelta
import calendar


data = []
selected_start_date = datetime.strptime('2019-01-01', "%Y-%m-%d")
selected_start_date_year = selected_start_date.year
for month in range(1,13):
other_val, num_days = calendar.monthrange(int(selected_start_date_year), int(month))
month_start_date = datetime(int(selected_start_date_year), int(month), 1).strftime("%Y-%m-%d")
month_end_date = datetime(int(selected_start_date_year), int(month), num_days).strftime("%Y-%m-%d")
data.append({'start_date':month_start_date,'end_date':month_end_date})
print "data ______________",data

Wednesday, 20 June 2018

# Remove action button from tree view and form view.

# Remove action button from tree view and form view.

var Sidebar = require('web.Sidebar');

Sidebar.include({
    init : function(){
        this._super.apply(this, arguments);
        var view = this.getParent();
        var self = this;
    if (view.fields_view && view.fields_view.type === "form") {
            self.sections.splice(1, 2);
        }
        if (view.fields_view && view.fields_view.type === "tree") {
        self.sections.splice(1, 2);
        }
    },
   
});

Wednesday, 31 January 2018

Current Status display in form view.

Example:

odoo.define('module name.module name', function (require) {
"use strict";

var calenderView = require('web_calendar.CalendarView');
var form_common = require('web.form_common');
var core = require('web.core');
var _t = core._t;
var QWeb = core.qweb;
var session = require('web.session');

var form_widgets = require('web.form_widgets');

form_widgets.FieldStatus.include({
render_value: function() {
var self = this;
if(self.view.model=='obj.obj'){
        var content = QWeb.render("FieldStatus.content.extended", {
            'widget': self,
            'value_folded': _.find(self.selection.folded, function(i){return i[0] === self.get('value');})
        });
        self.$el.html(content);
}else{
this._super();
}
    }
})

Friday, 8 September 2017

Open Wizard On Click Menu

Open Wizard On Click Menu

<report
    id="abc_abc_report"
    string="ABC"
    model="abc.abc"
    report_type="qweb-pdf"
    file="modulename.report_id"
    name="modulename.report_id"
    menu='False'
/>

Add one py file for add field in wizard object.

like below code.

from openerp import models, fields, api, _
from openerp.exceptions import Warning
import datetime

class abc_abc_wizard(models.TransientModel):
    _name = "abc.abc"

    start_date = fields.Date('Start Date')
    end_date = fields.Date('End Date')


    @api.multi
    def get_abc_abc(self):
        return self.env['report'].get_action(self, 'module_name.abc_abc_report_template')

Add wizard view and menu.

<?xml version="1.0"?>
<openerp>
    <data>

        <record id="abc_abc_form_view" model="ir.ui.view">
            <field name="name">abc_abc</field>
            <field name="model">abc.abc</field>
            <field name="arch" type="xml">
                <form string="ABC">
                    <group>
                        <field name="start_date"/>
                        <field name="end_date"/>
                    </group>
                    <footer>
                        <button name="get_abc_abc" string="ABC" type="object" class="oe_highlight"/>
                        or
                    <button string="Cancel" class="oe_highlight" special="cancel" />
                    </footer>
                </form>
            </field>
        </record>

        <record model="ir.actions.act_window" id="abc_abc_action">
            <field name="name">ABC</field>
            <field name="res_model">abc.abc</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="abc_abc_form_view"/>
            <field name="target">new</field>
        </record>

        <menuitem name="Report" id="report_reporting" parent="base.menu_reporting" sequence="500"/>

        <menuitem name="ABC" id="abc_abc_reporting" parent="report_reporting" action="abc_abc_action" sequence="510"/>

    </data>
</openerp>

Create Template for report.

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_id">
    <t t-foreach="docs" t-as="o">
        <t t-call="report.external_layout">
            <div class="page">
                <br /><br /><br />
                <div class="row">
                    <strong style="text-align:center;display:block;">ABC</strong>
                    <br/>
                    <table border="1" class="table table-condensed">
                    </table>
                </div>
            </div>
        </t>
    </t>
</template>
</data>

open form onclick button from form view

Add one button on form view like below code.

<div name="button_box" position="inside">
    <button class="oe_inline oe_stat_button" name="action_form_view"
            type="object" icon="fa-book">
        <field string="Examples" name="Examples_count" widget="statinfo"/>
    </button>
</div>

Add Examples_count field on py file.

Examples_count is field for display total number of record on button.

Add below code in py file

    @api.multi
    def action_form_view(self):
        Example_line_ids = self.env['Example.order.line'].search([('product_id','=',self.id)])
        Example_ids = []
        for line in Example_line_ids:
            if line.order_id:
                Example_ids.append(line.order_id.id)
       
        view_id = self.env.ref('product_Example.view_tree_tree').id
        form_view_id = self.env.ref('product_Example.view_Example_order_view').id
        context = self._context.copy()
        return {
            'name':'form_name',
            'view_type':'form',
            'view_mode':'tree',
            'res_model':'Example.order',
            'view_id':view_id,
            'views':[(view_id,'tree'),(form_view_id,'form')],
            'type':'ir.actions.act_window',
            'domain':[('id','in',Example_ids)],
            'target':'current',
            'context':context,
        }


    @api.multi
    def get_Example_count(self):
        Example_line_ids = self.env['Example.order.line'].search([('product_id','=',self.id)])
        Example_ids = []
        for line in Example_line_ids:
            if line.order_id:
                Example_ids.append(line.order_id.id)
        self.Examples_count = len(Example_ids) or 0


    Examples_count = fields.Float(compute='get_Example_count', string='Examples Count') 

Wednesday, 31 May 2017

Put menu in more options.

Create One wizard object like below

class wizard_wizard(models.TransientModel):
    _name = "wizard.wizard"

Add Your Field as per your requirements like as below

    name = field.Char('Name')


Now Create One view for wizard like below

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
    <record id="wizard_wizard_view" model="ir.ui.view">
            <field name="name">wizard.wizard.form</field>
            <field name="model">wizard.wizard</field>
            <field name="arch" type="xml">
                <form string="Wizard">
                    <footer>
                        <button name="your_method" string="Wizard" type="object" class="oe_highlight"/>
                        or
                        <button string="Cancel" class="oe_link" special="cancel" />
                    </footer>
                </form>
            </field>
        </record>

        <act_window id="wizard_wizard_action"
            name="wizard"
            src_model="object.object" #on which object you have to put menu
            res_model="wizard.wizard"
            view_type="form" view_mode="form"
            key2="client_action_multi" target="new"/>
    </data>
</openerp>

Wednesday, 19 April 2017

Send mail On Click Button In Odoo

Send mail On Click Button In Odoo

Please First Put your button in your view.
I will give example for when we click confirm order in sale order at that time send mail.
You can use your button insted of confirm button.

First You have to create email template like as below

            <record id="email_template_id" model="email.template">
            <field name="name">Template Name</field>
            <field name="email_from">${object.user_id.email or object.company_id.email or                    'noreply@localhost'|safe}</field>
            <field name="subject">Add Subject Name ${object.name}</field>
            <field name="model_id" ref="sale.model_sale_order"/> #You can give your own model name
            <field name="auto_delete" eval="True"/>
            <field name="body_html"><![CDATA[
<div>
    <p>Hello ${object.partner_id.name},</p>
    <p>Thank you for your order ${object.name}, We appreciate your Business!</p>
</div>
            ]]></field>
            </record>


@api.multi
def action_button_confirm(self):
    template_id = self.env['ir.model.data'].get_object_reference('module_name', 'your_email_template_name')[1]
    template_id.email_to = 'email id'
    template_id.email_from = 'Give your mail id'
    template_id.send_mail()
    Ex.
    template_id = self.env['ir.model.data'].get_object_reference('sale_order_enhance', 'email_template_id')[1]
    template_id.email_to = 'abc@gmail.com'
    template_id.email_from = self.company_id.email
    template_id.send_mail()


  • Without Template Send Mail.


Create Template detail and store in one variable like as below.

body_html = '''
    <div>
        <p>
        Hello,
        <br/><br/>
            <br/><br/>
            The details of template is as below.
            <br/><br/>
        </p>
        <table border="1" cellpadding="5" cellspacing="1">
            <tbody>
                <tr>
                    <td><strong>Value 1:</strong></td><td>''' + do + '''</td>
                </tr>
                <tr>
                    <td><strong>Value 2:</strong></td><td>''' + self.field name + '''</td>
                </tr>
                <tr>
                    <td><strong>Value 3:</strong></td><td>''' + self.field name + '''</td>
                </tr>
                <tr>
                    <td><strong>Value 4:</strong></td><td>''' + self.field name + '''</td>
                </tr>
            </tbody>
        </table>
    </div>
    '''
mail_values = {
            'email_from': 'From mail id',
            'email_to': 'To mail id',
            'subject': 'Subject',
            'body_html': body_html,
            'state': 'outgoing',
            'type': 'email',
        }
        mail_id = mail_mail.create(mail_values)
        if mail_id:
            mail_id.send()

Tuesday, 21 March 2017

Display field name when inspect element on many2one and char field in odoo

Display field name when inspect element on many2one and char field in odoo

Code Applay In Version - 10

Example is below:-
Example: <input id="oe-field-input-13" name="field_name" type="text">
---------------------------------------------------------------------------------------------
Inherit FieldChar template for add 't-att-name="widget.name"''

Inherit FieldMany2One template for add 't-att-name="widget.name"''

After Create below file register in __openerp__.py file

<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

    <t t-extend="FieldChar">
        <t t-jquery="input" t-operation="replace">
        <input t-if="!widget.get('effective_readonly')" class="o_form_input"
            t-att-barcode_events="widget.options.barcode_events"
            t-att-type="widget.password ? 'password' : 'text'"
            t-att-name="widget.name"
            t-att-id="widget.id_for_label"
            t-att-tabindex="widget.node.attrs.tabindex"
            t-att-autofocus="widget.node.attrs.autofocus"
            t-att-placeholder="widget.node.attrs.placeholder"
            t-att-autocomplete="widget.password ? 'new-password' : widget.node.attrs.autocomplete"
            t-att-maxlength="widget.field.size"/>
        </t>
    </t>

    <t t-extend="FieldMany2One">
        <t t-jquery="input" t-operation="replace">
       <input type="text" class="o_form_input"
            t-att-name="widget.name"
            t-att-barcode_events="widget.options.barcode_events"
            t-att-id="widget.id_for_label"
            t-att-tabindex="widget.node.attrs.tabindex"
            t-att-autofocus="widget.node.attrs.autofocus"
            t-att-placeholder="widget.node.attrs.placeholder"/>
        </t>
    </t>
</templates>

Code Applay In Version - 8

<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

    <t t-extend="FieldChar">
        <t t-jquery="input" t-operation="replace">
   <input t-att-type="widget.password ? 'password' : 'text'"
            t-att-name="widget.name"
                t-att-id="widget.id_for_label"
                t-att-tabindex="widget.node.attrs.tabindex"
                t-att-autofocus="widget.node.attrs.autofocus"
                t-att-placeholder="widget.node.attrs.placeholder"
                t-att-maxlength="widget.field.size"
            />
        </t>
    </t>

    <t t-extend="FieldMany2One">
        <t t-jquery="input" t-operation="replace">
  <input type="text"
t-att-name="widget.name"
t-att-id="widget.id_for_label"
t-att-tabindex="widget.node.attrs.tabindex"
t-att-autofocus="widget.node.attrs.autofocus"
t-att-placeholder="widget.node.attrs.placeholder"
  />
        </t>
    </t>
</templates>

Tuesday, 14 March 2017

Could not execute command 'lessc' in odoo-9

Could not execute command 'lessc' in odoo-9


If "Could not execute command 'lessc'" Error ocour while installing odoo-9 and the login page will not show clearly.
Then use this six command in terminal and run it one by one

1- sudo apt-get install nodejs

2- sudo apt-get install npm

3- sudo npm install -g less

4- sudo npm install -g less-plugin-clean-css

5- sudo ln -s /usr/local/bin/lessc /usr/bin/lessc

6- sudo ln -s /usr/bin/nodejs /usr/bin/node

Thursday, 9 February 2017

How to disable or invisible Edit and Create button as per group.

How to disable or invisible Edit and Create button as per group.


Follow below example.

Follow Below step.

1 ) Open  Setting-> Technical-> user Interface-> Views

2 ) Create one view like below.

View Name              :-  Give name for view

View Type              :-  Form

Object                 :- product.product

Sequence               :- 16

Inherited View         :- product.product.form

View inheritance mode  :- Extension View

Active                 :- True

3 ) Add below code in Architecture tab.

<data>
<xpath expr='//form[@string="Product Variant"]' position="attributes">
<attribute name="edit">false</attribute>
<attribute name="create">false</attribute>
</xpath>
</data>

4 ) Add any group in Groups Tab.

Ex. -> your own group

Tuesday, 7 February 2017

How to open wizard on click button in odoo/OpenERP

How to open wizard on click button in odoo/OpenERP

Create .py file for define method and field like below

class wizard_object(models.TransientModel):
_name = 'wizard.object'

field_1 = fields.Text('Field - 1')
field_2 = fields.Text('Field - 2')

@api.multi
def method_name(self):
pass


Create .xml file as below.


<record id="wizard_object_view" model="ir.ui.view">
<field name="name">wizard.object</field>
<field name="model">wizard.object</field>
<field name="arch" type="xml">
<form string="Wizard Demo" version="7.0">
<group>
<field name="field_1"/>
<field name="field_1"/>
</group>
<footer>
<button name="method_name" string="Yes" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>

<record id="open_wizard_action_id" model="ir.actions.act_window">
<field name="name">Wizard Demo</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">wizard.object</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

Create One button when you want to open wizard.

<button name="%(open_wizard_action_id)d" type="action" string="Open Wizard"/>

Monday, 6 February 2017

How To create Sequence in odoo/openerp

How To create Sequence in odoo/openerp

Step -1

Create One Xml File and register xml file in __openerp__.py and Add below code.

<data noupdate="1">

    <!-- Sequences for any object -->
    <record id="seq_id" model="ir.sequence.type">
        <field name="name">Give Any Name</field>
        <field name="code">seq.seq</field>
    </record>

    <record id="give_any_unique_id" model="ir.sequence">
        <field name="name">name same as above</field>
        <field name="code">seq.seq</field>
        <field name="prefix">SQ</field>
        <field name="padding">5</field>
    </record>

</data>



Step - 2

Create Py file when you want to add sequence like below

class proejct_task(models.Model):
    _inherit = "project.task"
 
    sequence_id = fields.Char('Sequence', readonly=True)

    @api.model
    def create(self, vals):
        seq = self.env['ir.sequence'].get('seq.seq') or '/'    //seq.seq is code which is define in xml file
        vals['sequence_id'] = seq
        return super(proejct_task, self).create(vals)

step - 3

Add sequence_id in project task form view like below.

<record id="view_task_form2_inherit" model="ir.ui.view">
<field name="name">view.task.form2.form</field>
<field name="model">project.task</field>
<field name="type">form</field>
<field name="inherit_id" ref="project.view_task_form2" />
<field name="arch" type="xml">
<xpath expr="//field[@name='project_id']" position="after">
<field name="sequence_id"/>
</xpath>
</field>
</record>

When you crate ptoject task sequence field is auto create like SQ00002,SQ00003,SQ00004

Wednesday, 1 February 2017

How To reload page on click button in openerp/odoo

How To reload page on click button in openerp/odoo



You have to add button in form view like below code.
<xpath expr="//field[@name='name']" position="after">
            <button name="refresh_page" string="Refresh" type="object"/>
        </xpath>

You have to create one method like below.(this mehtod call when you click on button)

@api.multi
        def refresh_page(self):
            return { 'type': 'ir.actions.client', 'tag': 'reload'}

Monday, 26 December 2016

How Create Inherited Tree view

How Create Inherited Tree view

1) Create parent field and child field as below

class object_object(models.Model):
    _name = 'object.object'

    name = fields.Char('Name')
    parent_id = fields.Many2one('object.object','Parent Field')
    child_id = fields.One2many('object.object', 'parent_id', string='Child Field')

2) Create simple tree view and add field as 'field_parent' as below

<record id="inherited_tree_view_example" model="ir.ui.view">
            <field name="name">object.object.tree</field>
            <field name="model">object.object</field>
            <field name="field_parent">child_id</field>
            <field name="arch" type="xml">
                <tree string="String Name">
                    <field name="name"/>
                </tree>
                or
                <tree toolbar="True" string="String Name">
                    <field name="name"/>
                </tree>
            </field>
        </record>

3) Create simple action as below

        <record id="inherited_tree_view_action" model="ir.actions.act_window">
            <field name="name">Action Name</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">object.object</field>
            <field name="domain">[('parent_id','=',False)]</field>
            <field name="view_type">tree</field>
            <field name="view_id" ref="inherited_tree_view_example"/>
        </record>
4) Create simple menu as below

        <menuitem action="inherited_tree_view_action" id="menu_id"/>

Sunday, 11 December 2016

Create Custom Header Footer

Create Custome Header Footer

Create Simple template For Header Footer as below

<template id="header_footer_id">
    <t t-if="o and 'company_id' in o">
        <t t-set="company" t-value="o.company_id"></t>
    </t>
    <t t-if="not o or not 'company_id' in o">
        <t t-set="company" t-value="res_company"></t>
    </t>

    <t t-call="modulename.header_id" />
    <t t-raw="0" />
    <t t-call="modulename.footer_id" />
</template>

Create Header

<template id="header_id">
    <div class="header">
        //Your Code
    </div>
</template>

Create Footer

<template id="footer_id">
<div class="footer">
    //Your Code
</div>
</template>

Create Report custome report or inherited report

<template id="your_report_id">
    <t t-foreach="docs" t-as="o">
   <t t-call="modulename.header_footer_id">
       <div class="page">
       //Your Code
       </div>
   </t>
</t>
</template>

Odoo 17 New Features

  Odoo 17 new Features 1) Duplicate  multiple records from List view. Please have look below screenshots first you need to select records th...