Need to print Five sequence number for one sale.order other than ir.sequence - odoo

I have writen code to print five sequence number for 1 sale order
but it affect last sale order number , it was jumping 5 order numbers
I have to print 5 sequence number for 1 sale order without ir sequence
ticket = fields.Char(string="Ticket", readonly=True, required=True, copy=False, default='New')
#api.multi
def action_confirm(self):
result = super(SaleOrder, self).action_confirm()
len_count = []
ticket_list = []
tickets = ""
count = 5
for i in range(count):
x = self.env['ir.sequence'].next_by_code('sale.order')
if not len(len_count) == 5:
if not tickets:
tickets = x
else:
tickets = tickets + ',' + x
print tickets
print 'abc'
ticket_list.append(str(tickets))
self.ticket = ticket_list
print ticket_list
ctx = dict(self.env.context or {})
ctx.update({
'sale_action_new': ticket_list,
})
print ctx
template = self.env.ref('sale_order.email_template_ticket')
template.with_context(ctx).send_mail(self.id)

Let me try to help.
start = self.id //sales-order id
limit = start + 5
for x in range(start, limit):
if not tickets:
tickets = x
else:
tickets = tickets + ',' + x

Related

Movie Ticketing Project

these is my movie ticketing Code
x = 10
Booked_seat = 0
prize_of_ticket = 0
Total_Income = 0
Row = int(input('Enter number of Row - \n'))
Seats = int(input('Enter number of seats in a Row - \n'))
Total_seat = Row*Seats
Booked_ticket_Person = [[None for j in range(Seats)] for i in range(Row)]
class chart:
#staticmethod
def chart_maker():
seats_chart = {}
for i in range(Row):
seats_in_row = {}
for j in range(Seats):
seats_in_row[str(j+1)] = 'S'
seats_chart[str(i)] = seats_in_row
return seats_chart
#staticmethod
def find_percentage():
percentage = (Booked_seat/Total_seat)*100
return percentage
class_call = chart
table_of_chart = class_call.chart_maker()
while x != 0:
print('1 for Show the seats \n2 for Buy a Ticket \n3 for Statistics ',
'\n4 for Show booked Tickets User Info \n0 for Exit')
x = int(input('Select Option - '))
if x == 1:
if Seats < 10:
for seat in range(Seats):
print(seat, end=' ')
print(Seats)
else:
for seat in range(10):
print(seat, end=' ')
for seat in range(10, Seats):
print(seat, end=' ')
print(Seats)
if Seats < 10:
for num in table_of_chart.keys():
print(int(num)+1, end=' ')
for no in table_of_chart[num].values():
print(no, end=' ')
print()
else:
count_num = 0
for num in table_of_chart.keys():
if int(list(table_of_chart.keys())[count_num]) < 9:
print(int(num)+1, end=' ')
else:
print(int(num)+1, end=' ')
count_key = 0
for no in table_of_chart[num].values():
if int(list(table_of_chart[num].keys())[count_key]) <= 10:
print(no, end=' ')
else:
print(no, end=' ')
count_key += 1
count_num += 1
print()
print('Vacant Seats = ', Total_seat - Booked_seat)
print()
elif x == 2:
Row_number = int(input('Enter Row Number - \n'))
Column_number = int(input('Enter Column Number - \n'))
if Row_number in range(1, Row+1) and Column_number in range(1, Seats+1):
if table_of_chart[str(Row_number-1)][str(Column_number)] == 'S':
if Row*Seats <= 60:
prize_of_ticket = 10
elif Row_number <= int(Row/2):
prize_of_ticket = 10
else:
prize_of_ticket = 8
print('prize_of_ticket - ', '$', prize_of_ticket)
conform = input('yes for booking and no for Stop booking - ')
person_detail = {}
if conform == 'yes':
person_detail['Name'] = input('Enter Name - ')
person_detail['Gender'] = input('Enter Gender - ')
person_detail['Age'] = input('Enter Age - ')
person_detail['Phone_No'] = input('Enter Phone number - ')
person_detail['Ticket_prize'] = prize_of_ticket
table_of_chart[str(Row_number-1)][str(Column_number)] = 'B'
Booked_seat += 1
Total_Income += prize_of_ticket
else:
continue
Booked_ticket_Person[Row_number-1][Column_number-1] = person_detail
print('Booked Successfully')
else:
print('This seat already booked by some one')
else:
print()
print('*** Invalid Input ***')
print()
elif x == 3:
print('Number of purchased Ticket - ', Booked_seat)
print('Percentage - ', class_call.find_percentage())
print('Current Income - ', '$', prize_of_ticket)
print('Total Income - ', '$', Total_Income)
print()
elif x == 4:
Enter_row = int(input('Enter Row number - \n'))
Enter_column = int(input('Enter Column number - \n'))
if Enter_row in range(1, Row+1) and Enter_column in range(1, Seats+1):
if table_of_chart[str(Enter_row-1)][str(Enter_column)] == 'B':
person = Booked_ticket_Person[Enter_row - 1][Enter_column - 1]
print('Name - ', person['Name'])
print('Gender - ', person['Gender'])
print('Age - ', person['Age'])
print('Phone number - ', person['Phone_No'])
print('Ticket Prize - ', '$', person['Ticket_prize'])
else:
print()
print('---**--- Vacant seat ---**---')
else:
print()
print('*** Invalid Input ***')
print()
else:
print()
print('*** Invalid Input ***')
print()
(i want To add Admin login panal and Customer login panel. How to do it??. also i want seperate things in Admin panal and customer panal, to Add first the 4 options into admin panal and Add First 2 options in Customer panal .. Thanks little help would be Very Helpfull <3

Getting the charge of a single atom, per loop in MD Analysis

I have been trying to use the partial charge of one particular ion to go through a calculation within mdanalysis.
I have tried(This is just a snippet from the code that I know is throwing the error):
Cl = u.select_atoms('resname CLA and prop z <= 79.14')
Lz = 79.14 #Determined from system set-up
Q_sum = 0
COM = 38.42979431152344 #Determined from VMD
file_object1 = open(fors, 'a')
print(dcd, file = file_object1)
for ts in u.trajectory[200:]:
frame = u.trajectory.frame
time = u.trajectory.time
for coord in Cl.positions:
q= Cl.total_charge(Cl.position[coord][2])
coords = coord - (Lz/COM)
q_prof = q * (coords + (Lz / 2)) / Lz
Q_sum = Q_sum + q_prof
print(q)
But I keep getting an error associated with this.
How would I go about selecting this particular atom as it goes through the loop to get the charge of it in MD Analysis? Before I was setting q to equal a constant and the code ran fine so I know it is only this line that is throwing the error:
q = Cl.total_charge(Cl.position[coord][2])
Thanks for the help!
I figured it out with:
def Q_code(dcd, topo):
Lz = u.dimensions[2]
Q_sum = 0
count = 0
CLAs = u.select_atoms('segid IONS or segid PROA or segid PROB or segid MEMB')
ini_frames = -200
n_frames = len(u.trajectory[ini_frames:])
for ts in u.trajectory[ini_frames:]:
count += 1
membrane = u.select_atoms('segid PROA or segid PROB or segid MEMB')
COM = membrane.atoms.center_of_mass()[2]
q_prof = CLAs.atoms.charges * (CLAs.positions[:,2] + (Lz/2 - COM))/Lz
Q_instant = np.sum(q_prof)
Q_sum += Q_instant
Q_av = Q_sum / n_frames
with open('Q_av.txt', 'a') as f:
print('The Q_av for {} is {}'.format(s, Q_av), file = f)
return Q_av

Passing python list in hive query as parameters

from tkinter import *
import pyodbc
with pyodbc.connect("DSN=ffff", autocommit=True) as conn:
df2 = pd.read_sql("SELECT * FROM holdingsummarysaaas", conn)
list46 = []
for md in df2['clientcode']:
list46.append(md)
print(list46)
result = []
for i in list46:
if i not in result:
result.append(i)
print(result)
#list_no_nan = [x for x in result if pd.notnull(x)]
#print(list_no_nan)
#select name from studens where id in (%s)" % ",".join(map(str,mylist)
#def fun():
num1 = Entry(root)
blank = Entry(root)
Ans = (num1.get())
blank.insert(0, Ans)
if Ans in result:
df2 = pd.read_sql('SELECT * FROM holdingsummary where ' + ' or '.join(('clientcode = '
+ str(n) for n in result)),conn)
#df2 = pd.read_sql("SELECT * FROM holdingsummary where clientcode = '" + Ans + "'",
conn)
print(df2)
I am taking unique clientcodes from database and I want user input which is in fun
function should access the results list(unique clientcode )check each clientcode from list
and check whether entered clientcode if same in result list then open that clientcode.
for eg:
Ans=='100014'
#df2 = pd.read_sql("SELECT * FROM holdingsummarysaaas where clientcode = '100014', conn)

Calculate Percentile Ranks by Group using Numpy

I'm very new with Python, and I want to calculate percentile ranks by group. My group is wildlife management unit (WMU - string), and ranks are based the value of predicted moose density (PMDEN3 - FLOAT). The rank value goes into the field RankMD.
My approach was to use the for loop to calculate the 3 ranks within each WMU, but the result is that 3 ranks are created for the entire dbf file (about 23,000 records), without respect to WMU. Any help is much appreciated.
import arcpy
import numpy as np
input = r'K:\Moose\KrigStratPython\TestRank3.dbf'
arr = arcpy.da.TableToNumPyArray(input, ('PMDEN3', 'Wmu'))
c_arr = [float(x[0]) for x in np.ndarray.flatten(arr)]
for Wmu in arr:
##to create 3 rank for example
p1 = np.percentile(c_arr, 33) # rank = 0
p2 = np.percentile(c_arr, 67) # rank = 1
p3 = np.percentile(c_arr, 100) # rank = 2
#use cursor to update the new rank field
with arcpy.da.UpdateCursor(input , ['PMDEN3','RankMD']) as cursor:
for row in cursor:
if row[0] < p1:
row[1] = 0 #rank 0
elif p1 <= row[0] and row[0] < p2:
row[1] = 1
else:
row[1] = 2
cursor.updateRow(row)
Your for loop is correct, however, your UpdateCursor is iterating over all rows in the table. To get your desired result you need to select out a subset of the table, and then use the update cursor on that. You can do this by passing a query to the where_clause parameter of the UpdateCursor function.
So you would have a query like this:
current_wmu = WMU['wmu'] # This should be the value of the wmu that the for loop is currently on I think it would be WMU['wmu'] but i'm not positive
where_clause = "WMU = '{}'".format(current_wmu) # format the above variable into a query string
and then your UpdateCursor would now be:
with arcpy.da.UpdateCursor(input , ['PMDEN3','RankMD'], where_clause) as cursor:
Based on suggestion from BigGerman, I revised my code and this is now working. Script loops through each WMU value, and calculates rank percentile within each group based on PMDEN. To improve the script I should create an array of WMU values from my input file rather than manually creating the array.
import arcpy
import numpy as np
#fields to be calculated
fldPMDEN = "PMDEN"
fldRankWMU = "RankWMU"
input = r'K:\Moose\KrigStratPython\TestRank3.dbf'
arcpy.MakeFeatureLayer_management(input, "stratLayerShpNoNullsLyr")
WMUs = ["10", "11A", "11B", "11Q", "12A"]
for current_wmu in WMUs:
##to create 3 rank for example
where_clause = "Wmu = '{}'".format(current_wmu) # format the above variable into a query
with arcpy.da.UpdateCursor("stratLayerShpNoNullsLyr", [fldPMDEN,fldRankWMU], where_clause) as cursor:
arr1 = arcpy.da.TableToNumPyArray("stratLayerShpNoNullsLyr", [fldPMDEN,fldRankWMU], where_clause)
c_arrS = [float(x[0]) for x in np.ndarray.flatten(arr1)]
p1 = np.percentile(c_arrS, 33) # rank = 3
p2 = np.percentile(c_arrS, 67) # rank = 2
p3 = np.percentile(c_arrS, 100) # rank = 1 (highest density)
for row in cursor:
if row[0] < p1:
row[1] = 3 #rank 0
elif p1 <= row[0] and row[0] < p2:
row[1] = 2
else:
row[1] = 1
cursor.updateRow(row)

Error on adding a number into a table

i want to get the date of this website and i can get it but it returns an error adding to the column.
Print: http://prntscr.com/fsav5h
Code:
page = urllib2.urlopen('https://www.meetup.com/find/events/career-business/?allMeetups=false&radius=50&userFreeform=London&mcId=c1012717&change=yes')
soup = BeautifulSoup(page, 'html.parser')
events = soup.find('div', class_='unit size5of7 ')
A = []
try:
conn = psycopg2.connect("dbname='meetup' user='postgres' host='localhost' password='root'")
except:
print 'Unable to connect to the database.'
cur = conn.cursor()
for event in events.findAll('ul', class_="searchResults resetList clearfix"):
date = event.findAll('li', class_="date-indicator")
if len(date) != 0:
A.append(date[0].find(text = True))
cur.execute("""UPDATE events SET event_date = %s WHERE event_date = '' """ % tuple(A) )
conn.commit()
del A[:]
Try this
cur.execute("""UPDATE events SET event_date = '%s' WHERE event_date = '' """, (tuple(A)))