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>

Monday, 7 November 2016

How To change default tree view limit.

How To change default tree view limit.

2) Create xml file for register js file.
<?xml version="1.0" encoding="utf-8"?>
<!-- vim:fdn=3:
-->
<openerp>
    <data>

        <template id="assets_backend" name="change_list_view_extend assets" inherit_id="web.assets_backend">
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/change_list_view_extend/static/src/js/change_list_number_list_view.js"></script>
            </xpath>
        </template>

    </data>
</openerp>


1) You have to create js file in static->src->js and copy below code.
openerp.change_list_view_extend = function(instance) {

    var QWeb = instance.web.qweb,
        _t = instance.web._t;

    instance.web.ListView.include({

    limit: function () {
   
       if (this._limit === undefined) {
           this._limit = (20
            || this.options.limit
                       || this.defaults.limit
                       || (this.getParent().action || {}).limit
                       || 20);
       }
       return this._limit;
   },


   load_list: function(data) {
       var self = this;
       this.fields_view = data;

       // Pager
       if (!this.$pager) {
           this.$pager = $(QWeb.render("ListView.pager", {'widget':self}));
           if (this.options.$buttons) {
               this.$pager.appendTo(this.options.$pager);
           } else {
               this.$el.find('.oe_list_pager').replaceWith(this.$pager);
           }

           this.$pager
               .on('click', 'a[data-pager-action]', function () {
                   var $this = $(this);
                   var max_page = Math.floor(self.dataset.size() / self.limit());
                   switch ($this.data('pager-action')) {
                       case 'first':
                           self.page = 0; break;
                       case 'last':
                           self.page = max_page - 1;
                           break;
                       case 'next':
                           self.page += 1; break;
                       case 'previous':
                           self.page -= 1; break;
                   }
                   if (self.page < 0) {
                       self.page = max_page;
                   } else if (self.page > max_page) {
                       self.page = 0;
                   }
                   self.reload_content();
               }).find('.oe_list_pager_state')
                   .click(function (e) {
                       e.stopPropagation();
                       var $this = $(this);

                       var $select = $('<select>')
                           .appendTo($this.empty())
                           .click(function (e) {e.stopPropagation();})
                           .append('<option value="20">20</option>' +
                            '<option value="40">40</option>' +
                                   '<option value="80">80</option>' +
                                   '<option value="200">200</option>' +
                                   '<option value="500">500</option>' +
                                   '<option value="2000">2000</option>' +
                                   '<option value="NaN">' + _t("Unlimited") + '</option>')
                           .change(function () {
                               var val = parseInt($select.val(), 10);
                               self._limit = (isNaN(val) ? null : val);
                               self.page = 0;
                               self.reload_content();
                           }).blur(function() {
                               $(this).trigger('change');
                           })
                           .val(self._limit || 'NaN');
                   });
       }
       return self._super(data);
   },
    });
};

Sunday, 6 November 2016

How To generate manual invoice.

How To generate manual invoice.

If You want to create manul invoice then folllow below step.

1) Create Py file for account invoice as below.


from openerp import models, fields, api, _

class account_invoice(models.Model):
    _inherit = "account.invoice"

    @api.multi
    def write(self, vals):
        if vals.get('number'):
            vals['number'] = vals['number']
        elif self.number:
            vals['number'] = self.number
        return super(account_invoice, self).write(vals)

    _defaults = {
        'number': False
    }

2) Change in invoice form view as below.

<?xml version="1.0"?>
<openerp>
    <data>
        <record model="ir.ui.view" id="inherit_view_account_invoice_for_number">
            <field name="name">inherit.view.account.invoice.for.number</field>
            <field name="model">account.invoice</field>
            <field name="inherit_id" ref="account.invoice_form"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='number']" position="replace">
                    <field name="number" attrs="{'readonly':[('state','!=','draft')]}" required="1"/>
                </xpath>
            </field>
        </record>
        <record model="ir.ui.view" id="inherit_invoice_supplier_form">
            <field name="name">inherit.view.account.invoice.for.supplier.number</field>
            <field name="model">account.invoice</field>
            <field name="inherit_id" ref="account.invoice_supplier_form"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='number']" position="replace">
                    <field name="number" attrs="{'readonly':[('state','!=','draft')]}" required="1"/>
                </xpath>
            </field>
        </record>
    </data>
</openerp>

Version - 9 :
class AccountInvoice(models.Model):
    _inherit = "account.invoice"

    temp_number = fields.Char('Temp Number', copy=False)

    @api.multi
    def write(self, vals):
    if vals.get('temp_number'):
    vals['number'] = vals.get('temp_number')
    if self.temp_number:
    vals['number'] = self.temp_number
    return super(AccountInvoice, self).write(vals)

<record id="manual_invoice_form_inherit" model="ir.ui.view">
        <field name="name">manual.invoice.form.inherit</field>
        <field name="model">account.invoice</field>
        <field name="inherit_id" ref="account.invoice_form"/>
        <field name="arch" type="xml">
        <data>
            <xpath expr="//form/sheet/h1/field[@name='number']" position="replace">
                <field name="number"/>
            </xpath>
            <xpath expr="//form/sheet/h1/field[@name='number']" position="after">
                <field name="temp_number"/>
            </xpath>
        </data>
        </field>
    </record>

Thursday, 29 September 2016

How To create simple module in odoo

How To create simple module in odoo


If you are new in odoo/openerp developer then you can easily develop your own module using below step

Create One folder and give proper name like student
1)You have to create __openerp__.py file.
In that you have to just copy below code and change as per your requirements.
{
    "name": "Demo Student",
    "version": "8.0",
    "author": "Module Author Name",
    "website": "Write your company website",
    "category": "Write module category like sale,project, hr etc.",
    "description": """ Write Your module description here.""",
    "depends": ['base','sale'],
    "data": [
            "student_view.xml",
    ],
    'demo': [],

    'test': [ ],

    "installable": True,
    "auto_install": False,
    "application": True,
}
2) You have to create simple __init__.py file
In that you have to include some file which in that you have to defines fields or some other code.
import student

Example
File name is student.py
Copy below code in your file
from openerp import models, api, fields

class student_student(models.Model):
_name = 'student.student'

fname = fields.Char('First Name')
mname = fields.Char('Middle Name')
lname = fields.Char('Last Name')

3) Create simple view file like below
<?xml version="1.0" encoding="utf-8"?>
<openerp>
   <data>

    <record id="student_form_view" model="ir.ui.view">
           <field name="name">student.form</field>
           <field name="model">student.student</field>
           <field name="arch" type="xml">
               <form string="Student">
                   <sheet>
                    <group>
                        <field name="fname" class="oe_inline"/>
                        <field name="mname" class="oe_inline"/>
                        <field name="lname" class="oe_inline"/>
                       </group>
                   </sheet>
               </form>
           </field>
       </record>

       <record id="student_action" model="ir.actions.act_window">
           <field name="name">Student</field>
           <field name="type">ir.actions.act_window</field>
           <field name="res_model">student.student</field>
           <field name="view_mode">tree,form</field>
           <field name="view_type">form</field>
           <field name="view_id" ref="student_form_view"/>
       </record>

       <menuitem action="student_action"
           id="menu_student_action"
           parent="base.menu_product" sequence="1"/>
</data>
</openerp>


4) Now you can update list of module in setting page and search your module and install it.

5) You can see your menu name sale->products->Student

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