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'}

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