How to use update_amount method in avocado

Best Python code snippet using avocado_python

progress.py

Source:progress.py Github

copy

Full Screen

...31 self.span = maxValue - minValue32 self.width = totalWidth33 self.amount = 0 # When amount == max, we are 100% done 34 self.autoreturn = autoreturn35 self.update_amount(0) # Build progress bar string36 def update_amount(self, newAmount=0):37 if newAmount < self.min: newAmount = self.min38 if newAmount > self.max: newAmount = self.max39 self.amount = newAmount40 # Figure out the new percent done, round to an integer41 diffFromMin = float(self.amount - self.min)42 try:43 percentDone = (diffFromMin / float(self.span)) * 100.044 except ZeroDivisionError:45 percentDone = 10046 percentDone = int(percentDone)47 # Figure out how many hash bars the percentage should be48 allFull = self.width - 249 numHashes = (percentDone / 100.0) * allFull50 numHashes = int(round(numHashes))51 # build a progress bar with hashes and spaces52 self.progBar = "[" + '=' * numHashes + ' ' * (allFull - numHashes) + "]"53 # figure out where to put the percentage, roughly centered54 percentPlace = (len(self.progBar) / 2.0) - len(str(percentDone)) 55 percentPlace = int(percentPlace)56 percentString = " %s%% " % percentDone57 # slice the percentage into the bar58 self.progBar = ''.join((self.progBar[0:percentPlace], 59 percentString,60 self.progBar[percentPlace+len(percentString):]))61 if self.autoreturn:62 self.progBar = '\r' + self.progBar63 def __str__(self):64 return str(self.progBar)65 def display(self, stream=sys.stdout):66 stream.write(str(self))67 stream.flush()68 def finish(self, stream=sys.stdout):69 stream.write('\r' + ' ' * self.width + '\r')70 stream.flush()71def autoprogressbar(seq, **progressbar_params):72 """Returns an iterator over seq while displaying a progress bar of73 the appropriate length. Usage is simple:74 for x in autoprogressbar(some_seq):75 f(x)76 """77 length = len(seq)78 bar = ProgressBar(maxValue=length, **progressbar_params)79 for i, item in enumerate(seq):80 bar.update_amount(i)81 if i < length:82 bar.display()83 else:84 bar.finish()85 yield item86 bar.finish()87if __name__ == "__main__":88 import time, sys89 prog = ProgressBar(0, 100, 34, autoreturn=False)90 prog2 = ProgressBar(0, 100, 34)91 for i in range(1001):92 prog.update_amount(i / 10.0)93 prog2.update_amount(100 - (i / 5.0))94 sys.stdout.write("\r%s" % prog)95 sys.stdout.write("%s" % prog2)96 sys.stdout.flush()...

Full Screen

Full Screen

account_move_force_update.py

Source:account_move_force_update.py Github

copy

Full Screen

1from odoo import fields, models, api2class AccountMoveForceUpdateAmount(models.TransientModel):3 _name = "account.move.force.update.amount"4 def _default_account_move(self):5 if self._context.get('active_ids'):6 return self.env['account.move'].browse(self._context.get('active_ids'))7 account_moves = fields.Many2many('account.move',8 string="Record", required=True, default=_default_account_move)9 update_amount = fields.Float('New Amount', store=True, help='Update New Amount', digits=(16, 2))10 @api.model11 def default_get(self, fields):12 defaults = super(AccountMoveForceUpdateAmount, self).default_get(fields)13 default_account_move_id = self.env.context.get('default_account_move_id')14 if default_account_move_id:15 account_move_line = self.env['account.move.line'].sudo().search([('move_id', '=', default_account_move_id)])16 sample_update_amount = 017 for e in account_move_line:18 if e['debit'] is not None and e['debit'] > e['credit'] and sample_update_amount == 0:19 sample_update_amount = e['debit']20 defaults['update_amount'] = sample_update_amount21 return defaults22 def force_update_amount_now(self):23 self.env.cr.execute("""update account_move set amount_total_signed=%s where id=%s""",24 (self.update_amount, self.account_moves.id,))25 self.env.cr.execute(26 """update account_move_line set debit=%s,balance=%s where debit > credit and move_id=%s""",27 (self.update_amount, self.update_amount, self.account_moves.id,))28 self.env.cr.execute(29 """update account_move_line set credit=%s,balance=%s where credit > debit and move_id=%s""",30 (self.update_amount, -self.update_amount, self.account_moves.id,))31 self.env.cr.execute(32 """update account_move_line set amount_residual=%s where debit > credit and move_id=%s and amount_residual_currency>0""",33 (self.update_amount, self.account_moves.id,))34 self.env.cr.execute(35 """update account_move_line set amount_residual=%s where credit > debit and move_id=%s and amount_residual_currency<0""",36 (-self.update_amount, self.account_moves.id,))37 # attendee = self.env['calendar.attendee'].sudo().search([('partner_id', '=', self.env['res.users'].sudo().browse(38 # self._uid).partner_id.id), ('state', '!=', 'accepted'),39 # ('event_id', 'in', tuple(self.calendar_events.ids))])40 # if attendee:41 # attendee.do_accept()42 # return {'type': 'ir.actions.act_window_close'}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful