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>

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