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

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