def _create_basic_config(self): new_config = Form(self.env['pos.config']) new_config.name = 'PoS Shop Test' new_config.module_account = True new_config.invoice_journal_id = self.invoice_journal new_config.journal_id = self.pos_sale_journal new_config.available_pricelist_ids.clear() new_config.available_pricelist_ids.add(self.currency_pricelist) new_config.pricelist_id = self.currency_pricelist config = new_config.save() cash_journal = config.payment_method_ids.filtered( lambda pm: pm.is_cash_count)[:1].cash_journal_id cash_split_pm = self.env['pos.payment.method'].create({ 'name': 'Split (Cash) PM', 'receivable_account_id': self.pos_receivable_account.id, 'split_transactions': True, 'is_cash_count': True, 'cash_journal_id': cash_journal.id, }) config.write({'payment_method_ids': [(4, cash_split_pm.id, 0)]}) return config
def create_payment(self, invoices): payment_register = Form(self.env['account.payment'].with_context(active_model='account.move', active_ids=invoices.ids)) payment_register.payment_date = time.strftime('%Y') + '-07-15' payment_register.journal_id = self.bank_journal payment_register.payment_method_id = self.payment_method_check payment = payment_register.save() payment.post() return payment
def _init_payment(cls, payment_type, partner_type=None): payment_form = Form(cls.env['account.payment']) payment_form.journal_id = cls.bank_journal payment_form.payment_date = fields.Date.from_string('2019-01-01') payment_form.amount = 100 if payment_type == 'transfer': payment_form.destination_journal_id = cls.cash_journal else: payment_form.partner_type = partner_type payment_form.partner_id = cls.partner_a payment_form.payment_type = payment_type return payment_form.save()
def test_out_refund_line_onchange_currency_1(self): # New journal having a foreign currency set. journal = self.company_data['default_journal_sale'].copy() journal.currency_id = self.currency_data['currency'] move_form = Form(self.invoice) move_form.journal_id = journal move_form.save() self.assertInvoiceValues( self.invoice, [ { **self.product_line_vals_1, 'currency_id': journal.currency_id.id, 'amount_currency': 1000.0, 'debit': 500.0, }, { **self.product_line_vals_2, 'currency_id': journal.currency_id.id, 'amount_currency': 200.0, 'debit': 100.0, }, { **self.tax_line_vals_1, 'currency_id': journal.currency_id.id, 'amount_currency': 180.0, 'debit': 90.0, }, { **self.tax_line_vals_2, 'currency_id': journal.currency_id.id, 'amount_currency': 30.0, 'debit': 15.0, }, { **self.term_line_vals_1, 'currency_id': journal.currency_id.id, 'amount_currency': -1410.0, 'credit': 705.0, }, ], { **self.move_vals, 'currency_id': journal.currency_id.id, 'journal_id': journal.id, }) move_form = Form(self.invoice) # Change the date to get another rate: 1/3 instead of 1/2. move_form.date = fields.Date.from_string('2016-01-01') move_form.save() self.assertInvoiceValues( self.invoice, [ { **self.product_line_vals_1, 'currency_id': journal.currency_id.id, 'amount_currency': 1000.0, 'debit': 333.33, }, { **self.product_line_vals_2, 'currency_id': journal.currency_id.id, 'amount_currency': 200.0, 'debit': 66.67, }, { **self.tax_line_vals_1, 'currency_id': journal.currency_id.id, 'amount_currency': 180.0, 'debit': 60.0, }, { **self.tax_line_vals_2, 'currency_id': journal.currency_id.id, 'amount_currency': 30.0, 'debit': 10.0, }, { **self.term_line_vals_1, 'currency_id': journal.currency_id.id, 'amount_currency': -1410.0, 'credit': 470.0, }, ], { **self.move_vals, 'currency_id': journal.currency_id.id, 'journal_id': journal.id, 'date': fields.Date.from_string('2016-01-01'), }) move_form = Form(self.invoice) with move_form.invoice_line_ids.edit(0) as line_form: # 0.045 * 0.1 = 0.0045. As the foreign currency has a 0.001 rounding, # the result should be 0.005 after rounding. line_form.quantity = 0.1 line_form.price_unit = 0.045 move_form.save() self.assertInvoiceValues( self.invoice, [ { **self.product_line_vals_1, 'quantity': 0.1, 'price_unit': 0.05, 'price_subtotal': 0.005, 'price_total': 0.006, 'currency_id': journal.currency_id.id, 'amount_currency': 0.005, 'debit': 0.0, }, { **self.product_line_vals_2, 'currency_id': journal.currency_id.id, 'amount_currency': 200.0, 'debit': 66.67, }, { **self.tax_line_vals_1, 'price_unit': 30.0, 'price_subtotal': 30.001, 'price_total': 30.001, 'currency_id': journal.currency_id.id, 'amount_currency': 30.001, 'debit': 10.0, }, { **self.tax_line_vals_2, 'currency_id': journal.currency_id.id, 'amount_currency': 30.0, 'debit': 10.0, }, { **self.term_line_vals_1, 'currency_id': journal.currency_id.id, 'price_unit': -260.01, 'price_subtotal': -260.006, 'price_total': -260.006, 'amount_currency': -260.006, 'credit': 86.67, }, ], { **self.move_vals, 'currency_id': journal.currency_id.id, 'journal_id': journal.id, 'date': fields.Date.from_string('2016-01-01'), 'amount_untaxed': 200.005, 'amount_tax': 60.001, 'amount_total': 260.006, }) # The journal forces you to provide a secondary currency. with self.assertRaises(UserError), self.cr.savepoint(): move_form = Form(self.invoice) move_form.currency_id = self.company_data['currency'] move_form.save() # Exit the multi-currencies. journal.currency_id = False move_form = Form(self.invoice) move_form.currency_id = self.company_data['currency'] move_form.save() self.assertInvoiceValues( self.invoice, [ { **self.product_line_vals_1, 'quantity': 0.1, 'price_unit': 0.1, 'price_subtotal': 0.01, 'price_total': 0.01, 'debit': 0.01, }, self.product_line_vals_2, { **self.tax_line_vals_1, 'price_unit': 30.0, 'price_subtotal': 30.0, 'price_total': 30.0, 'debit': 30.0, }, self.tax_line_vals_2, { **self.term_line_vals_1, 'price_unit': -260.01, 'price_subtotal': -260.01, 'price_total': -260.01, 'credit': 260.01, }, ], { **self.move_vals, 'currency_id': self.company_data['currency'].id, 'journal_id': journal.id, 'date': fields.Date.from_string('2016-01-01'), 'amount_untaxed': 200.01, 'amount_tax': 60.0, 'amount_total': 260.01, })
def test_onchange_taxes_2(self): ''' Test the amount of tax account.move.line is adapted when editing the account.move.line amount. This test uses the following scenario: - Create manually a debit line of 1000 having a tax. - Assume a line containing the tax amount is created automatically. - Set the debit amount to 2000 in the first created line. - Assume the line containing the tax amount has been updated automatically. - Create manually a credit line to balance the two previous lines. - Save the move. tax = 10% Name | Debit | Credit | Tax_ids | Tax_line_id's name ----------------|-----------|-----------|---------------|------------------- debit_line_1 | 2000 | | tax | tax_line | 200 | | | tax_line debit_line_1 | | 2200 | | ''' move_form = Form(self.env['account.move'], view='account.view_move_form') move_form.ref = 'azerty' move_form.journal_id = self.journal # Create a new account.move.line with debit amount. with move_form.line_ids.new() as debit_line: debit_line.name = 'debit_line_1' debit_line.account_id = self.account debit_line.debit = 1000 debit_line.tax_ids.clear() debit_line.tax_ids.add(self.percent_tax) self.assertTrue(debit_line.recompute_tax_line) debit_line.debit = 2000 self.assertTrue(debit_line.recompute_tax_line) # Create a third account.move.line with credit amount. with move_form.line_ids.new() as credit_line: credit_line.name = 'credit_line_1' credit_line.account_id = self.account credit_line.credit = 2200 move = move_form.save() self.assertRecordValues(move.line_ids, [ { 'name': 'credit_line_1', 'debit': 0.0, 'credit': 2200.0, 'tax_ids': [], 'tax_line_id': False }, { 'name': 'tax_line', 'debit': 200.0, 'credit': 0.0, 'tax_ids': [], 'tax_line_id': self.percent_tax.id }, { 'name': 'debit_line_1', 'debit': 2000.0, 'credit': 0.0, 'tax_ids': [self.percent_tax.id], 'tax_line_id': False }, ])
def test_onchange_taxes_3(self): ''' Test the amount of tax account.move.line is still editable manually. Test the amount of tax account.move.line is cumulative for the same tax. This test uses the following scenario: - Create manually a debit line of 1000 having a tax. - Assume a line containing the tax amount is created automatically. - Edit the tax line amount of the auto-generated line by adding 5. - Create manually a credit line to balance the two previous lines. - Save the move. - Edit the move. - Create manually a debit line of 2000 having the same tax. - Assume the line containing the tax amount has been updated (no new line created). - Create manually a credit line to balance the four previous lines. - Save the move. tax = 10% Name | Debit | Credit | Tax_ids | Tax_line_id's name ----------------|-----------|-----------|---------------|------------------- debit_line_1 | 1000 | | tax | tax_line | 300 | | | tax_line credit_line_1 | | 1105 | | debit_line_2 | 2000 | | tax | credit_line_2 | | 2195 | | ''' move_form = Form(self.env['account.move'], view='account.view_move_form') move_form.ref = 'azerty' move_form.journal_id = self.journal # Create a new account.move.line with debit amount. with move_form.line_ids.new() as debit_line: debit_line.name = 'debit_line_1' debit_line.account_id = self.account debit_line.debit = 1000 debit_line.tax_ids.clear() debit_line.tax_ids.add(self.percent_tax) self.assertTrue(debit_line.recompute_tax_line) # Edit the tax account.move.line with move_form.line_ids.edit(index=1) as tax_line: tax_line.debit = 105 # Was 100 # Create a third account.move.line with credit amount. with move_form.line_ids.new() as credit_line: credit_line.name = 'credit_line_1' credit_line.account_id = self.account credit_line.credit = 1105 move = move_form.save() move_form = Form(move, view='account.view_move_form') # Create a new account.move.line with debit amount. with move_form.line_ids.new() as debit_line2: debit_line2.name = 'debit_line_2' debit_line2.account_id = self.account debit_line2.debit = 2000 debit_line2.tax_ids.clear() debit_line2.tax_ids.add(self.percent_tax) self.assertTrue(debit_line2.recompute_tax_line) with move_form.line_ids.new() as credit_line2: credit_line2.name = 'credit_line_2' credit_line2.account_id = self.account credit_line2.credit = 2195 move = move_form.save() self.assertRecordValues(move.line_ids, [ { 'name': 'credit_line_2', 'debit': 0.0, 'credit': 2195.0, 'tax_ids': [], 'tax_line_id': False }, { 'name': 'debit_line_2', 'debit': 2000.0, 'credit': 0.0, 'tax_ids': [self.percent_tax.id], 'tax_line_id': False }, { 'name': 'credit_line_1', 'debit': 0.0, 'credit': 1105.0, 'tax_ids': [], 'tax_line_id': False }, { 'name': 'tax_line', 'debit': 300.0, 'credit': 0.0, 'tax_ids': [], 'tax_line_id': self.percent_tax.id }, { 'name': 'debit_line_1', 'debit': 1000.0, 'credit': 0.0, 'tax_ids': [self.percent_tax.id], 'tax_line_id': False }, ])
def _create_other_currency_config(self): (self.other_currency.rate_ids | self.company_currency.rate_ids).unlink() self.env['res.currency.rate'].create({ 'rate': 0.5, 'currency_id': self.other_currency.id, }) other_cash_journal = self.env['account.journal'].create({ 'name': 'Cash Other', 'type': 'cash', 'company_id': self.company.id, 'code': 'CSHO', 'sequence': 10, 'currency_id': self.other_currency.id }) other_invoice_journal = self.env['account.journal'].create({ 'name': 'Customer Invoice Other', 'type': 'sale', 'company_id': self.company.id, 'code': 'INVO', 'sequence': 11, 'currency_id': self.other_currency.id }) other_sales_journal = self.env['account.journal'].create({ 'name': 'PoS Sale Other', 'type': 'sale', 'code': 'POSO', 'company_id': self.company.id, 'sequence': 12, 'currency_id': self.other_currency.id }) other_pricelist = self.env['product.pricelist'].create({ 'name': 'Public Pricelist Other', 'currency_id': self.other_currency.id, }) other_cash_payment_method = self.env['pos.payment.method'].create({ 'name': 'Cash Other', 'receivable_account_id': self.pos_receivable_account.id, 'is_cash_count': True, 'cash_journal_id': other_cash_journal.id, }) other_bank_payment_method = self.env['pos.payment.method'].create({ 'name': 'Bank Other', 'receivable_account_id': self.pos_receivable_account.id, }) new_config = Form(self.env['pos.config']) new_config.name = 'Shop Other' new_config.invoice_journal_id = other_invoice_journal new_config.journal_id = other_sales_journal new_config.use_pricelist = True new_config.available_pricelist_ids.clear() new_config.available_pricelist_ids.add(other_pricelist) new_config.pricelist_id = other_pricelist new_config.payment_method_ids.clear() new_config.payment_method_ids.add(other_cash_payment_method) new_config.payment_method_ids.add(other_bank_payment_method) config = new_config.save() return config