Partner Ledger Report using ORM methods in Odoo8 - python-2.7

I am working on partner ledger report and i have prepared report using SQL query
def lines(self, partner):
move_state = ['draft','posted']
if self.target_move == 'posted':
move_state = ['posted']
full_account = []
if self.reconcil:
RECONCILE_TAG = " "
else:
RECONCILE_TAG = "AND l.reconcile_id IS NULL"
self.cr.execute(
"SELECT l.id, l.date, j.code, acc.code as a_code, acc.name as a_name,inv.state,inv.date_due, l.ref, m.name as move_name, l.name, l.debit, l.credit, l.amount_currency,l.currency_id, c.symbol AS currency_code " \
"FROM account_move_line l " \
"LEFT JOIN account_journal j " \
"ON (l.journal_id = j.id) " \
"LEFT JOIN account_account acc " \
"ON (l.account_id = acc.id) " \
"LEFT JOIN res_currency c ON (l.currency_id=c.id)" \
"LEFT JOIN account_move m ON (m.id=l.move_id)" \
"LEFT JOIN account_invoice inv ON (inv.move_id = l.move_id)" \
"WHERE l.partner_id = %s " \
"AND l.account_id IN %s AND " + self.query +" " \
"AND m.state IN %s " \
" " + RECONCILE_TAG + " "\
"ORDER BY l.date",
(partner.id, tuple(self.account_ids), tuple(move_state)))
res = self.cr.dictfetchall()
sum = 0.0
if self.initial_balance:
sum = self.init_bal_sum
for r in res:
sum += r['debit'] - r['credit']
r['progress'] = sum
full_account.append(r)
return full_account
My result are accurate
but now I want to do this using ORM methods and code for this:
account_move_model = self.pool.get('account.move.line')
full_account_custom = []
move_line_ids = account_move_model.search(self.cr, self.uid, [
('partner_id', '=', partner.id), ('account_id', 'in', tuple(self.account_ids)),
('state', 'in', tuple(move_state))
])
move_lines = account_move_model.browse(self.cr, self.uid, move_line_ids)
sum = 0.0
if self.initial_balance:
sum = self.init_bal_sum
for r in move_lines:
sum += r['debit'] - r['credit']
r['progress'] = sum
full_account_custom.append(r)
return full_account_custom
By doing this I am just getting the sum of all invoices of a partner/customer but the list of all invoice is not showing.
Where is the mistake and how to resolve it

Using ORM methods there are some difficulties..
Easy way is to use raw query.

Related

Google apps script - If function logic & URL

How can I add the "radiobutton" so that it is after the if statement - when I originally tried to do it - it created two forms?
Also how can I capture the URL of the form that is created so that I can send it to the approver of the sheet in MailApp.sendEmail?
if (period == 'Yes'){
var form = FormApp.create("Request for Leave" + UID)
.setTitle(name + " REQUEST FOR LEAVE" )
.setDescription("LEAVE DATES REQUESTED; \n\n" + date_from + " to " + date_to + "\n\nTYPE OF LEAVE; \n\n" + paid + " " + leave_type + "\n\nREASON FOR THE REQUEST; \n\n " + info + "\n\nCOVER HAS BEEN ARRANGED BY \n\n" + cover +"\n" );
// radiobuttons
item = "Leave approved?";
var choices = ["YES", "NO",];
form.addMultipleChoiceItem()
.setTitle(item)
.setChoiceValues(choices)
.setRequired(true);
}
/**Following is for part of day */
{ var form = FormApp.create("Request for Leave" + UID)
.setTitle(name + " PARTIAL DAY REQUEST FOR LEAVE" )
.setDescription("LEAVE DATE REQUESTED; \n\n" + date_from + " between " + time_from + " and " + time_to + "\n\nTYPE OF LEAVE; \n\n" + paid + " " + leave_type + "\n\nREASON FOR THE REQUEST; \n\n " + info + "\n\nCOVER HAS BEEN ARRANGED BY \n\n" + cover +"\n" );
// radiobuttons
item = "Leave approved?";
var choices = ["YES", "NO",];
form.addMultipleChoiceItem()
.setTitle(item)
.setChoiceValues(choices)
.setRequired(true);

Getting the connected components in networkx in the order of which edges are added

Each sentence in doc2 is displayed as a graph. Now the edges were added in the form s-o-v from the respective subject_list, object_list and verb_list.
I have tried to display the connected components. But the order in which it displays the sentence is not in the order in which the edges were added.
# This Python file uses the following encoding: utf-8
%matplotlib notebook
import codecs
import itertools
import re
import networkx as nx
import matplotlib.pyplot as pl
from matplotlib.font_manager import FontProperties
prop = FontProperties()
graph = nx.Graph()
labels = {}
each_one = []
list_of_sentences = []
subject_list = []
object_list = []
verb_list = []
newDict = {}
with codecs.open('doc2.txt', encoding='utf-8') as f:
text = f.read()
sentences = re.split(r' *[\.\?!][\'"\)\]]* *', text)
for stuff in sentences:
list_of_sentences.append(stuff)
new_list_of_sentences = []
for d in list_of_sentences:
s = d.replace(u'वतीन', '').replace(u'आनी', '').replace(u'हिणें', '').replace(',', '')
new_list_of_sentences.append(s)
f = open('doc2_tag.txt', 'r')
for line in f:
k, v = line.strip().split('/')
newDict[k.strip().decode('utf-8')] = v.strip()
f.close()
for sentence in new_list_of_sentences:
a = b = c = ""
sentence_word_list = sentence.split()
for word in sentence_word_list:
if newDict[word] == 'N-NNP':
a += word + " "
if newDict[word] == 'N-NN':
b += word + " "
if newDict[word] == 'JJ':
b += word + " "
if newDict[word] == 'QT-QTC':
b += word + " "
if newDict[word] == 'RB':
b += word + " "
if newDict[word] == 'N-NST':
b += word + " "
if newDict[word] == 'PR-PRP':
b += word + " "
if newDict[word] == 'PSP':
b += word + " "
if newDict[word] == 'CC-CCD':
b += word + " "
if newDict[word] == 'V-VM-VF':
c += word + " "
subject_list.append(a)
object_list.append(b)
verb_list.append(c)
konkani_dict = {u'सनरायझर्साक': u'सनरायझर्स', u'सनरायझर्सान': u'सनरायझर्स', u'सनरायझर्साच्या': u'सनरायझर्स'}
for idx, sub in enumerate(subject_list):
temp_list = sub.split(" ")
for i in temp_list:
if i in konkani_dict:
new_sub = sub.replace(i, konkani_dict[i])
subject_list[idx] = new_sub
for s in subject_list:
if s is not "":
graph.add_node(s)
labels[s] = s
for o in object_list:
if o is not "":
graph.add_node(o)
labels[b] = b
for v in verb_list:
if v is not "":
graph.add_node(v)
labels[v] = v
for (s, o, v) in zip(subject_list, object_list, verb_list):
if s and o is not "":
graph.add_edge(s, o)
if o and v is not "":
graph.add_edge(o, v)
pos=nx.spring_layout(graph,k=0.15,iterations=20)
nx.draw(graph, with_labels = True, font_family = "Nirmala UI", node_size = 40, font_size = 9 ,node_color = "darkblue")
pl.show()
sentences=[]
for component in nx.connected_components(graph):
g=(
filter(
lambda x: x[0] in component and x[1] in component,
graph.edges
)
)
p=[]
p= ''.join(item for tuple_ in g for item in tuple_)
print p
sentences.append(p)
print sentences
output=[]
for i in sentences:
inputWords = i.split(" ")
inputWords=inputWords[-1::-1]
output = ' '.join(inputWords)
print output
Expected output is spmething like this:
शिखर धवनान सगळ्यांत चड ४५ धांवड्यो केल्यो ,
सनरायझर्स दीपर हुडा जैतांत पर्जळ्ळो
This is the output I get: sentences displayed
networkx doesn't store the order of created nodes/edges because this information is mostly useless. If you want to have this information, you should add it manually. In your program, for example (for edges):
edge_index = 0
for (s, o, v) in zip(subject_list, object_list, verb_list):
if s and o is not "":
graph.add_edge(s, o, index=edge_index)
edge_index += 1
if o and v is not "":
graph.add_edge(o, v, index=edge_index)
edge_index += 1
Then you should print sorted edges:
sorted( # Sorted list of edges
list(g.edges.data('index')), # With 'index' data
key=lambda x: x[2] # Sorted by 'index' data
)```

#SQLite This query statement does not work as I thought. What should I do

const static char* QUERY_UPDATE_ROUTE_ADDRESS = "UPDATE [PRouteAddrTable] SET [addressLanguage] = ?, [iso] = ?, " \
"[country] = ? , [state] = ?, [city] = ? , [cityCenter] = ?, " \
"[street] = ? , [street2] = ?, [houseNo] = ? , [zip] = ? " \
"WHERE RouteID = ? AND WptUseType = ? AND Lon = ? AND Lat = ?";
When this query is executed, the table is empty. So I think the table should be empty even after executing the query statement. But there is one record. I seem to be thinking wrong.
Please Help me

can't add everything together? (stuck on the last code)

*ignore this part, just look at the last few codes. im trying to add all the quanties together but the last code prints every purchase individually? How can i get it to print "Your purchases is" and add the quanties times their price all in one line instead of printing it for every individual
print "Enter a fruit name (or done):",
fruit = raw_input()
fruit_list = []
while fruit != "done":
fruit_list = fruit_list + [fruit]
print "Enter a fruit name (or done):",
fruit = raw_input()
price_list = []
for x in range(0, len(fruit_list)):
print "Enter the price for " + fruit_list[x] + ":",
price = float(raw_input())
price_list = price_list + [price]
# print " Your fruit list is:" + str(fruit_list)
# print "Your price list is:" + str(price_list)
print fruit_list
print price_list
quanity_list = []
for x in range(0, len(fruit_list)):
print str(fruit_list[x]) + str(price_list[x]) + " Quantity:",
quantity = int(raw_input())
print "Your total purchase is:", + price_list[x] * quantity
Try the following code :
Replace your last part of code with;
total = 0
quanity_list = []
for x in range(0, len(fruit_list)):
print str(fruit_list[x]) + str(price_list[x]) + " Quantity:",
quantity = int(raw_input())
total = total + price_list[x] * quantity
print "Your total purchase is:" + total

Python 2.7; How to clear an entry in the GUI

I have an example code, here just for BMI index. I would like to clear the input and output fields in the GUI. It seems that i can clear the entries, but the BMI calculation is not being removed (row 79 does not seem to have an effect) (# self.text.delete(0, 'end'))
Thanks
Emin
import math
from Tkinter import *
class Application(Frame):
"""A GUI application with three buttons"""
def __init__(self, master):
"""Initialize the Frame"""
Frame.__init__(self,master)
self.grid()
self.create_widgets()
self.title = Label(self, text = "BMI index calculation")
self.title.grid(row = 0, column = 0, columnspan = 2 , sticky =W)
def create_widgets(self):
"""Create button, text and entry widgets"""
self.name = Label(self, text = "What is your name?")
self.name.grid(row = 1, column = 0, columnspan = 2 , sticky =W)
self.name_io = Entry(self)
self.name_io.grid(row = 1, column =2, sticky = W)
self.age = Label(self, text = "How old are you?")
self.age.grid(row = 2, column = 0, columnspan = 2 , sticky =W)
self.age_io = Entry(self)
self.age_io.grid(row = 2, column =2, sticky = W)
self.height = Label(self, text = "How tall are you?")
self.height.grid(row = 3, column = 0, columnspan = 2 , sticky =W)
self.height_io = Entry(self)
self.height_io.grid(row = 3, column =2, sticky = W)
self.weight = Label(self, text = "How much do you weigh in kg?")
self.weight.grid(row = 4, column = 0, columnspan = 2 , sticky =W)
self.weight_io = Entry(self)
self.weight_io.grid(row = 4, column =2, sticky = W)
self.submit_button = Button(self, text = "Calculate", command = self.reveal)
self.submit_button.grid(row = 5, column = 0, sticky = W)
self.text = Text(self, width = 40, height = 5, wrap = WORD)
self.text.grid(row = 6, column = 0, columnspan = 3, sticky = W)
self.clear_button = Button(self, text = "Clear", command = self.clear_text)
self.clear_button.grid(row = 7, column = 0, sticky = W)
def reveal(self):
"""Display message based on the password typed in"""
content_name = self.name_io.get()
content_age = float(self.age_io.get())
content_height = float(self.height_io.get())
content_weight = float(self.weight_io.get())
BMI = round((content_weight/(content_height/100)**2.),1)
underBMI = 18.5
NormalBMI = 24.9
OverweightBMI = 29.9
ObesityBMI = 30
if BMI <= underBMI:
message = content_name + ", " + "your BMI index is" + " " + str(BMI) + ", " + "you are underweight, so you need to eat!"
elif (BMI > underBMI) and (BMI <= NormalBMI):
message = content_name + ", " + "your BMI index is" + " " + str(BMI) + ", " + "your BMI is Normal"
elif (BMI > NormalBMI) and (BMI <= OverweightBMI):
message = content_name + ", " + "your BMI index is" + " " + str(BMI) + ", " + "you are Overweight - need to exercise!"
elif (BMI > OverweightBMI):
message = content_name + ", " + "your BMI index is" + " " + str(BMI) + ", " + "you are in Obesity"
self.text.insert(0.0, message)
def clear_text(self):
self.name_io.delete(0, 'end')
self.age_io.delete(0, 'end')
self.height_io.delete(0, 'end')
self.weight_io.delete(0, 'end')
# self.text.delete(0, 'end')
root = Tk()
root.title("BMI Index")
root.geometry("600x350")
app = Application(root)
root.mainloop ()
The problem is that you're giving an index that is 0.0. Text widget indexes are a string of the form line.column but you're giving it a floating point number.
The proper index for the first character is the string "1.0".
self.text.delete("1.0", 'end')
Simply
your_entry.delete(0,END)