How to use test_move method in keyboard

Best Python code snippet using keyboard

test_account_move_entry.py

Source:test_account_move_entry.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from odoo.addons.account.tests.invoice_test_common import InvoiceTestCommon3from odoo.tests import tagged, new_test_user4from odoo import fields5from odoo.exceptions import ValidationError, UserError6@tagged('post_install', '-at_install')7class TestAccountMove(InvoiceTestCommon):8 @classmethod9 def setUpClass(cls):10 super(TestAccountMove, cls).setUpClass()11 tax_repartition_line = cls.company_data['default_tax_sale'].invoice_repartition_line_ids\12 .filtered(lambda line: line.repartition_type == 'tax')13 cls.test_move = cls.env['account.move'].create({14 'type': 'entry',15 'date': fields.Date.from_string('2016-01-01'),16 'line_ids': [17 (0, None, {18 'name': 'revenue line 1',19 'account_id': cls.company_data['default_account_revenue'].id,20 'debit': 500.0,21 'credit': 0.0,22 }),23 (0, None, {24 'name': 'revenue line 2',25 'account_id': cls.company_data['default_account_revenue'].id,26 'debit': 1000.0,27 'credit': 0.0,28 'tax_ids': [(6, 0, cls.company_data['default_tax_sale'].ids)],29 }),30 (0, None, {31 'name': 'tax line',32 'account_id': cls.company_data['default_account_tax_sale'].id,33 'debit': 150.0,34 'credit': 0.0,35 'tax_repartition_line_id': tax_repartition_line.id,36 }),37 (0, None, {38 'name': 'counterpart line',39 'account_id': cls.company_data['default_account_expense'].id,40 'debit': 0.0,41 'credit': 1650.0,42 }),43 ]44 })45 def test_custom_currency_on_account_1(self):46 custom_account = self.company_data['default_account_revenue'].copy()47 # The currency set on the account is not the same as the one set on the company.48 # It should raise an error.49 custom_account.currency_id = self.currency_data['currency']50 with self.assertRaises(UserError), self.cr.savepoint():51 self.test_move.line_ids[0].account_id = custom_account52 # The currency set on the account is the same as the one set on the company.53 # It should not raise an error.54 custom_account.currency_id = self.company_data['currency']55 self.test_move.line_ids[0].account_id = custom_account56 def test_misc_fiscalyear_lock_date_1(self):57 self.test_move.post()58 # Set the lock date after the journal entry date.59 self.test_move.company_id.fiscalyear_lock_date = fields.Date.from_string('2017-01-01')60 # lines[0] = 'counterpart line'61 # lines[1] = 'tax line'62 # lines[2] = 'revenue line 1'63 # lines[3] = 'revenue line 2'64 lines = self.test_move.line_ids.sorted('debit')65 # Try to edit a line not affecting the taxes.66 with self.assertRaises(UserError), self.cr.savepoint():67 self.test_move.write({68 'line_ids': [69 (1, lines[0].id, {'credit': lines[0].credit + 100.0}),70 (1, lines[2].id, {'debit': lines[2].debit + 100.0}),71 ],72 })73 # Try to edit the account of a line.74 with self.assertRaises(UserError), self.cr.savepoint():75 self.test_move.line_ids[0].write({'account_id': self.test_move.line_ids[0].account_id.copy().id})76 # Try to edit a line.77 with self.assertRaises(UserError), self.cr.savepoint():78 self.test_move.write({79 'line_ids': [80 (1, lines[0].id, {'credit': lines[0].credit + 100.0}),81 (1, lines[3].id, {'debit': lines[3].debit + 100.0}),82 ],83 })84 # Try to add a new tax on a line.85 with self.assertRaises(UserError), self.cr.savepoint():86 self.test_move.write({87 'line_ids': [88 (1, lines[2].id, {'tax_ids': [(6, 0, self.company_data['default_tax_purchase'].ids)]}),89 ],90 })91 # Try to create a new line.92 with self.assertRaises(UserError), self.cr.savepoint():93 self.test_move.write({94 'line_ids': [95 (1, lines[0].id, {'credit': lines[0].credit + 100.0}),96 (0, None, {97 'name': 'revenue line 1',98 'account_id': self.company_data['default_account_revenue'].id,99 'debit': 100.0,100 'credit': 0.0,101 }),102 ],103 })104 # You can't remove the journal entry from a locked period.105 with self.assertRaises(UserError), self.cr.savepoint():106 self.test_move.date = fields.Date.from_string('2018-01-01')107 with self.assertRaises(UserError), self.cr.savepoint():108 self.test_move.unlink()109 with self.assertRaises(UserError), self.cr.savepoint():110 self.test_move.button_draft()111 copy_move = self.test_move.copy()112 # Try to add a new journal entry prior to the lock date.113 with self.assertRaises(UserError), self.cr.savepoint():114 copy_move.post()115 # You can change the date as the journal entry is not posted.116 copy_move.date = fields.Date.from_string('2018-01-01')117 copy_move.post()118 # You can't change the date to one being in a locked period.119 with self.assertRaises(UserError), self.cr.savepoint():120 copy_move.date = fields.Date.from_string('2017-01-01')121 def test_misc_tax_lock_date_1(self):122 self.test_move.post()123 # Set the tax lock date after the journal entry date.124 self.test_move.company_id.tax_lock_date = fields.Date.from_string('2017-01-01')125 # lines[0] = 'counterpart line'126 # lines[1] = 'tax line'127 # lines[2] = 'revenue line 1'128 # lines[3] = 'revenue line 2'129 lines = self.test_move.line_ids.sorted('debit')130 # Try to edit a line not affecting the taxes.131 self.test_move.write({132 'line_ids': [133 (1, lines[0].id, {'credit': lines[0].credit + 100.0}),134 (1, lines[2].id, {'debit': lines[2].debit + 100.0}),135 ],136 })137 # Try to edit the account of a line.138 self.test_move.line_ids[0].write({'account_id': self.test_move.line_ids[0].account_id.copy().id})139 # Try to edit a line having some taxes.140 with self.assertRaises(UserError), self.cr.savepoint():141 self.test_move.write({142 'line_ids': [143 (1, lines[0].id, {'credit': lines[0].credit + 100.0}),144 (1, lines[3].id, {'debit': lines[3].debit + 100.0}),145 ],146 })147 # Try to add a new tax on a line.148 with self.assertRaises(UserError), self.cr.savepoint():149 self.test_move.write({150 'line_ids': [151 (1, lines[2].id, {'tax_ids': [(6, 0, self.company_data['default_tax_purchase'].ids)]}),152 ],153 })154 # Try to edit a tax line.155 with self.assertRaises(UserError), self.cr.savepoint():156 self.test_move.write({157 'line_ids': [158 (1, lines[0].id, {'credit': lines[0].credit + 100.0}),159 (1, lines[1].id, {'debit': lines[1].debit + 100.0}),160 ],161 })162 # Try to create a line not affecting the taxes.163 self.test_move.write({164 'line_ids': [165 (1, lines[0].id, {'credit': lines[0].credit + 100.0}),166 (0, None, {167 'name': 'revenue line 1',168 'account_id': self.company_data['default_account_revenue'].id,169 'debit': 100.0,170 'credit': 0.0,171 }),172 ],173 })174 # Try to create a line affecting the taxes.175 with self.assertRaises(UserError), self.cr.savepoint():176 self.test_move.write({177 'line_ids': [178 (1, lines[0].id, {'credit': lines[0].credit + 100.0}),179 (0, None, {180 'name': 'revenue line 2',181 'account_id': self.company_data['default_account_revenue'].id,182 'debit': 1000.0,183 'credit': 0.0,184 'tax_ids': [(6, 0, self.company_data['default_tax_sale'].ids)],185 }),186 ],187 })188 # You can't remove the journal entry from a locked period.189 with self.assertRaises(UserError), self.cr.savepoint():190 self.test_move.date = fields.Date.from_string('2018-01-01')191 with self.assertRaises(UserError), self.cr.savepoint():192 self.test_move.unlink()193 with self.assertRaises(UserError), self.cr.savepoint():194 self.test_move.button_draft()195 copy_move = self.test_move.copy()196 # /!\ The date is changed automatically to the next available one during the post.197 copy_move.post()198 # You can't change the date to one being in a locked period.199 with self.assertRaises(UserError), self.cr.savepoint():200 copy_move.date = fields.Date.from_string('2017-01-01')201 def test_misc_draft_reconciled_entries_1(self):202 draft_moves = self.env['account.move'].create([203 {204 'type': 'entry',205 'line_ids': [206 (0, None, {207 'name': 'move 1 receivable line',208 'account_id': self.company_data['default_account_receivable'].id,209 'debit': 1000.0,210 'credit': 0.0,211 }),212 (0, None, {213 'name': 'move 1 counterpart line',214 'account_id': self.company_data['default_account_expense'].id,215 'debit': 0.0,216 'credit': 1000.0,217 }),218 ]219 },220 {221 'type': 'entry',222 'line_ids': [223 (0, None, {224 'name': 'move 2 receivable line',225 'account_id': self.company_data['default_account_receivable'].id,226 'debit': 0.0,227 'credit': 2000.0,228 }),229 (0, None, {230 'name': 'move 2 counterpart line',231 'account_id': self.company_data['default_account_expense'].id,232 'debit': 2000.0,233 'credit': 0.0,234 }),235 ]236 },237 ])238 # lines[0] = 'move 2 receivable line'239 # lines[1] = 'move 1 counterpart line'240 # lines[2] = 'move 1 receivable line'241 # lines[3] = 'move 2 counterpart line'242 lines = draft_moves.mapped('line_ids').sorted('balance')243 (lines[0] + lines[2]).reconcile()244 draft_moves.flush()245 self.cr.execute('SAVEPOINT test_misc_draft_reconciled_entries_1')246 with self.assertRaises(UserError):247 draft_moves[0].write({248 'line_ids': [249 (1, lines[1].id, {'credit': lines[1].credit + 100.0}),250 (1, lines[2].id, {'debit': lines[2].debit + 100.0}),251 ]252 })253 with self.assertRaises(UserError):254 draft_moves.unlink()255 draft_moves.flush()256 draft_moves.invalidate_cache()257 self.cr.execute('ROLLBACK TO SAVEPOINT test_misc_draft_reconciled_entries_1')258 def test_misc_unique_sequence_number(self):259 ''' Ensure two journal entries can't share the same name when using the same sequence. '''260 self.test_move.post()261 # Edit the sequence to force the next move to get the same name.262 self.test_move.journal_id\263 .sequence_id.date_range_ids\264 .filtered(lambda seq: seq.date_from == fields.Date.from_string('2016-01-01')).number_next -= 1265 test_move2 = self.test_move.copy()266 with self.assertRaises(ValidationError):267 test_move2.post()268 def test_add_followers_on_post(self):269 # Add some existing partners, some from another company270 company = self.env['res.company'].create({'name': 'Oopo'})271 existing_partners = self.env['res.partner'].create([{272 'name': 'Jean',273 'company_id': company.id,274 },{275 'name': 'Paulus',276 }])277 self.test_move.message_subscribe(existing_partners.ids)278 user = new_test_user(self.env, login='jag', groups='account.group_account_invoice')279 move = self.test_move.with_user(user)280 partner = self.env['res.partner'].create({'name': 'Belouga'})281 commercial_partner = self.env['res.partner'].create({'name': 'Rorqual'})282 move.partner_id = partner283 move.commercial_partner_id = commercial_partner284 move.post()...

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 keyboard 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