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>

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