Skip to content

Instantly share code, notes, and snippets.

Avatar

Sehrish sehrishnaz

View GitHub Profile
@sehrishnaz
sehrishnaz / odoo_get_selection_field_value.py
Created Aug 2, 2021
Retrieving Selection Field value instead of key
View odoo_get_selection_field_value.py
# Syntax
dict(self.fields_get(allfields=['field_name'])['field_name']['selection'])['key_of_selection_field']
#If you want to get field value in same model in which you are working than use below code
code = dict(self.fields_get(allfields=['state'])['state']['selection'])['key']
#Example
code = dict(self.fields_get(allfields=['code'])['code']['selection'])[self.code]
#If you want to get field value from another model than use below code
code = dict(self.env['your.model'].fields_get(allfields=['state'])['state']['selection'])['key']
@sehrishnaz
sehrishnaz / odoo_get_selection_field_value.py
Created Aug 2, 2021
Get Selection field value instead of key in Odoo
View odoo_get_selection_field_value.py
#syntax
some_variable = self._fields['your_selection_field'].selection
#Example
code = self._fields['code'].selection
# output: [('a', 'A'), ('b','B'), ('c','C')]
#To convert into python dictionary we will use dict keyword provided by python.
code_dict = dict(code)
#To get actual value we will pass key to above dictionary.
name = code_dict.get(self.code)
@sehrishnaz
sehrishnaz / get_first_date_of_every_month.py
Created Jul 29, 2021
Produce a date for every month from start until end in Odoo
View get_first_date_of_every_month.py
from datetime import datetime, timedelta, date
class some_model(models.Model):
_name = 'some.model'
# creating date field in odoo class
date_start = fields.Date(string="Start Date")
date_end = fields.Date(string="End Date")
@api.multi
@sehrishnaz
sehrishnaz / odoo_date_field_conversion.py
Created Jul 29, 2021
How to use and manipulate Date field in Odoo
View odoo_date_field_conversion.py
from datetime import datetime, timedelta, date
class some_model(models.Model):
_name = 'some.model'
# creating date field in odoo class
date_start = fields.Date(string="Start Date")
@api.one
def button_click(self):
@sehrishnaz
sehrishnaz / ecat_aggregate_calculator_tkinter.py
Created Apr 26, 2021
Ecat Aggregate Calculator using Python and Tkinter
View ecat_aggregate_calculator_tkinter.py
import tkinter as tk
from tkinter import messagebox
from tkinter import *
# reset input values or entry
def remove():
matric_total_entry.delete(0, END)
matric_obtained_entry.delete(0, END)
inter_obtained_entry.delete(0, END)
@sehrishnaz
sehrishnaz / grid_geometry_manager_tkinter.py
Created Apr 7, 2021
Layout Managers in Tkinter - .grid() geometry manager
View grid_geometry_manager_tkinter.py
import tkinter as tk
window = tk.Tk()
for i in range(5):
for j in range(5):
frame = tk.Frame(
master=window,
relief=tk.RAISED,
borderwidth=1
@sehrishnaz
sehrishnaz / place_geometry_manager_tkinter.py
Created Apr 7, 2021
Layout Managers in Tkinter - .place() geometry manager
View place_geometry_manager_tkinter.py
import tkinter as tk
window = tk.Tk()
frame = tk.Frame(master=window, width=300, height=100)
frame.pack()
label1 = tk.Label(master=frame, text="Position at (10, 10)", bg="grey")
label1.place(x=10, y=10)
@sehrishnaz
sehrishnaz / pack_geometry_manager_tkinter.py
Created Apr 7, 2021
Layout Managers in Tkinter - .pack() geometry manager
View pack_geometry_manager_tkinter.py
import tkinter as tk
window = tk.Tk()
# First Frame
frame1 = tk.Frame(master=window, width=300, height=200, bg="grey")
frame1.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
# Second Frame
frame2 = tk.Frame(master=window, width=200, bg="green")
frame2.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
# Third Frame
@sehrishnaz
sehrishnaz / create_tkinter_frame.py
Created Mar 30, 2021
Difference b/w Tkinter Windows, Widgets and Frames
View create_tkinter_frame.py
from tkinter import *
root = Tk()
root.geometry("500x350")
frame1 = Frame(root, highlightbackground="green", highlightcolor="green", highlightthickness=1, width=400, height=150, bd= 2)
frame1.pack()
frame1.pack_propagate(False)
Entry(frame1).pack()
@sehrishnaz
sehrishnaz / first_tkinter_application.py
Created Mar 29, 2021
First GUI Application using Tkinter and Python
View first_tkinter_application.py
from tkinter import *
# Create the root (base) window
win = Tk()
win.geometry("200x200")
# Create a label with words
w = Label(win, text="Hello, Welcome to LearnOpenerp!")
# Put the label into the window
w.pack()
# Start the event loop