mirror of
https://gitlab.com/datalifeit/trytond-staff_profile
synced 2023-12-14 04:32:57 +01:00
Improve script to fill payroll cost price
This commit is contained in:
parent
c14119a4ea
commit
7988ab8cb2
|
@ -10,6 +10,8 @@ def parse_commandline():
|
|||
default=None, help="specify config file")
|
||||
parser.add_argument("-d", "--database", dest="database_name", default=None,
|
||||
metavar='DATABASE', help="specify the database name")
|
||||
parser.add_argument("-l", "--limit", dest="limit", default=None,
|
||||
metavar='LIMIT', help="specify the limit number of records")
|
||||
options = parser.parse_args()
|
||||
|
||||
if not options.configfile:
|
||||
|
@ -41,10 +43,20 @@ if __name__ == '__main__':
|
|||
line_table = Line.__table__()
|
||||
cursor = Transaction().connection.cursor()
|
||||
print('>>> START')
|
||||
lines = Line.search([('employee', '!=', None)])
|
||||
res = {l.id: l.employee.compute_payroll_price(l.date) for l in lines}
|
||||
for id_, value in res.items():
|
||||
cursor.execute(*line_table.update(
|
||||
[line_table.payroll_cost_price], [value],
|
||||
where=(line_table.id == id_)))
|
||||
while True:
|
||||
lines = Line.search([
|
||||
('payroll_cost_price', '=', None),
|
||||
('employee', '!=', None)],
|
||||
order=[('date', 'DESC')],
|
||||
limit=options.limit)
|
||||
if not lines:
|
||||
break
|
||||
res = {l.id: l.employee.compute_payroll_price(l.date)
|
||||
for l in lines}
|
||||
for id_, value in res.items():
|
||||
cursor.execute(*line_table.update(
|
||||
[line_table.payroll_cost_price], [value],
|
||||
where=(line_table.id == id_)))
|
||||
Transaction().commit()
|
||||
print('>>> END ITERATION')
|
||||
print('>>> END')
|
||||
|
|
Loading…
Reference in a new issue