From 419d4bbee04763367fef675a01dc73afa9758b2f Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Wed, 29 Apr 2020 08:26:56 +0000 Subject: [PATCH] [IMP] account, *: Required currency on journal items closes odoo/odoo#50711 Task: 1930680 Related: odoo/enterprise#10394 Related: odoo/upgrade#1147 Signed-off-by: Cedric Snauwaert (csn) --- .../account/models/account_bank_statement.py | 49 +- addons/account/models/account_move.py | 428 ++++++------------ .../models/account_partial_reconcile.py | 45 +- addons/account/models/account_payment.py | 31 +- .../tests/test_account_bank_statement.py | 22 +- .../tests/test_account_move_in_invoice.py | 73 ++- .../tests/test_account_move_in_refund.py | 65 ++- .../tests/test_account_move_out_invoice.py | 111 +++-- .../tests/test_account_move_out_refund.py | 63 ++- .../test_account_move_payments_widget.py | 4 +- .../tests/test_account_move_reconcile.py | 30 +- addons/account/tests/test_account_payment.py | 63 +-- .../tests/test_account_payment_register.py | 48 +- addons/account/tests/test_reconciliation.py | 68 +-- addons/account/tests/test_transfer_wizard.py | 12 +- addons/account/views/account_move_views.xml | 6 +- .../wizard/account_automatic_entry_wizard.py | 21 +- addons/hr_expense/models/hr_expense.py | 43 +- addons/hr_expense/tests/test_expenses.py | 12 +- .../tests/test_pos_other_currency_config.py | 16 +- 20 files changed, 547 insertions(+), 663 deletions(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 8a130f60f4e..70f7a6d100b 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -566,23 +566,18 @@ class AccountBankStatementLine(models.Model): balance = self.amount_currency else: amount_currency = self.amount - balance = journal_currency._convert(amount_currency, journal.company_id.currency_id, journal.company_id, self.date) + balance = journal_currency._convert(amount_currency, company_currency, journal.company_id, self.date) elif self.foreign_currency_id and not journal_currency: - if self.foreign_currency_id == company_currency: - amount_currency = 0.0 - balance = self.amount - currency_id = False - else: - amount_currency = self.amount_currency - balance = self.amount - currency_id = self.foreign_currency_id.id + amount_currency = self.amount_currency + balance = self.amount + currency_id = self.foreign_currency_id.id elif not self.foreign_currency_id and journal_currency: currency_id = journal_currency.id amount_currency = self.amount balance = journal_currency._convert(amount_currency, journal.company_id.currency_id, journal.company_id, self.date) else: - currency_id = False - amount_currency = 0.0 + currency_id = company_currency.id + amount_currency = self.amount balance = self.amount return { @@ -685,8 +680,8 @@ class AccountBankStatementLine(models.Model): amount_currency = amounts[journal_currency.id] currency_id = journal_currency.id else: - amount_currency = 0.0 - currency_id = False + amount_currency = amounts[company_currency.id] + currency_id = company_currency.id return { **counterpart_vals, @@ -695,8 +690,8 @@ class AccountBankStatementLine(models.Model): 'partner_id': self.partner_id.id, 'currency_id': currency_id, 'account_id': counterpart_vals.get('account_id', move_line.account_id.id if move_line else False), - 'debit': balance if balance > 0 else 0.0, - 'credit': -balance if balance < 0 else 0.0, + 'debit': balance if balance > 0.0 else 0.0, + 'credit': -balance if balance < 0.0 else 0.0, 'amount_currency': amount_currency, } @@ -718,6 +713,12 @@ class AccountBankStatementLine(models.Model): liquidity_line_vals = self._prepare_liquidity_move_line_vals() + # Ensure the counterpart will have a balance exactly equals to the amount in journal currency. + # This avoid some rounding issues when the currency rate between two currencies is not symmetrical. + # E.g: + # A.convert(amount_a, B) = amount_b + # B.convert(amount_b, A) = amount_c != amount_a + counterpart_vals = { 'name': self.payment_ref, 'account_id': counterpart_account_id, @@ -772,15 +773,12 @@ class AccountBankStatementLine(models.Model): st_line.is_reconciled = True # Compute residual amount - st_line_currency = suspense_lines.currency_id or suspense_lines.company_currency_id - balance_field, residual_field = ('amount_currency', 'amount_residual_currency') if suspense_lines.currency_id else ('balance', 'amount_residual') - if st_line.to_check: st_line.amount_residual = -st_line.amount_currency if st_line.foreign_currency_id else -st_line.amount elif suspense_lines.account_id.reconcile: - st_line.amount_residual = sum(suspense_lines.mapped(residual_field)) + st_line.amount_residual = sum(suspense_lines.mapped('amount_residual_currency')) else: - st_line.amount_residual = sum(suspense_lines.mapped(balance_field)) + st_line.amount_residual = sum(suspense_lines.mapped('amount_currency')) # ------------------------------------------------------------------------- # CONSTRAINT METHODS @@ -921,14 +919,13 @@ class AccountBankStatementLine(models.Model): 'foreign_currency_id': False, }) - elif not suspense_lines.currency_id and st_line.foreign_currency_id == company_currency: + elif not journal_currency and suspense_lines.currency_id == company_currency: - # The suspense line has no foreign currency because the foreign currency set on the - # statement line is the same as the company one. In that case, don't erase the - # 'foreign_currency_id' field. + # Don't set a specific foreign currency on the statement line. st_line_vals_to_write.update({ - 'amount_currency': -suspense_lines.balance, + 'amount_currency': 0.0, + 'foreign_currency_id': False, }) else: @@ -1121,7 +1118,7 @@ class AccountBankStatementLine(models.Model): 'name': '%s: %s' % (self.payment_ref, _('Open Balance')), 'account_id': open_balance_account.id, 'balance': -total_balance, - 'currency_id': False, + 'currency_id': self.company_currency_id.id, }) else: open_balance_vals = None diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 340b652adc1..53b017c6b68 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -418,18 +418,15 @@ class AccountMove(models.Model): @api.onchange('date', 'currency_id') def _onchange_currency(self): - if not self.currency_id: - return - if self.is_invoice(include_receipts=True): - company_currency = self.company_id.currency_id - has_foreign_currency = self.currency_id and self.currency_id != company_currency + currency = self.currency_id or self.company_id.currency_id + if self.is_invoice(include_receipts=True): for line in self._get_lines_onchange_currency(): - new_currency = has_foreign_currency and self.currency_id - line.currency_id = new_currency + line.currency_id = currency line._onchange_currency() else: - self.line_ids._onchange_currency() + for line in self.line_ids: + line._onchange_currency() self._recompute_dynamic_lines(recompute_tax_base_amount=True) @@ -548,25 +545,18 @@ class AccountMove(models.Model): handle_price_include = True sign = -1 if move.is_inbound() else 1 quantity = base_line.quantity - if base_line.currency_id: - price_unit_foreign_curr = sign * base_line.price_unit * (1 - (base_line.discount / 100.0)) - price_unit_comp_curr = base_line.currency_id._convert(price_unit_foreign_curr, move.company_id.currency_id, move.company_id, move.date) - else: - price_unit_foreign_curr = 0.0 - price_unit_comp_curr = sign * base_line.price_unit * (1 - (base_line.discount / 100.0)) - tax_type = 'sale' if move.move_type.startswith('out_') else 'purchase' is_refund = move.move_type in ('out_refund', 'in_refund') + price_unit_wo_discount = sign * base_line.price_unit * (1 - (base_line.discount / 100.0)) else: handle_price_include = False quantity = 1.0 - price_unit_foreign_curr = base_line.amount_currency - price_unit_comp_curr = base_line.balance tax_type = base_line.tax_ids[0].type_tax_use if base_line.tax_ids else None is_refund = (tax_type == 'sale' and base_line.debit) or (tax_type == 'purchase' and base_line.credit) + price_unit_wo_discount = base_line.balance balance_taxes_res = base_line.tax_ids._origin.compute_all( - price_unit_comp_curr, - currency=base_line.company_currency_id, + price_unit_wo_discount, + currency=base_line.currency_id, quantity=quantity, product=base_line.product_id, partner=base_line.partner_id, @@ -583,36 +573,6 @@ class AccountMove(models.Model): for tax_res in balance_taxes_res['taxes']: tax_res['tag_ids'] = base_line._revert_signed_tags(self.env['account.account.tag'].browse(tax_res['tag_ids'])).ids - if base_line.currency_id: - # Multi-currencies mode: Taxes are computed both in company's currency / foreign currency. - amount_currency_taxes_res = base_line.tax_ids._origin.compute_all( - price_unit_foreign_curr, - currency=base_line.currency_id, - quantity=quantity, - product=base_line.product_id, - partner=base_line.partner_id, - is_refund=is_refund, - handle_price_include=handle_price_include, - ) - - if move.move_type == 'entry': - repartition_field = is_refund and 'refund_repartition_line_ids' or 'invoice_repartition_line_ids' - repartition_tags = base_line.tax_ids.mapped(repartition_field).filtered(lambda x: x.repartition_type == 'base').tag_ids - tags_need_inversion = (tax_type == 'sale' and not is_refund) or (tax_type == 'purchase' and is_refund) - if tags_need_inversion: - balance_taxes_res['base_tags'] = base_line._revert_signed_tags(repartition_tags).ids - for tax_res in balance_taxes_res['taxes']: - tax_res['tag_ids'] = base_line._revert_signed_tags(self.env['account.account.tag'].browse(tax_res['tag_ids'])).ids - - for b_tax_res, ac_tax_res in zip(balance_taxes_res['taxes'], amount_currency_taxes_res['taxes']): - tax = self.env['account.tax'].browse(b_tax_res['id']) - b_tax_res['amount_currency'] = ac_tax_res['amount'] - - # A tax having a fixed amount must be converted into the company currency when dealing with a - # foreign currency. - if tax.amount_type == 'fixed': - b_tax_res['amount'] = base_line.currency_id._convert(b_tax_res['amount'], move.company_id.currency_id, move.company_id, move.date) - return balance_taxes_res taxes_map = {} @@ -629,8 +589,7 @@ class AccountMove(models.Model): else: taxes_map[grouping_key] = { 'tax_line': line, - 'balance': 0.0, - 'amount_currency': 0.0, + 'amount': 0.0, 'tax_base_amount': 0.0, 'grouping_dict': False, } @@ -661,56 +620,66 @@ class AccountMove(models.Model): taxes_map_entry = taxes_map.setdefault(grouping_key, { 'tax_line': None, - 'balance': 0.0, - 'amount_currency': 0.0, + 'amount': 0.0, 'tax_base_amount': 0.0, 'grouping_dict': False, }) - taxes_map_entry['balance'] += tax_vals['amount'] - taxes_map_entry['amount_currency'] += tax_vals.get('amount_currency', 0.0) + taxes_map_entry['amount'] += tax_vals['amount'] taxes_map_entry['tax_base_amount'] += tax_vals['base'] taxes_map_entry['grouping_dict'] = grouping_dict line.tax_exigible = tax_exigible # ==== Process taxes_map ==== for taxes_map_entry in taxes_map.values(): - # Don't create tax lines with zero balance. - if self.currency_id.is_zero(taxes_map_entry['balance']) and self.currency_id.is_zero(taxes_map_entry['amount_currency']): - taxes_map_entry['grouping_dict'] = False - - tax_line = taxes_map_entry['tax_line'] - tax_base_amount = -taxes_map_entry['tax_base_amount'] if self.is_inbound() else taxes_map_entry['tax_base_amount'] - - if not tax_line and not taxes_map_entry['grouping_dict']: + # The tax line is no longer used in any base lines, drop it. + if taxes_map_entry['tax_line'] and not taxes_map_entry['grouping_dict']: + self.line_ids -= taxes_map_entry['tax_line'] continue - elif tax_line and recompute_tax_base_amount: - tax_line.tax_base_amount = tax_base_amount - elif tax_line and not taxes_map_entry['grouping_dict']: - # The tax line is no longer used, drop it. - self.line_ids -= tax_line - elif tax_line: - tax_line.update({ - 'amount_currency': taxes_map_entry['amount_currency'], - 'debit': taxes_map_entry['balance'] > 0.0 and taxes_map_entry['balance'] or 0.0, - 'credit': taxes_map_entry['balance'] < 0.0 and -taxes_map_entry['balance'] or 0.0, - 'tax_base_amount': tax_base_amount, - }) + + currency = self.env['res.currency'].browse(taxes_map_entry['grouping_dict']['currency_id']) + + # Don't create tax lines with zero balance. + if currency.is_zero(taxes_map_entry['amount']): + if taxes_map_entry['tax_line']: + self.line_ids -= taxes_map_entry['tax_line'] + continue + + tax_base_amount = (-1 if self.is_inbound() else 1) * taxes_map_entry['tax_base_amount'] + + # Recompute only the tax_base_amount. + if taxes_map_entry['tax_line'] and recompute_tax_base_amount: + taxes_map_entry['tax_line'].tax_base_amount = tax_base_amount + continue + + balance = currency._convert( + taxes_map_entry['amount'], + self.journal_id.company_id.currency_id, + self.journal_id.company_id, + self.date or fields.Date.context_today(self), + ) + to_write_on_line = { + 'amount_currency': taxes_map_entry['amount'], + 'currency_id': taxes_map_entry['grouping_dict']['currency_id'], + 'debit': balance > 0.0 and balance or 0.0, + 'credit': balance < 0.0 and -balance or 0.0, + 'tax_base_amount': tax_base_amount, + } + + if taxes_map_entry['tax_line']: + # Update an existing tax line. + taxes_map_entry['tax_line'].update(to_write_on_line) else: create_method = in_draft_mode and self.env['account.move.line'].new or self.env['account.move.line'].create tax_repartition_line_id = taxes_map_entry['grouping_dict']['tax_repartition_line_id'] tax_repartition_line = self.env['account.tax.repartition.line'].browse(tax_repartition_line_id) tax = tax_repartition_line.invoice_tax_id or tax_repartition_line.refund_tax_id - tax_line = create_method({ + taxes_map_entry['tax_line'] = create_method({ + **to_write_on_line, 'name': tax.name, 'move_id': self.id, 'partner_id': line.partner_id.id, 'company_id': line.company_id.id, 'company_currency_id': line.company_currency_id.id, - 'quantity': 1.0, - 'date_maturity': False, - 'amount_currency': taxes_map_entry['amount_currency'], - 'debit': taxes_map_entry['balance'] > 0.0 and taxes_map_entry['balance'] or 0.0, - 'credit': taxes_map_entry['balance'] < 0.0 and -taxes_map_entry['balance'] or 0.0, 'tax_base_amount': tax_base_amount, 'exclude_from_invoice_tab': True, 'tax_exigible': tax.tax_exigibility == 'on_invoice', @@ -718,8 +687,7 @@ class AccountMove(models.Model): }) if in_draft_mode: - tax_line._onchange_amount_currency() - tax_line._onchange_balance() + taxes_map_entry['tax_line'].update(taxes_map_entry['tax_line']._get_fields_onchange_balance()) def _recompute_cash_rounding_lines(self): ''' Handle the cash rounding feature on invoices. @@ -737,18 +705,17 @@ class AccountMove(models.Model): self.ensure_one() in_draft_mode = self != self._origin - def _compute_cash_rounding(self, total_balance, total_amount_currency): + def _compute_cash_rounding(self, total_amount_currency): ''' Compute the amount differences due to the cash rounding. :param self: The current account.move record. - :param total_balance: The invoice's total in company's currency. :param total_amount_currency: The invoice's total in invoice's currency. :return: The amount differences both in company's currency & invoice's currency. ''' + difference = self.invoice_cash_rounding_id.compute_difference(self.currency_id, total_amount_currency) if self.currency_id == self.company_id.currency_id: - diff_balance = self.invoice_cash_rounding_id.compute_difference(self.currency_id, total_balance) - diff_amount_currency = 0.0 + diff_amount_currency = diff_balance = difference else: - diff_amount_currency = self.invoice_cash_rounding_id.compute_difference(self.currency_id, total_amount_currency) + diff_amount_currency = difference diff_balance = self.currency_id._convert(diff_amount_currency, self.company_id.currency_id, self.company_id, self.date) return diff_balance, diff_amount_currency @@ -767,7 +734,7 @@ class AccountMove(models.Model): 'amount_currency': diff_amount_currency, 'partner_id': self.partner_id.id, 'move_id': self.id, - 'currency_id': self.currency_id if self.currency_id != self.company_id.currency_id else False, + 'currency_id': self.currency_id, 'company_id': self.company_id.id, 'company_currency_id': self.company_id.currency_id.id, 'is_rounding_line': True, @@ -815,8 +782,7 @@ class AccountMove(models.Model): cash_rounding_line = create_method(rounding_line_vals) if in_draft_mode: - cash_rounding_line._onchange_amount_currency() - cash_rounding_line._onchange_balance() + cash_rounding_line.update(cash_rounding_line._get_fields_onchange_balance()) existing_cash_rounding_line = self.line_ids.filtered(lambda line: line.is_rounding_line) @@ -835,10 +801,9 @@ class AccountMove(models.Model): others_lines = self.line_ids.filtered(lambda line: line.account_id.user_type_id.type not in ('receivable', 'payable')) others_lines -= existing_cash_rounding_line - total_balance = sum(others_lines.mapped('balance')) total_amount_currency = sum(others_lines.mapped('amount_currency')) - diff_balance, diff_amount_currency = _compute_cash_rounding(self, total_balance, total_amount_currency) + diff_balance, diff_amount_currency = _compute_cash_rounding(self, total_amount_currency) # The invoice is already rounded. if self.currency_id.is_zero(diff_balance) and self.currency_id.is_zero(diff_amount_currency): @@ -898,13 +863,13 @@ class AccountMove(models.Model): ''' if self.invoice_payment_term_id: to_compute = self.invoice_payment_term_id.compute(total_balance, date_ref=date, currency=self.currency_id) - if self.currency_id != self.company_id.currency_id: + if self.currency_id == self.company_id.currency_id: + # Single-currency. + return [(b[0], b[1], b[1]) for b in to_compute] + else: # Multi-currencies. to_compute_currency = self.invoice_payment_term_id.compute(total_amount_currency, date_ref=date, currency=self.currency_id) return [(b[0], b[1], ac[1]) for b, ac in zip(to_compute, to_compute_currency)] - else: - # Single-currency. - return [(b[0], b[1], 0.0) for b in to_compute] else: return [(fields.Date.to_string(date), total_balance, total_amount_currency)] @@ -946,15 +911,14 @@ class AccountMove(models.Model): 'amount_currency': -amount_currency, 'date_maturity': date_maturity, 'move_id': self.id, - 'currency_id': self.currency_id.id if self.currency_id != self.company_id.currency_id else False, + 'currency_id': self.currency_id.id, 'account_id': account.id, 'partner_id': self.commercial_partner_id.id, 'exclude_from_invoice_tab': True, }) new_terms_lines += candidate if in_draft_mode: - candidate._onchange_amount_currency() - candidate._onchange_balance() + candidate.update(candidate._get_fields_onchange_balance()) return new_terms_lines existing_terms_lines = self.line_ids.filtered(lambda line: line.account_id.user_type_id.type in ('receivable', 'payable')) @@ -1330,17 +1294,12 @@ class AccountMove(models.Model): domain.append(('balance', '>', 0.0)) payments_widget_vals['title'] = _('Outstanding debits') - if move.currency_id == move.company_currency_id: - currency = False - else: - currency = move.currency_id - for line in self.env['account.move.line'].search(domain): - if currency and line.currency_id == currency: + if line.currency_id == move.currency_id: # Same foreign currency. amount = abs(line.amount_residual_currency) - elif currency: + else: # Different foreign currencies. amount = move.company_currency_id._convert( abs(line.amount_residual), @@ -1348,9 +1307,6 @@ class AccountMove(models.Model): move.company_id, line.date, ) - else: - # Company's currency. - amount = abs(line.amount_residual) if move.currency_id.is_zero(amount): continue @@ -1610,7 +1566,6 @@ class AccountMove(models.Model): ''' self.ensure_one() - line_currency = self.currency_id if self.currency_id != self.company_id.currency_id else False for line in self.line_ids: # Do something only on invoice lines. if line.exclude_from_invoice_tab: @@ -1634,7 +1589,7 @@ class AccountMove(models.Model): line.partner_id = self.partner_id line.date = self.date line.recompute_tax_line = True - line.currency_id = line_currency + line.currency_id = self.currency_id self.line_ids._onchange_price_subtotal() @@ -1678,6 +1633,8 @@ class AccountMove(models.Model): vals['date'] = vals['invoice_date'] ctx_vals = {'default_move_type': vals.get('move_type') or self._context.get('default_move_type')} + if vals.get('currency_id'): + ctx_vals['default_currency_id'] = vals['currency_id'] if vals.get('journal_id'): ctx_vals['default_journal_id'] = vals['journal_id'] # reorder the companies in the context so that the company of the journal @@ -2769,15 +2726,15 @@ class AccountMoveLine(models.Model): amount_currency = fields.Monetary(string='Amount in Currency', store=True, copy=True, help="The amount expressed in an optional other currency if it is a multi-currency entry.") price_subtotal = fields.Monetary(string='Subtotal', store=True, readonly=True, - currency_field='always_set_currency_id') + currency_field='currency_id') price_total = fields.Monetary(string='Total', store=True, readonly=True, - currency_field='always_set_currency_id') + currency_field='currency_id') reconciled = fields.Boolean(compute='_compute_amount_residual', store=True) blocked = fields.Boolean(string='No Follow-up', default=False, help="You can check this box to mark this journal item as a litigation with the associated partner") date_maturity = fields.Date(string='Due Date', index=True, tracking=True, help="This field is used for payable and receivable journal entries. You can put the limit date for the payment of this line.") - currency_id = fields.Many2one('res.currency', string='Currency') + currency_id = fields.Many2one('res.currency', string='Currency', required=True) partner_id = fields.Many2one('res.partner', string='Partner', ondelete='restrict') product_uom_id = fields.Many2one('uom.uom', string='Unit of Measure', domain="[('category_id', '=', product_uom_category_id)]") product_id = fields.Many2one('product.product', string='Product') @@ -2849,9 +2806,6 @@ class AccountMoveLine(models.Model): ], default=False, help="Technical field for UX purpose.") is_rounding_line = fields.Boolean(help="Technical field used to retrieve the cash rounding line.") exclude_from_invoice_tab = fields.Boolean(help="Technical field used to exclude some lines from the invoice_line_ids tab in the form view.") - always_set_currency_id = fields.Many2one('res.currency', string='Foreign Currency', - compute='_compute_always_set_currency_id', - help="Technical field used to compute the monetary field. As currency_id is not a required field, we need to use either the foreign currency, either the company one.") _sql_constraints = [ ( @@ -2872,21 +2826,25 @@ class AccountMoveLine(models.Model): ( 'check_amount_currency_balance_sign', '''CHECK( - currency_id IS NULL - OR - company_currency_id IS NULL - OR ( (currency_id != company_currency_id) AND ( - (balance > 0 AND amount_currency > 0) - OR (balance <= 0 AND amount_currency <= 0) - OR (balance >= 0 AND amount_currency >= 0) + (debit - credit <= 0 AND amount_currency <= 0) + OR + (debit - credit >= 0 AND amount_currency >= 0) ) ) + OR + ( + currency_id = company_currency_id + AND + ROUND(debit - credit - amount_currency, 2) = 0 + ) )''', - "The amount expressed in the secondary currency must be positive when account is debited and negative when account is credited. Moreover, the currency field has to be left empty when the amount is expressed in the company currency." + "The amount expressed in the secondary currency must be positive when account is debited and negative when " + "account is credited. If the currency is the same as the one from the company, this amount must strictly " + "be equal to the balance." ), ] @@ -3108,30 +3066,22 @@ class AccountMoveLine(models.Model): sign = -1 else: sign = 1 - price_subtotal *= sign - if currency and currency != company.currency_id: - # Multi-currencies. - balance = currency._convert(price_subtotal, company.currency_id, company, date) - return { - 'amount_currency': price_subtotal, - 'debit': balance > 0.0 and balance or 0.0, - 'credit': balance < 0.0 and -balance or 0.0, - } - else: - # Single-currency. - return { - 'amount_currency': 0.0, - 'debit': price_subtotal > 0.0 and price_subtotal or 0.0, - 'credit': price_subtotal < 0.0 and -price_subtotal or 0.0, - } + amount_currency = price_subtotal * sign + balance = currency._convert(amount_currency, company.currency_id, company, date) + return { + 'amount_currency': amount_currency, + 'currency_id': currency.id, + 'debit': balance > 0.0 and balance or 0.0, + 'credit': balance < 0.0 and -balance or 0.0, + } - def _get_fields_onchange_balance(self, quantity=None, discount=None, balance=None, move_type=None, currency=None, taxes=None, price_subtotal=None): + def _get_fields_onchange_balance(self, quantity=None, discount=None, amount_currency=None, move_type=None, currency=None, taxes=None, price_subtotal=None): self.ensure_one() return self._get_fields_onchange_balance_model( quantity=quantity or self.quantity, discount=discount or self.discount, - balance=balance or self.balance, + amount_currency=amount_currency or self.amount_currency, move_type=move_type or self.move_id.move_type, currency=currency or self.currency_id or self.move_id.currency_id, taxes=taxes or self.tax_ids, @@ -3139,7 +3089,7 @@ class AccountMoveLine(models.Model): ) @api.model - def _get_fields_onchange_balance_model(self, quantity, discount, balance, move_type, currency, taxes, price_subtotal): + def _get_fields_onchange_balance_model(self, quantity, discount, amount_currency, move_type, currency, taxes, price_subtotal): ''' This method is used to recompute the values of 'quantity', 'discount', 'price_unit' due to a change made in some accounting fields such as 'balance'. @@ -3148,7 +3098,7 @@ class AccountMoveLine(models.Model): :param quantity: The current quantity. :param discount: The current discount. - :param balance: The new balance. + :param amount_currency: The new balance in line's currency. :param move_type: The type of the move. :param currency: The currency. :param taxes: The applied taxes. @@ -3161,14 +3111,14 @@ class AccountMoveLine(models.Model): sign = -1 else: sign = 1 - balance *= sign + amount_currency *= sign # Avoid rounding issue when dealing with price included taxes. For example, when the price_unit is 2300.0 and # a 5.5% price included tax is applied on it, a balance of 2300.0 / 1.055 = 2180.094 ~ 2180.09 is computed. # However, when triggering the inverse, 2180.09 + (2180.09 * 0.055) = 2180.09 + 119.90 = 2299.99 is computed. # To avoid that, set the price_subtotal at the balance if the difference between them looks like a rounding # issue. - if currency.is_zero(balance - price_subtotal): + if currency.is_zero(amount_currency - price_subtotal): return {} taxes = taxes.flatten_taxes_hierarchy() @@ -3188,25 +3138,25 @@ class AccountMoveLine(models.Model): # 220 | 10% incl, 5% | | 200 | 230 # 20 | | 10% incl | 20 | 20 # 10 | | 5% | 10 | 10 - taxes_res = taxes._origin.compute_all(balance, currency=currency, handle_price_include=False) + taxes_res = taxes._origin.compute_all(amount_currency, currency=currency, handle_price_include=False) for tax_res in taxes_res['taxes']: tax = self.env['account.tax'].browse(tax_res['id']) if tax.price_include: - balance += tax_res['amount'] + amount_currency += tax_res['amount'] discount_factor = 1 - (discount / 100.0) - if balance and discount_factor: + if amount_currency and discount_factor: # discount != 100% vals = { 'quantity': quantity or 1.0, - 'price_unit': balance / discount_factor / (quantity or 1.0), + 'price_unit': amount_currency / discount_factor / (quantity or 1.0), } - elif balance and not discount_factor: + elif amount_currency and not discount_factor: # discount == 100% vals = { 'quantity': quantity or 1.0, 'discount': 0.0, - 'price_unit': balance / (quantity or 1.0), + 'price_unit': amount_currency / (quantity or 1.0), } elif not discount_factor: # balance of line is 0, but discount == 100% so we display the normal unit_price @@ -3261,8 +3211,8 @@ class AccountMoveLine(models.Model): line.price_unit = line._get_price_total_and_subtotal()['price_subtotal'] line.tax_ids = line.move_id.fiscal_position_id.map_tax(line.tax_ids._origin, partner=line.move_id.partner_id) accounting_vals = line._get_fields_onchange_subtotal(price_subtotal=line.price_unit, currency=line.move_id.company_currency_id) - balance = accounting_vals['debit'] - accounting_vals['credit'] - line.price_unit = line._get_fields_onchange_balance(balance=balance).get('price_unit', line.price_unit) + amount_currency = accounting_vals['amount_currency'] + line.price_unit = line._get_fields_onchange_balance(amount_currency=amount_currency).get('price_unit', line.price_unit) # Convert the unit price to the invoice's currency. company = line.move_id.company_id @@ -3278,8 +3228,8 @@ class AccountMoveLine(models.Model): if taxes and self.move_id.fiscal_position_id: price_subtotal = self._get_price_total_and_subtotal(price_unit=price_unit, taxes=taxes)['price_subtotal'] accounting_vals = self._get_fields_onchange_subtotal(price_subtotal=price_subtotal, currency=self.move_id.company_currency_id) - balance = accounting_vals['debit'] - accounting_vals['credit'] - price_unit = self._get_fields_onchange_balance(balance=balance).get('price_unit', price_unit) + amount_currency = accounting_vals['amount_currency'] + price_unit = self._get_fields_onchange_balance(amount_currency=amount_currency).get('price_unit', price_unit) # Convert the unit price to the invoice's currency. company = self.move_id.company_id @@ -3300,12 +3250,13 @@ class AccountMoveLine(models.Model): def _onchange_balance(self): for line in self: - if line.currency_id: + if line.currency_id == line.move_id.company_id.currency_id: + line.amount_currency = line.balance + else: continue if not line.move_id.is_invoice(include_receipts=True): continue line.update(line._get_fields_onchange_balance()) - line.update(line._get_price_total_and_subtotal()) @api.onchange('debit') def _onchange_debit(self): @@ -3322,14 +3273,15 @@ class AccountMoveLine(models.Model): @api.onchange('amount_currency') def _onchange_amount_currency(self): for line in self: - if not line.currency_id: - continue + company = line.move_id.company_id + balance = line.currency_id._convert(line.amount_currency, company.currency_id, company, line.move_id.date) + line.debit = balance if balance > 0.0 else 0.0 + line.credit = -balance if balance < 0.0 else 0.0 + if not line.move_id.is_invoice(include_receipts=True): - line._recompute_debit_credit_from_amount_currency() continue - line.update(line._get_fields_onchange_balance( - balance=line.amount_currency, - )) + + line.update(line._get_fields_onchange_balance()) line.update(line._get_price_total_and_subtotal()) @api.onchange('quantity', 'discount', 'price_unit', 'tax_ids') @@ -3344,21 +3296,15 @@ class AccountMoveLine(models.Model): @api.onchange('currency_id') def _onchange_currency(self): for line in self: + company = line.move_id.company_id + if line.move_id.is_invoice(include_receipts=True): line._onchange_price_subtotal() elif not line.move_id.reversed_entry_id: - line._recompute_debit_credit_from_amount_currency() + balance = line.currency_id._convert(line.amount_currency, company.currency_id, company, line.move_id.date or fields.Date.context_today(line)) + line.debit = balance if balance > 0.0 else 0.0 + line.credit = -balance if balance < 0.0 else 0.0 - def _recompute_debit_credit_from_amount_currency(self): - for line in self: - # Recompute the debit/credit based on amount_currency/currency_id and date. - - company_currency = line.account_id.company_id.currency_id - balance = line.amount_currency - if line.currency_id and company_currency and line.currency_id != company_currency: - balance = line.currency_id._convert(balance, company_currency, line.account_id.company_id, line.move_id.date or fields.Date.context_today(self)) - line.debit = balance > 0 and balance or 0.0 - line.credit = balance < 0 and -balance or 0.0 # ------------------------------------------------------------------------- # COMPUTE METHODS # ------------------------------------------------------------------------- @@ -3373,11 +3319,6 @@ class AccountMoveLine(models.Model): else: record.matching_number = None - @api.depends('currency_id') - def _compute_always_set_currency_id(self): - for line in self: - line.always_set_currency_id = line.currency_id or line.company_currency_id - @api.depends('debit', 'credit') def _compute_balance(self): for line in self: @@ -3571,6 +3512,18 @@ class AccountMoveLine(models.Model): move = self.env['account.move'].browse(vals['move_id']) vals.setdefault('company_currency_id', move.company_id.currency_id.id) # important to bypass the ORM limitation where monetary fields are not rounded; more info in the commit message + # Ensure balance == amount_currency in case of missing currency or same currency as the one from the + # company. + currency_id = vals.get('currency_id') or move.company_id.currency_id.id + if currency_id == move.company_id.currency_id.id: + balance = vals.get('debit', 0.0) - vals.get('credit', 0.0) + vals.update({ + 'currency_id': currency_id, + 'amount_currency': balance, + }) + else: + vals['amount_currency'] = vals.get('amount_currency', 0.0) + if move.is_invoice(include_receipts=True): currency = move.currency_id partner = self.env['res.partner'].browse(vals.get('partner_id')) @@ -3583,10 +3536,6 @@ class AccountMoveLine(models.Model): # in onchange and in create/write. So, if something changed in accounting [resp. business] fields, # business [resp. accounting] fields are recomputed. if any(vals.get(field) for field in ACCOUNTING_FIELDS): - if vals.get('currency_id'): - balance = vals.get('amount_currency', 0.0) - else: - balance = vals.get('debit', 0.0) - vals.get('credit', 0.0) price_subtotal = self._get_price_total_and_subtotal_model( vals.get('price_unit', 0.0), vals.get('quantity', 0.0), @@ -3600,7 +3549,7 @@ class AccountMoveLine(models.Model): vals.update(self._get_fields_onchange_balance_model( vals.get('quantity', 0.0), vals.get('discount', 0.0), - balance, + vals['amount_currency'], move.move_type, currency, taxes, @@ -3759,6 +3708,14 @@ class AccountMoveLine(models.Model): if not cleaned_vals: continue + # Auto-fill amount_currency if working in single-currency. + if 'currency_id' not in cleaned_vals \ + and line.currency_id == line.company_currency_id \ + and any(field_name in cleaned_vals for field_name in ('debit', 'credit')): + cleaned_vals.update({ + 'amount_currency': vals.get('debit', 0.0) - vals.get('credit', 0.0), + }) + result |= super(AccountMoveLine, line).write(cleaned_vals) if not line.move_id.is_invoice(include_receipts=True): @@ -3769,12 +3726,8 @@ class AccountMoveLine(models.Model): # in onchange and in create/write. So, if something changed in accounting [resp. business] fields, # business [resp. accounting] fields are recomputed. if any(field in cleaned_vals for field in ACCOUNTING_FIELDS): - balance = line.currency_id and line.amount_currency or line.debit - line.credit price_subtotal = line._get_price_total_and_subtotal().get('price_subtotal', 0.0) - to_write = line._get_fields_onchange_balance( - balance=balance, - price_subtotal=price_subtotal, - ) + to_write = line._get_fields_onchange_balance(price_subtotal=price_subtotal) to_write.update(line._get_price_total_and_subtotal( price_unit=to_write.get('price_unit', line.price_unit), quantity=to_write.get('quantity', line.quantity), @@ -4413,97 +4366,6 @@ class AccountMoveLine(models.Model): return results - def _create_writeoff(self, writeoff_vals): - """ Create a writeoff move per journal for the account.move.lines in self. If debit/credit is not specified in vals, - the writeoff amount will be computed as the sum of amount_residual of the given recordset. - :param writeoff_vals: list of dicts containing values suitable for account_move_line.create(). The data in vals will - be processed to create bot writeoff account.move.line and their enclosing account.move. - """ - def compute_writeoff_counterpart_vals(values): - line_values = values.copy() - line_values['debit'], line_values['credit'] = line_values['credit'], line_values['debit'] - if 'amount_currency' in values: - line_values['amount_currency'] = -line_values['amount_currency'] - return line_values - # Group writeoff_vals by journals - writeoff_dict = {} - for val in writeoff_vals: - journal_id = val.get('journal_id', False) - if not writeoff_dict.get(journal_id, False): - writeoff_dict[journal_id] = [val] - else: - writeoff_dict[journal_id].append(val) - - partner_id = self.env['res.partner']._find_accounting_partner(self[0].partner_id).id - company_currency = self[0].account_id.company_id.currency_id - writeoff_currency = self[0].account_id.currency_id or company_currency - line_to_reconcile = self.env['account.move.line'] - # Iterate and create one writeoff by journal - writeoff_moves = self.env['account.move'] - for journal_id, lines in writeoff_dict.items(): - total = 0 - total_currency = 0 - writeoff_lines = [] - date = fields.Date.context_today(self) - for vals in lines: - # Check and complete vals - if 'account_id' not in vals or 'journal_id' not in vals: - raise UserError(_("It is mandatory to specify an account and a journal to create a write-off.")) - if ('debit' in vals) ^ ('credit' in vals): - raise UserError(_("Either pass both debit and credit or none.")) - if 'date' not in vals: - vals['date'] = self._context.get('date_p') or fields.Date.context_today(self) - vals['date'] = fields.Date.to_date(vals['date']) - if vals['date'] and vals['date'] < date: - date = vals['date'] - if 'name' not in vals: - vals['name'] = self._context.get('comment') or _('Write-Off') - if 'analytic_account_id' not in vals: - vals['analytic_account_id'] = self.env.context.get('analytic_id', False) - #compute the writeoff amount if not given - if 'credit' not in vals and 'debit' not in vals: - amount = sum([r.amount_residual for r in self]) - vals['credit'] = amount > 0 and amount or 0.0 - vals['debit'] = amount < 0 and abs(amount) or 0.0 - vals['partner_id'] = partner_id - total += vals['debit']-vals['credit'] - if 'amount_currency' not in vals and writeoff_currency != company_currency: - vals['currency_id'] = writeoff_currency.id - sign = 1 if vals['debit'] > 0 else -1 - vals['amount_currency'] = sign * abs(sum([r.amount_residual_currency for r in self])) - total_currency += vals['amount_currency'] - - writeoff_lines.append(compute_writeoff_counterpart_vals(vals)) - - # Create balance line - writeoff_lines.append({ - 'name': _('Write-Off'), - 'debit': total > 0 and total or 0.0, - 'credit': total < 0 and -total or 0.0, - 'amount_currency': total_currency, - 'currency_id': total_currency and writeoff_currency.id or False, - 'journal_id': journal_id, - 'account_id': self[0].account_id.id, - 'partner_id': partner_id - }) - - # Create the move - writeoff_move = self.env['account.move'].create({ - 'journal_id': journal_id, - 'date': date, - 'state': 'draft', - 'line_ids': [(0, 0, line) for line in writeoff_lines], - }) - writeoff_moves += writeoff_move - line_to_reconcile += writeoff_move.line_ids.filtered(lambda r: r.account_id == self[0].account_id).sorted(key='id')[-1:] - - #post all the writeoff moves at once - if writeoff_moves: - writeoff_moves._post() - - # Return the writeoff move.line which is to be reconciled - return line_to_reconcile - def remove_move_reconcile(self): """ Undo a reconciliation """ (self.matched_debit_ids + self.matched_credit_ids).unlink() diff --git a/addons/account/models/account_partial_reconcile.py b/addons/account/models/account_partial_reconcile.py index a35f8bcc381..d1c12f6c0a1 100644 --- a/addons/account/models/account_partial_reconcile.py +++ b/addons/account/models/account_partial_reconcile.py @@ -371,8 +371,6 @@ class AccountPartialReconcile(models.Model): # reconciliation. # ========================================================================== - balance_field = 'balance' if move_values['currency'] == move.company_id.currency_id else 'amount_currency' - for line in move_values['to_process_lines']: if line.tax_repartition_line_id: # Tax line. @@ -381,7 +379,7 @@ class AccountPartialReconcile(models.Model): account=line.tax_repartition_line_id.account_id, ) residual_amount_per_group.setdefault(grouping_key, 0.0) - residual_amount_per_group[grouping_key] += line[balance_field] + residual_amount_per_group[grouping_key] += line['amount_currency'] elif line.tax_ids: # Base line. @@ -390,7 +388,7 @@ class AccountPartialReconcile(models.Model): account=line.company_id.account_cash_basis_base_account_id, ) residual_amount_per_group.setdefault(grouping_key, 0.0) - residual_amount_per_group[grouping_key] += line[balance_field] + residual_amount_per_group[grouping_key] += line['amount_currency'] # ========================================================================== # Part 2: @@ -419,7 +417,7 @@ class AccountPartialReconcile(models.Model): # we are not able to ensure the full coverage of the balance. return - residual_amount_per_group[grouping_key] -= line[balance_field] + residual_amount_per_group[grouping_key] -= line['amount_currency'] # ========================================================================== # Part 3: @@ -439,20 +437,13 @@ class AccountPartialReconcile(models.Model): for grouping_key, aggregated_vals in partial_lines_to_create.items(): line_vals = aggregated_vals['vals'] - if move_values['currency'] == move.company_id.currency_id: - balance = residual_amount_per_group[grouping_key] - line_vals.update({ - 'debit': balance if balance > 0.0 else 0.0, - 'credit': -balance if balance < 0.0 else 0.0, - }) - else: - amount_currency = residual_amount_per_group[grouping_key] - balance = partial_values['payment_rate'] and amount_currency / partial_values['payment_rate'] or 0.0 - line_vals.update({ - 'debit': balance if balance > 0.0 else 0.0, - 'credit': -balance if balance < 0.0 else 0.0, - 'amount_currency': amount_currency, - }) + amount_currency = residual_amount_per_group[grouping_key] + balance = partial_values['payment_rate'] and amount_currency / partial_values['payment_rate'] or 0.0 + line_vals.update({ + 'debit': balance if balance > 0.0 else 0.0, + 'credit': -balance if balance < 0.0 else 0.0, + 'amount_currency': amount_currency, + }) def _create_tax_cash_basis_moves(self): ''' Create the tax cash basis journal entries. @@ -493,14 +484,9 @@ class AccountPartialReconcile(models.Model): # that is actually paid by the current partial. # ========================================================================== - if move_values['currency'] == move.company_id.currency_id: - # Percentage expressed in the company's currency. - balance = line.company_currency_id.round(line.balance * partial_values['percentage']) - amount_currency = 0.0 - else: - # Percentage expressed in the foreign currency. - amount_currency = line.currency_id.round(line.amount_currency * partial_values['percentage']) - balance = partial_values['payment_rate'] and amount_currency / partial_values['payment_rate'] or 0.0 + # Percentage expressed in the foreign currency. + amount_currency = line.currency_id.round(line.amount_currency * partial_values['percentage']) + balance = partial_values['payment_rate'] and amount_currency / partial_values['payment_rate'] or 0.0 # ========================================================================== # Prepare the mirror cash basis journal item of the current line. @@ -568,10 +554,7 @@ class AccountPartialReconcile(models.Model): line_vals = aggregated_vals['vals'] line_vals['sequence'] = sequence - if move_values['currency'] == move.company_id.currency_id: - pending_cash_basis_lines.append((grouping_key, line_vals['debit'] - line_vals['credit'])) - else: - pending_cash_basis_lines.append((grouping_key, line_vals['amount_currency'])) + pending_cash_basis_lines.append((grouping_key, line_vals['amount_currency'])) if 'tax_repartition_line_id' in line_vals: # Tax line. diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 7a88c6e15e6..1fbd206f050 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -191,21 +191,11 @@ class AccountPayment(models.Model): counterpart_amount = 0.0 write_off_amount = 0.0 - # Manage currency. - if self.currency_id == self.company_id.currency_id: - # Single-currency. - balance = counterpart_amount - counterpart_amount_currency = 0.0 - write_off_balance = write_off_amount - write_off_amount_currency = 0.0 - currency_id = False - else: - # Multi-currencies. - balance = self.currency_id._convert(counterpart_amount, self.company_id.currency_id, self.company_id, self.date) - counterpart_amount_currency = counterpart_amount - write_off_balance = self.currency_id._convert(write_off_amount, self.company_id.currency_id, self.company_id, self.date) - write_off_amount_currency = write_off_amount - currency_id = self.currency_id.id + balance = self.currency_id._convert(counterpart_amount, self.company_id.currency_id, self.company_id, self.date) + counterpart_amount_currency = counterpart_amount + write_off_balance = self.currency_id._convert(write_off_amount, self.company_id.currency_id, self.company_id, self.date) + write_off_amount_currency = write_off_amount + currency_id = self.currency_id.id if self.is_internal_transfer: if self.payment_type == 'inbound': @@ -630,17 +620,17 @@ class AccountPayment(models.Model): else: partner_type = 'supplier' - liquidity_amount = liquidity_lines.amount_currency if liquidity_lines.currency_id else liquidity_lines.balance + liquidity_amount = liquidity_lines.amount_currency move_vals_to_write.update({ - 'currency_id': liquidity_lines.currency_id.id or liquidity_lines.company_currency_id.id, + 'currency_id': liquidity_lines.currency_id.id, 'partner_id': liquidity_lines.partner_id.id, }) payment_vals_to_write.update({ 'amount': abs(liquidity_amount), 'payment_type': 'inbound' if liquidity_amount > 0.0 else 'outbound', 'partner_type': partner_type, - 'currency_id': liquidity_lines.currency_id.id or liquidity_lines.company_currency_id.id, + 'currency_id': liquidity_lines.currency_id.id, 'destination_account_id': counterpart_lines.account_id.id, 'partner_id': liquidity_lines.partner_id.id, }) @@ -668,9 +658,8 @@ class AccountPayment(models.Model): # This allows to create a new payment with custom 'line_ids'. if writeoff_lines: - writeoff_amount_field = 'balance' if pay.currency_id == pay.company_id.currency_id else 'amount_currency' - writeoff_amount = sum(writeoff_lines.mapped(writeoff_amount_field)) - counterpart_amount = counterpart_lines[writeoff_amount_field] + writeoff_amount = sum(writeoff_lines.mapped('amount_currency')) + counterpart_amount = counterpart_lines['amount_currency'] if writeoff_amount > 0.0 and counterpart_amount > 0.0: sign = 1 else: diff --git a/addons/account/tests/test_account_bank_statement.py b/addons/account/tests/test_account_bank_statement.py index a6431f2e3b5..253c9e8243e 100644 --- a/addons/account/tests/test_account_bank_statement.py +++ b/addons/account/tests/test_account_bank_statement.py @@ -508,7 +508,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): 120.0, 80.0, self.currency_2, self.currency_1, {'debit': 80.0, 'credit': 0.0, 'amount_currency': 120.0, 'currency_id': self.currency_2.id}, - {'debit': 0.0, 'credit': 80.0, 'amount_currency': 0.0, 'currency_id': False}, + {'debit': 0.0, 'credit': 80.0, 'amount_currency': -80.0, 'currency_id': self.currency_1.id}, ) def test_edition_journal_curr_1_statement_curr_2(self): @@ -531,8 +531,8 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): self._test_edition_customer_and_supplier_flows( 80.0, 0.0, self.currency_1, False, - {'debit': 80.0, 'credit': 0.0, 'amount_currency': 0.0, 'currency_id': False}, - {'debit': 0.0, 'credit': 80.0, 'amount_currency': 0.0, 'currency_id': False}, + {'debit': 80.0, 'credit': 0.0, 'amount_currency': 80.0, 'currency_id': self.currency_1.id}, + {'debit': 0.0, 'credit': 80.0, 'amount_currency': -80.0, 'currency_id': self.currency_1.id}, ) def test_zero_amount_journal_curr_1_statement_curr_2(self): @@ -604,7 +604,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): self.assertRecordValues(statement.line_ids.move_id.line_ids, [ {'debit': 10.0, 'credit': 0.0, 'amount_currency': 0.0, 'currency_id': self.currency_2.id}, - {'debit': 0.0, 'credit': 10.0, 'amount_currency': 0.0, 'currency_id': False}, + {'debit': 0.0, 'credit': 10.0, 'amount_currency': -10.0, 'currency_id': self.currency_1.id}, ]) def test_zero_amount_currency_journal_curr_2_statement_curr_1(self): @@ -628,7 +628,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): self.assertRecordValues(statement.line_ids.move_id.line_ids, [ {'debit': 0.0, 'credit': 0.0, 'amount_currency': 10.0, 'currency_id': self.currency_2.id}, - {'debit': 0.0, 'credit': 0.0, 'amount_currency': 0.0, 'currency_id': False}, + {'debit': 0.0, 'credit': 0.0, 'amount_currency': 0.0, 'currency_id': self.currency_1.id}, ]) def test_zero_amount_journal_curr_2_statement_curr_3(self): @@ -1049,7 +1049,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): 120.0, 80.0, -120.0, self.currency_2, self.currency_1, self.currency_2, {'debit': 80.0, 'credit': 0.0, 'amount_currency': 120.0, 'currency_id': self.currency_2.id}, - {'debit': 0.0, 'credit': 80.0, 'amount_currency': 0.0, 'currency_id': False}, + {'debit': 0.0, 'credit': 80.0, 'amount_currency': -80.0, 'currency_id': self.currency_1.id}, ) def test_reconciliation_journal_curr_2_statement_curr_3_counterpart_curr_2(self): @@ -1104,8 +1104,8 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): self._test_reconciliation_customer_and_supplier_flows( 80.0, 0.0, -480.0, self.currency_1, False, self.currency_3, - {'debit': 80.0, 'credit': 0.0, 'amount_currency': 0.0, 'currency_id': False}, - {'debit': 0.0, 'credit': 80.0, 'amount_currency': 0.0, 'currency_id': False}, + {'debit': 80.0, 'credit': 0.0, 'amount_currency': 80.0, 'currency_id': self.currency_1.id}, + {'debit': 0.0, 'credit': 80.0, 'amount_currency': -80.0, 'currency_id': self.currency_1.id}, ) def test_reconciliation_journal_curr_2_statement_curr_1_counterpart_curr_1(self): @@ -1113,7 +1113,7 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): 120.0, 80.0, -80.0, self.currency_2, self.currency_1, self.currency_1, {'debit': 80.0, 'credit': 0.0, 'amount_currency': 120.0, 'currency_id': self.currency_2.id}, - {'debit': 0.0, 'credit': 80.0, 'amount_currency': 0.0, 'currency_id': False}, + {'debit': 0.0, 'credit': 80.0, 'amount_currency': -80.0, 'currency_id': self.currency_1.id}, ) def test_reconciliation_journal_curr_2_statement_curr_3_counterpart_curr_1(self): @@ -1144,8 +1144,8 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): self._test_reconciliation_customer_and_supplier_flows( 80.0, 0.0, -80.0, self.currency_1, False, self.currency_1, - {'debit': 80.0, 'credit': 0.0, 'amount_currency': 0.0, 'currency_id': False}, - {'debit': 0.0, 'credit': 80.0, 'amount_currency': 0.0, 'currency_id': False}, + {'debit': 80.0, 'credit': 0.0, 'amount_currency': 80.0, 'currency_id': self.currency_1.id}, + {'debit': 0.0, 'credit': 80.0, 'amount_currency': -80.0, 'currency_id': self.currency_1.id}, ) def test_reconciliation_statement_line_state(self): diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py index bd8e9a09b42..81a49631df7 100644 --- a/addons/account/tests/test_account_move_in_invoice.py +++ b/addons/account/tests/test_account_move_in_invoice.py @@ -28,8 +28,8 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 920.0, 'tax_ids': cls.product_a.supplier_taxes_id.ids, 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': 800.0, 'debit': 800.0, 'credit': 0.0, 'date_maturity': False, @@ -48,8 +48,8 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 208.0, 'tax_ids': cls.product_b.supplier_taxes_id.ids, 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': 160.0, 'debit': 160.0, 'credit': 0.0, 'date_maturity': False, @@ -68,8 +68,8 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 144.0, 'tax_ids': [], 'tax_line_id': cls.tax_purchase_a.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': 144.0, 'debit': 144.0, 'credit': 0.0, 'date_maturity': False, @@ -88,8 +88,8 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 24.0, 'tax_ids': [], 'tax_line_id': cls.tax_purchase_b.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': 24.0, 'debit': 24.0, 'credit': 0.0, 'date_maturity': False, @@ -108,8 +108,8 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': -1128.0, 'tax_ids': [], 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': -1128.0, 'debit': 0.0, 'credit': 1128.0, 'date_maturity': fields.Date.from_string('2019-01-01'), @@ -155,6 +155,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_subtotal': 160.0, 'price_total': 208.0, 'tax_ids': self.product_b.supplier_taxes_id.ids, + 'amount_currency': 160.0, 'debit': 160.0, }, self.product_line_vals_2, @@ -163,6 +164,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 48.0, 'price_subtotal': 48.0, 'price_total': 48.0, + 'amount_currency': 48.0, 'debit': 48.0, }, { @@ -170,6 +172,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 48.0, 'price_subtotal': 48.0, 'price_total': 48.0, + 'amount_currency': 48.0, 'debit': 48.0, }, { @@ -177,6 +180,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -416.0, 'price_subtotal': -416.0, 'price_total': -416.0, + 'amount_currency': -416.0, 'credit': 416.0, }, ], { @@ -512,6 +516,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'discount': 100.0, 'price_subtotal': 0.0, 'price_total': 0.0, + 'amount_currency': 0.0, 'debit': 0.0, }, self.product_line_vals_2, @@ -520,6 +525,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 24.0, 'price_subtotal': 24.0, 'price_total': 24.0, + 'amount_currency': 24.0, 'debit': 24.0, }, self.tax_line_vals_2, @@ -528,6 +534,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -208.0, 'price_subtotal': -208.0, 'price_total': -208.0, + 'amount_currency': -208.0, 'credit': 208.0, }, ], { @@ -560,6 +567,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 3000.0, 'price_subtotal': 3000.0, 'price_total': 3450.0, + 'amount_currency': 3000.0, 'debit': 3000.0, }, { @@ -567,6 +575,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -500.0, 'price_subtotal': -500.0, 'price_total': -650.0, + 'amount_currency': -500.0, 'debit': 0.0, 'credit': 500.0, }, @@ -575,6 +584,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 800.0, 'price_subtotal': 800.0, 'price_total': 800.0, + 'amount_currency': 800.0, 'debit': 800.0, }, { @@ -582,6 +592,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 250.0, 'price_subtotal': 250.0, 'price_total': 250.0, + 'amount_currency': 250.0, 'debit': 250.0, }, { @@ -589,6 +600,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -3550.0, 'price_subtotal': -3550.0, 'price_total': -3550.0, + 'amount_currency': -3550.0, 'credit': 3550.0, }, ], { @@ -629,6 +641,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -789.6, 'price_subtotal': -789.6, 'price_total': -789.6, + 'amount_currency': -789.6, 'credit': 789.6, 'date_maturity': fields.Date.from_string('2019-02-28'), }, @@ -640,6 +653,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -338.4, 'price_subtotal': -338.4, 'price_total': -338.4, + 'amount_currency': -338.4, 'credit': 338.4, }, ], { @@ -690,6 +704,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -772.8, 'price_subtotal': -772.8, 'price_total': -772.8, + 'amount_currency': -772.8, 'credit': 772.8, 'date_maturity': fields.Date.from_string('2019-02-28'), }, @@ -701,6 +716,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -331.2, 'price_subtotal': -331.2, 'price_total': -331.2, + 'amount_currency': -331.2, 'credit': 331.2, }, ], { @@ -749,8 +765,8 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 70.4, 'tax_ids': child_tax_2.ids, 'tax_line_id': child_tax_1.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 64.0, 'debit': 64.0, 'credit': 0.0, 'date_maturity': False, @@ -769,8 +785,8 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 105.6, 'tax_ids': child_tax_2.ids, 'tax_line_id': child_tax_1.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 96.0, 'debit': 96.0, 'credit': 0.0, 'date_maturity': False, @@ -789,8 +805,8 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 96.0, 'tax_ids': [], 'tax_line_id': child_tax_2.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 96.0, 'debit': 96.0, 'credit': 0.0, 'date_maturity': False, @@ -801,6 +817,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -1384.0, 'price_subtotal': -1384.0, 'price_total': -1384.0, + 'amount_currency': -1384.0, 'credit': 1384.0, }, ], { @@ -844,8 +861,8 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 0.01, 'tax_ids': [], 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 0.01, 'debit': 0.01, 'credit': 0.0, 'date_maturity': False, @@ -856,6 +873,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 799.99, 'price_subtotal': 799.99, 'price_total': 919.99, + 'amount_currency': 799.99, 'debit': 799.99, }, self.product_line_vals_2, @@ -875,6 +893,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 799.99, 'price_subtotal': 799.99, 'price_total': 919.99, + 'amount_currency': 799.99, 'debit': 799.99, }, self.product_line_vals_2, @@ -893,8 +912,8 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': -0.04, 'tax_ids': [], 'tax_line_id': self.tax_purchase_a.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -0.04, 'debit': 0.0, 'credit': 0.04, 'date_maturity': False, @@ -905,6 +924,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -1127.95, 'price_subtotal': -1127.95, 'price_total': -1127.95, + 'amount_currency': -1127.95, 'credit': 1127.95, }, ], { @@ -1067,6 +1087,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 0.05, 'price_subtotal': 0.01, 'price_total': 0.01, + 'amount_currency': 0.01, 'debit': 0.01, }, self.product_line_vals_2, @@ -1075,6 +1096,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 24.0, 'price_subtotal': 24.0, 'price_total': 24.0, + 'amount_currency': 24.0, 'debit': 24.0, }, self.tax_line_vals_2, @@ -1083,6 +1105,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -208.01, 'price_subtotal': -208.01, 'price_total': -208.01, + 'amount_currency': -208.01, 'credit': 208.01, }, ], { @@ -1126,27 +1149,32 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): self.assertInvoiceValues(reverse_move, [ { **self.product_line_vals_1, + 'amount_currency': -800.0, 'debit': 0.0, 'credit': 800.0, }, { **self.product_line_vals_2, + 'amount_currency': -160.0, 'debit': 0.0, 'credit': 160.0, }, { **self.tax_line_vals_1, + 'amount_currency': -144.0, 'debit': 0.0, 'credit': 144.0, }, { **self.tax_line_vals_2, + 'amount_currency': -24.0, 'debit': 0.0, 'credit': 24.0, }, { **self.term_line_vals_1, 'name': '', + 'amount_currency': 1128.0, 'debit': 1128.0, 'credit': 0.0, 'date_maturity': move_reversal.date, @@ -1172,27 +1200,32 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): self.assertInvoiceValues(reverse_move, [ { **self.product_line_vals_1, + 'amount_currency': -800.0, 'debit': 0.0, 'credit': 800.0, }, { **self.product_line_vals_2, + 'amount_currency': -160.0, 'debit': 0.0, 'credit': 160.0, }, { **self.tax_line_vals_1, + 'amount_currency': -144.0, 'debit': 0.0, 'credit': 144.0, }, { **self.tax_line_vals_2, + 'amount_currency': -24.0, 'debit': 0.0, 'credit': 24.0, }, { **self.term_line_vals_1, 'name': '', + 'amount_currency': 1128.0, 'debit': 1128.0, 'credit': 0.0, 'date_maturity': move_reversal.date, diff --git a/addons/account/tests/test_account_move_in_refund.py b/addons/account/tests/test_account_move_in_refund.py index 828903a5269..da76d527547 100644 --- a/addons/account/tests/test_account_move_in_refund.py +++ b/addons/account/tests/test_account_move_in_refund.py @@ -27,8 +27,8 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 920.0, 'tax_ids': cls.product_a.supplier_taxes_id.ids, 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': -800.0, 'debit': 0.0, 'credit': 800.0, 'date_maturity': False, @@ -47,8 +47,8 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 208.0, 'tax_ids': cls.product_b.supplier_taxes_id.ids, 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': -160.0, 'debit': 0.0, 'credit': 160.0, 'date_maturity': False, @@ -67,8 +67,8 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 144.0, 'tax_ids': [], 'tax_line_id': cls.tax_purchase_a.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': -144.0, 'debit': 0.0, 'credit': 144.0, 'date_maturity': False, @@ -87,8 +87,8 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 24.0, 'tax_ids': [], 'tax_line_id': cls.tax_purchase_b.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': -24.0, 'debit': 0.0, 'credit': 24.0, 'date_maturity': False, @@ -107,8 +107,8 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_total': -1128.0, 'tax_ids': [], 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': 1128.0, 'debit': 1128.0, 'credit': 0.0, 'date_maturity': fields.Date.from_string('2019-01-01'), @@ -154,6 +154,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_subtotal': 160.0, 'price_total': 208.0, 'tax_ids': self.product_b.supplier_taxes_id.ids, + 'amount_currency': -160.0, 'credit': 160.0, }, self.product_line_vals_2, @@ -162,6 +163,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 48.0, 'price_subtotal': 48.0, 'price_total': 48.0, + 'amount_currency': -48.0, 'credit': 48.0, }, { @@ -169,6 +171,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 48.0, 'price_subtotal': 48.0, 'price_total': 48.0, + 'amount_currency': -48.0, 'credit': 48.0, }, { @@ -176,6 +179,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -416.0, 'price_subtotal': -416.0, 'price_total': -416.0, + 'amount_currency': 416.0, 'debit': 416.0, }, ], { @@ -223,6 +227,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'discount': 100.0, 'price_subtotal': 0.0, 'price_total': 0.0, + 'amount_currency': 0.0, 'credit': 0.0, }, self.product_line_vals_2, @@ -231,6 +236,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 24.0, 'price_subtotal': 24.0, 'price_total': 24.0, + 'amount_currency': -24.0, 'credit': 24.0, }, self.tax_line_vals_2, @@ -239,6 +245,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -208.0, 'price_subtotal': -208.0, 'price_total': -208.0, + 'amount_currency': 208.0, 'debit': 208.0, }, ], { @@ -271,6 +278,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 3000.0, 'price_subtotal': 3000.0, 'price_total': 3450.0, + 'amount_currency': -3000.0, 'credit': 3000.0, }, { @@ -278,14 +286,16 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -500.0, 'price_subtotal': -500.0, 'price_total': -650.0, - 'credit': 0.0, + 'amount_currency': 500.0, 'debit': 500.0, + 'credit': 0.0, }, { **self.tax_line_vals_1, 'price_unit': 800.0, 'price_subtotal': 800.0, 'price_total': 800.0, + 'amount_currency': -800.0, 'credit': 800.0, }, { @@ -293,6 +303,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 250.0, 'price_subtotal': 250.0, 'price_total': 250.0, + 'amount_currency': -250.0, 'credit': 250.0, }, { @@ -300,6 +311,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -3550.0, 'price_subtotal': -3550.0, 'price_total': -3550.0, + 'amount_currency': 3550.0, 'debit': 3550.0, }, ], { @@ -340,6 +352,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -338.4, 'price_subtotal': -338.4, 'price_total': -338.4, + 'amount_currency': 338.4, 'debit': 338.4, }, { @@ -350,6 +363,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -789.6, 'price_subtotal': -789.6, 'price_total': -789.6, + 'amount_currency': 789.6, 'debit': 789.6, 'date_maturity': fields.Date.from_string('2019-02-28'), }, @@ -401,6 +415,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -331.2, 'price_subtotal': -331.2, 'price_total': -331.2, + 'amount_currency': 331.2, 'debit': 331.2, }, { @@ -411,6 +426,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -772.8, 'price_subtotal': -772.8, 'price_total': -772.8, + 'amount_currency': 772.8, 'debit': 772.8, 'date_maturity': fields.Date.from_string('2019-02-28'), }, @@ -460,8 +476,8 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 105.6, 'tax_ids': child_tax_2.ids, 'tax_line_id': child_tax_1.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -96.0, 'debit': 0.0, 'credit': 96.0, 'date_maturity': False, @@ -480,8 +496,8 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 70.4, 'tax_ids': child_tax_2.ids, 'tax_line_id': child_tax_1.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -64.0, 'debit': 0.0, 'credit': 64.0, 'date_maturity': False, @@ -500,8 +516,8 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 96.0, 'tax_ids': [], 'tax_line_id': child_tax_2.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -96.0, 'debit': 0.0, 'credit': 96.0, 'date_maturity': False, @@ -512,6 +528,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -1384.0, 'price_subtotal': -1384.0, 'price_total': -1384.0, + 'amount_currency': 1384.0, 'debit': 1384.0, }, ], { @@ -555,8 +572,8 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 0.01, 'tax_ids': [], 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -0.01, 'debit': 0.0, 'credit': 0.01, 'date_maturity': False, @@ -567,6 +584,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 799.99, 'price_subtotal': 799.99, 'price_total': 919.99, + 'amount_currency': -799.99, 'credit': 799.99, }, self.product_line_vals_2, @@ -586,6 +604,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 799.99, 'price_subtotal': 799.99, 'price_total': 919.99, + 'amount_currency': -799.99, 'credit': 799.99, }, self.product_line_vals_2, @@ -604,8 +623,8 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_total': -0.04, 'tax_ids': [], 'tax_line_id': self.tax_purchase_a.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 0.04, 'debit': 0.04, 'credit': 0.0, 'date_maturity': False, @@ -616,6 +635,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -1127.95, 'price_subtotal': -1127.95, 'price_total': -1127.95, + 'amount_currency': 1127.95, 'debit': 1127.95, }, ], { @@ -778,6 +798,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 0.05, 'price_subtotal': 0.01, 'price_total': 0.01, + 'amount_currency': -0.01, 'credit': 0.01, }, self.product_line_vals_2, @@ -786,6 +807,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 24.0, 'price_subtotal': 24.0, 'price_total': 24.0, + 'amount_currency': -24.0, 'credit': 24.0, }, self.tax_line_vals_2, @@ -794,6 +816,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -208.01, 'price_subtotal': -208.01, 'price_total': -208.01, + 'amount_currency': 208.01, 'debit': 208.01, }, ], { diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index e77eff26027..2e1ffcfdf39 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -30,8 +30,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 1150.0, 'tax_ids': cls.product_a.taxes_id.ids, 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': -1000.0, 'debit': 0.0, 'credit': 1000.0, 'date_maturity': False, @@ -50,8 +50,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 260.0, 'tax_ids': cls.product_b.taxes_id.ids, 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': -200.0, 'debit': 0.0, 'credit': 200.0, 'date_maturity': False, @@ -70,8 +70,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 180.0, 'tax_ids': [], 'tax_line_id': cls.tax_sale_a.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': -180.0, 'debit': 0.0, 'credit': 180.0, 'date_maturity': False, @@ -90,8 +90,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 30.0, 'tax_ids': [], 'tax_line_id': cls.tax_sale_b.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': -30.0, 'debit': 0.0, 'credit': 30.0, 'date_maturity': False, @@ -110,8 +110,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': -1410.0, 'tax_ids': [], 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': 1410.0, 'debit': 1410.0, 'credit': 0.0, 'date_maturity': fields.Date.from_string('2019-01-01'), @@ -157,6 +157,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_subtotal': 200.0, 'price_total': 260.0, 'tax_ids': self.product_b.taxes_id.ids, + 'amount_currency': -200.0, 'credit': 200.0, }, self.product_line_vals_2, @@ -165,6 +166,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 60.0, 'price_subtotal': 60.0, 'price_total': 60.0, + 'amount_currency': -60.0, 'credit': 60.0, }, { @@ -172,6 +174,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 60.0, 'price_subtotal': 60.0, 'price_total': 60.0, + 'amount_currency': -60.0, 'credit': 60.0, }, { @@ -179,6 +182,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -520.0, 'price_subtotal': -520.0, 'price_total': -520.0, + 'amount_currency': 520.0, 'debit': 520.0, }, ], { @@ -514,6 +518,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'discount': 100.0, 'price_subtotal': 0.0, 'price_total': 0.0, + 'amount_currency': 0.0, 'credit': 0.0, }, self.product_line_vals_2, @@ -522,6 +527,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 30.0, 'price_subtotal': 30.0, 'price_total': 30.0, + 'amount_currency': -30.0, 'credit': 30.0, }, self.tax_line_vals_2, @@ -530,6 +536,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -260.0, 'price_subtotal': -260.0, 'price_total': -260.0, + 'amount_currency': 260.0, 'debit': 260.0, }, ], { @@ -562,6 +569,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 3000.0, 'price_subtotal': 3000.0, 'price_total': 3450.0, + 'amount_currency': -3000.0, 'credit': 3000.0, }, { @@ -569,6 +577,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -500.0, 'price_subtotal': -500.0, 'price_total': -650.0, + 'amount_currency': 500.0, 'debit': 500.0, 'credit': 0.0, }, @@ -577,6 +586,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 800.0, 'price_subtotal': 800.0, 'price_total': 800.0, + 'amount_currency': -800.0, 'credit': 800.0, }, { @@ -584,6 +594,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 250.0, 'price_subtotal': 250.0, 'price_total': 250.0, + 'amount_currency': -250.0, 'credit': 250.0, }, { @@ -591,6 +602,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -3550.0, 'price_subtotal': -3550.0, 'price_total': -3550.0, + 'amount_currency': 3550.0, 'debit': 3550.0, }, ], { @@ -631,6 +643,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -423.0, 'price_subtotal': -423.0, 'price_total': -423.0, + 'amount_currency': 423.0, 'debit': 423.0, }, { @@ -641,6 +654,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -987.0, 'price_subtotal': -987.0, 'price_total': -987.0, + 'amount_currency': 987.0, 'debit': 987.0, 'date_maturity': fields.Date.from_string('2019-02-28'), }, @@ -692,6 +706,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -414.0, 'price_subtotal': -414.0, 'price_total': -414.0, + 'amount_currency': 414.0, 'debit': 414.0, }, { @@ -702,6 +717,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -966.0, 'price_subtotal': -966.0, 'price_total': -966.0, + 'amount_currency': 966.0, 'debit': 966.0, 'date_maturity': fields.Date.from_string('2019-02-28'), }, @@ -751,8 +767,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 132.0, 'tax_ids': child_tax_2.ids, 'tax_line_id': child_tax_1.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -120.0, 'debit': 0.0, 'credit': 120.0, 'date_maturity': False, @@ -771,8 +787,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 88.0, 'tax_ids': child_tax_2.ids, 'tax_line_id': child_tax_1.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -80.0, 'debit': 0.0, 'credit': 80.0, 'date_maturity': False, @@ -791,8 +807,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 120.0, 'tax_ids': [], 'tax_line_id': child_tax_2.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -120.0, 'debit': 0.0, 'credit': 120.0, 'date_maturity': False, @@ -803,6 +819,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -1730.0, 'price_subtotal': -1730.0, 'price_total': -1730.0, + 'amount_currency': 1730.0, 'debit': 1730.0, }, ], { @@ -920,6 +937,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_subtotal': 2180.09, 'price_total': 2627.01, 'tax_ids': (self.product_a.taxes_id + tax_price_include).ids, + 'amount_currency': -2180.09, 'credit': 2180.09, }, { @@ -927,6 +945,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 327.01, 'price_subtotal': 327.01, 'price_total': 327.01, + 'amount_currency': -327.01, 'credit': 327.01, }, { @@ -942,8 +961,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 119.91, 'tax_ids': [], 'tax_line_id': tax_price_include.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -119.91, 'debit': 0.0, 'credit': 119.91, 'date_maturity': False, @@ -954,6 +973,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -2627.01, 'price_subtotal': -2627.01, 'price_total': -2627.01, + 'amount_currency': 2627.01, 'debit': 2627.01, }, ], { @@ -975,6 +995,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_subtotal': -2180.09, 'price_total': -2627.01, 'tax_ids': (self.product_a.taxes_id + tax_price_include).ids, + 'amount_currency': 2180.09, 'debit': 2180.09, 'credit': 0.0, }, @@ -983,6 +1004,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -327.01, 'price_subtotal': -327.01, 'price_total': -327.01, + 'amount_currency': 327.01, 'debit': 327.01, 'credit': 0.0, }, @@ -999,8 +1021,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': -119.91, 'tax_ids': [], 'tax_line_id': tax_price_include.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 119.91, 'debit': 119.91, 'credit': 0.0, 'date_maturity': False, @@ -1011,6 +1033,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 2627.01, 'price_subtotal': 2627.01, 'price_total': 2627.01, + 'amount_currency': -2627.01, 'debit': 0.0, 'credit': 2627.01, }, @@ -1233,6 +1256,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 150.0, 'price_subtotal': 150.0, 'price_total': 150.0, + 'amount_currency': -150.0, 'credit': 150.0, 'analytic_account_id': analytic_account.id, 'analytic_tag_ids': analytic_tag.ids, @@ -1242,6 +1266,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 30.0, 'price_subtotal': 30.0, 'price_total': 30.0, + 'amount_currency': -30.0, 'credit': 30.0, 'analytic_account_id': False, 'analytic_tag_ids': [], @@ -1327,8 +1352,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': 0.01, 'tax_ids': [], 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -0.01, 'debit': 0.0, 'credit': 0.01, 'date_maturity': False, @@ -1339,6 +1364,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 999.99, 'price_subtotal': 999.99, 'price_total': 1149.99, + 'amount_currency': -999.99, 'credit': 999.99, }, self.product_line_vals_2, @@ -1358,6 +1384,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 999.99, 'price_subtotal': 999.99, 'price_total': 1149.99, + 'amount_currency': -999.99, 'credit': 999.99, }, self.product_line_vals_2, @@ -1376,8 +1403,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_total': -0.04, 'tax_ids': [], 'tax_line_id': self.tax_sale_a.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 0.04, 'debit': 0.04, 'credit': 0.0, 'date_maturity': False, @@ -1388,6 +1415,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -1409.95, 'price_subtotal': -1409.95, 'price_total': -1409.95, + 'amount_currency': 1409.95, 'debit': 1409.95, }, ], { @@ -1550,6 +1578,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 0.05, 'price_subtotal': 0.01, 'price_total': 0.01, + 'amount_currency': -0.01, 'credit': 0.01, }, self.product_line_vals_2, @@ -1558,6 +1587,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': 30.0, 'price_subtotal': 30.0, 'price_total': 30.0, + 'amount_currency': -30.0, 'credit': 30.0, }, self.tax_line_vals_2, @@ -1566,6 +1596,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'price_unit': -260.01, 'price_subtotal': -260.01, 'price_total': -260.01, + 'amount_currency': 260.01, 'debit': 260.01, }, ], { @@ -1592,27 +1623,32 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): self.assertInvoiceValues(reverse_move, [ { **self.product_line_vals_1, + 'amount_currency': 1000.0, 'debit': 1000.0, 'credit': 0.0, }, { **self.product_line_vals_2, + 'amount_currency': 200.0, 'debit': 200.0, 'credit': 0.0, }, { **self.tax_line_vals_1, + 'amount_currency': 180.0, 'debit': 180.0, 'credit': 0.0, }, { **self.tax_line_vals_2, + 'amount_currency': 30.0, 'debit': 30.0, 'credit': 0.0, }, { **self.term_line_vals_1, 'name': '', + 'amount_currency': -1410.0, 'debit': 0.0, 'credit': 1410.0, 'date_maturity': move_reversal.date, @@ -1639,27 +1675,32 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): self.assertInvoiceValues(reverse_move, [ { **self.product_line_vals_1, + 'amount_currency': 1000.0, 'debit': 1000.0, 'credit': 0.0, }, { **self.product_line_vals_2, + 'amount_currency': 200.0, 'debit': 200.0, 'credit': 0.0, }, { **self.tax_line_vals_1, + 'amount_currency': 180.0, 'debit': 180.0, 'credit': 0.0, }, { **self.tax_line_vals_2, + 'amount_currency': 30.0, 'debit': 30.0, 'credit': 0.0, }, { **self.term_line_vals_1, 'name': '', + 'amount_currency': -1410.0, 'debit': 0.0, 'credit': 1410.0, 'date_maturity': move_reversal.date, @@ -1808,8 +1849,20 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'currency_id': self.currency_data['currency'].id, 'invoice_payment_term_id': self.pay_terms_a.id, 'invoice_line_ids': [ - (0, None, self.product_line_vals_1), - (0, None, self.product_line_vals_2), + (0, None, { + 'product_id': self.product_a.id, + 'product_uom_id': self.product_a.uom_id.id, + 'quantity': 1.0, + 'price_unit': 1000.0, + 'tax_ids': [(6, 0, self.product_a.taxes_id.ids)], + }), + (0, None, { + 'product_id': self.product_b.id, + 'product_uom_id': self.product_b.uom_id.id, + 'quantity': 1.0, + 'price_unit': 200.0, + 'tax_ids': [(6, 0, self.product_b.taxes_id.ids)], + }), ] }) @@ -1909,7 +1962,11 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'move_type': 'out_invoice', 'partner_id': self.partner_a.id, 'invoice_line_ids': [ - (0, None, self.product_line_vals_1), + (0, None, { + 'name': 'test_out_invoice_write_2', + 'quantity': 1.0, + 'price_unit': 2000, + }), ] }) diff --git a/addons/account/tests/test_account_move_out_refund.py b/addons/account/tests/test_account_move_out_refund.py index 79f48164a65..59472be893d 100644 --- a/addons/account/tests/test_account_move_out_refund.py +++ b/addons/account/tests/test_account_move_out_refund.py @@ -27,8 +27,8 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 1150.0, 'tax_ids': cls.product_a.taxes_id.ids, 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': 1000.0, 'debit': 1000.0, 'credit': 0.0, 'date_maturity': False, @@ -47,8 +47,8 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 260.0, 'tax_ids': cls.product_b.taxes_id.ids, 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': 200.0, 'debit': 200.0, 'credit': 0.0, 'date_maturity': False, @@ -67,8 +67,8 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 180.0, 'tax_ids': [], 'tax_line_id': cls.tax_sale_a.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': 180.0, 'debit': 180.0, 'credit': 0.0, 'date_maturity': False, @@ -87,8 +87,8 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 30.0, 'tax_ids': [], 'tax_line_id': cls.tax_sale_b.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': 30.0, 'debit': 30.0, 'credit': 0.0, 'date_maturity': False, @@ -107,8 +107,8 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_total': -1410.0, 'tax_ids': [], 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': cls.company_data['currency'].id, + 'amount_currency': -1410.0, 'debit': 0.0, 'credit': 1410.0, 'date_maturity': fields.Date.from_string('2019-01-01'), @@ -154,6 +154,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_subtotal': 200.0, 'price_total': 260.0, 'tax_ids': self.product_b.taxes_id.ids, + 'amount_currency': 200.0, 'debit': 200.0, }, self.product_line_vals_2, @@ -162,6 +163,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 60.0, 'price_subtotal': 60.0, 'price_total': 60.0, + 'amount_currency': 60.0, 'debit': 60.0, }, { @@ -169,6 +171,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 60.0, 'price_subtotal': 60.0, 'price_total': 60.0, + 'amount_currency': 60.0, 'debit': 60.0, }, { @@ -176,6 +179,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -520.0, 'price_subtotal': -520.0, 'price_total': -520.0, + 'amount_currency': -520.0, 'credit': 520.0, }, ], { @@ -223,6 +227,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'discount': 100.0, 'price_subtotal': 0.0, 'price_total': 0.0, + 'amount_currency': 0.0, 'debit': 0.0, }, self.product_line_vals_2, @@ -231,6 +236,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 30.0, 'price_subtotal': 30.0, 'price_total': 30.0, + 'amount_currency': 30.0, 'debit': 30.0, }, self.tax_line_vals_2, @@ -239,6 +245,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -260.0, 'price_subtotal': -260.0, 'price_total': -260.0, + 'amount_currency': -260.0, 'credit': 260.0, }, ], { @@ -271,6 +278,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 3000.0, 'price_subtotal': 3000.0, 'price_total': 3450.0, + 'amount_currency': 3000.0, 'debit': 3000.0, }, { @@ -278,6 +286,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -500.0, 'price_subtotal': -500.0, 'price_total': -650.0, + 'amount_currency': -500.0, 'debit': 0.0, 'credit': 500.0, }, @@ -286,6 +295,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 800.0, 'price_subtotal': 800.0, 'price_total': 800.0, + 'amount_currency': 800.0, 'debit': 800.0, }, { @@ -293,6 +303,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 250.0, 'price_subtotal': 250.0, 'price_total': 250.0, + 'amount_currency': 250.0, 'debit': 250.0, }, { @@ -300,6 +311,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -3550.0, 'price_subtotal': -3550.0, 'price_total': -3550.0, + 'amount_currency': -3550.0, 'credit': 3550.0, }, ], { @@ -340,6 +352,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -987.0, 'price_subtotal': -987.0, 'price_total': -987.0, + 'amount_currency': -987.0, 'credit': 987.0, 'date_maturity': fields.Date.from_string('2019-02-28'), }, @@ -351,6 +364,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -423.0, 'price_subtotal': -423.0, 'price_total': -423.0, + 'amount_currency': -423.0, 'credit': 423.0, }, ], { @@ -401,6 +415,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -966.0, 'price_subtotal': -966.0, 'price_total': -966.0, + 'amount_currency': -966.0, 'credit': 966.0, 'date_maturity': fields.Date.from_string('2019-02-28'), }, @@ -412,6 +427,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -414.0, 'price_subtotal': -414.0, 'price_total': -414.0, + 'amount_currency': -414.0, 'credit': 414.0, }, ], { @@ -460,8 +476,8 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 88.0, 'tax_ids': child_tax_2.ids, 'tax_line_id': child_tax_1.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 80.0, 'debit': 80.0, 'credit': 0.0, 'date_maturity': False, @@ -480,8 +496,8 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 132.0, 'tax_ids': child_tax_2.ids, 'tax_line_id': child_tax_1.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 120.0, 'debit': 120.0, 'credit': 0.0, 'date_maturity': False, @@ -500,8 +516,8 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 120.0, 'tax_ids': [], 'tax_line_id': child_tax_2.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 120.0, 'debit': 120.0, 'credit': 0.0, 'date_maturity': False, @@ -512,6 +528,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -1730.0, 'price_subtotal': -1730.0, 'price_total': -1730.0, + 'amount_currency': -1730.0, 'credit': 1730.0, }, ], { @@ -555,8 +572,8 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_total': 0.01, 'tax_ids': [], 'tax_line_id': False, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 0.01, 'debit': 0.01, 'credit': 0.0, 'date_maturity': False, @@ -567,6 +584,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 999.99, 'price_subtotal': 999.99, 'price_total': 1149.99, + 'amount_currency': 999.99, 'debit': 999.99, }, self.product_line_vals_2, @@ -586,6 +604,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 999.99, 'price_subtotal': 999.99, 'price_total': 1149.99, + 'amount_currency': 999.99, 'debit': 999.99, }, self.product_line_vals_2, @@ -604,8 +623,8 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_total': -0.04, 'tax_ids': [], 'tax_line_id': self.tax_sale_a.id, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -0.04, 'debit': 0.0, 'credit': 0.04, 'date_maturity': False, @@ -616,6 +635,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -1409.95, 'price_subtotal': -1409.95, 'price_total': -1409.95, + 'amount_currency': -1409.95, 'credit': 1409.95, }, ], { @@ -778,6 +798,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 0.05, 'price_subtotal': 0.01, 'price_total': 0.01, + 'amount_currency': 0.01, 'debit': 0.01, }, self.product_line_vals_2, @@ -786,6 +807,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': 30.0, 'price_subtotal': 30.0, 'price_total': 30.0, + 'amount_currency': 30.0, 'debit': 30.0, }, self.tax_line_vals_2, @@ -794,6 +816,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): 'price_unit': -260.01, 'price_subtotal': -260.01, 'price_total': -260.01, + 'amount_currency': -260.01, 'credit': 260.01, }, ], { diff --git a/addons/account/tests/test_account_move_payments_widget.py b/addons/account/tests/test_account_move_payments_widget.py index f4c0d9fffa3..b4a49515ec5 100644 --- a/addons/account/tests/test_account_move_payments_widget.py +++ b/addons/account/tests/test_account_move_payments_widget.py @@ -29,8 +29,8 @@ class TestAccountMovePaymentsWidget(AccountTestInvoicingCommon): cls.payment_2016_curr_1 = cls.env['account.move'].create({ 'date': '2016-01-01', 'line_ids': [ - (0, 0, {'debit': 0.0, 'credit': 500.0, 'amount_currency': 0.0, 'currency_id': False, 'account_id': cls.receivable_account.id, 'partner_id': cls.partner_a.id}), - (0, 0, {'debit': 500.0, 'credit': 0.0, 'amount_currency': 0.0, 'currency_id': False, 'account_id': cls.payable_account.id, 'partner_id': cls.partner_a.id}), + (0, 0, {'debit': 0.0, 'credit': 500.0, 'amount_currency': -500.0, 'currency_id': cls.curr_1.id, 'account_id': cls.receivable_account.id, 'partner_id': cls.partner_a.id}), + (0, 0, {'debit': 500.0, 'credit': 0.0, 'amount_currency': 500.0, 'currency_id': cls.curr_1.id, 'account_id': cls.payable_account.id, 'partner_id': cls.partner_a.id}), ], }) cls.payment_2016_curr_1.action_post() diff --git a/addons/account/tests/test_account_move_reconcile.py b/addons/account/tests/test_account_move_reconcile.py index 3ea1b77c36e..5b8d5b2c617 100644 --- a/addons/account/tests/test_account_move_reconcile.py +++ b/addons/account/tests/test_account_move_reconcile.py @@ -249,11 +249,11 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): line_5 = move.line_ids.filtered(lambda line: line.credit == 500.0) self.assertRecordValues(line_1 + line_2 + line_3 + line_4 + line_5, [ - {'amount_residual': 1000.0, 'amount_residual_currency': 0.0, 'reconciled': False}, - {'amount_residual': 200.0, 'amount_residual_currency': 0.0, 'reconciled': False}, - {'amount_residual': -300.0, 'amount_residual_currency': 0.0, 'reconciled': False}, - {'amount_residual': -400.0, 'amount_residual_currency': 0.0, 'reconciled': False}, - {'amount_residual': -500.0, 'amount_residual_currency': 0.0, 'reconciled': False}, + {'amount_residual': 1000.0, 'amount_residual_currency': 1000.0, 'reconciled': False}, + {'amount_residual': 200.0, 'amount_residual_currency': 200.0, 'reconciled': False}, + {'amount_residual': -300.0, 'amount_residual_currency': -300.0, 'reconciled': False}, + {'amount_residual': -400.0, 'amount_residual_currency': -400.0, 'reconciled': False}, + {'amount_residual': -500.0, 'amount_residual_currency': -500.0, 'reconciled': False}, ]) res = (line_1 + line_3).reconcile() @@ -267,7 +267,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): }]) self.assertRecordValues(line_1 + line_3, [ - {'amount_residual': 700.0, 'amount_residual_currency': 0.0, 'reconciled': False}, + {'amount_residual': 700.0, 'amount_residual_currency': 700.0, 'reconciled': False}, {'amount_residual': 0.0, 'amount_residual_currency': 0.0, 'reconciled': True}, ]) @@ -282,7 +282,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): }]) self.assertRecordValues(line_1 + line_4, [ - {'amount_residual': 300.0, 'amount_residual_currency': 0.0, 'reconciled': False}, + {'amount_residual': 300.0, 'amount_residual_currency': 300.0, 'reconciled': False}, {'amount_residual': 0.0, 'amount_residual_currency': 0.0, 'reconciled': True}, ]) @@ -298,7 +298,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): self.assertRecordValues(line_1 + line_5, [ {'amount_residual': 0.0, 'amount_residual_currency': 0.0, 'reconciled': True}, - {'amount_residual': -200.0, 'amount_residual_currency': 0.0, 'reconciled': False}, + {'amount_residual': -200.0, 'amount_residual_currency': -200.0, 'reconciled': False}, ]) res = (line_2 + line_5).reconcile() @@ -757,7 +757,7 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): self.assertAmountsGroupByAccount([ # Account Balance Amount Currency - (self.cash_basis_transfer_account, -33.34, 0.0), + (self.cash_basis_transfer_account, -33.34, -33.34), (self.tax_account_1, 0.0, 0.0), (self.tax_account_2, 0.0, 0.0), ]) @@ -798,8 +798,8 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): self.assertAmountsGroupByAccount([ # Account Balance Amount Currency - (self.cash_basis_transfer_account, -22.23, 0.0), - (self.tax_account_1, -11.11, 0.0), + (self.cash_basis_transfer_account, -22.23, -22.23), + (self.tax_account_1, -11.11, -11.11), (self.tax_account_2, 0.0, 0.0), ]) @@ -850,8 +850,8 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): self.assertAmountsGroupByAccount([ # Account Balance Amount Currency - (self.cash_basis_transfer_account, -0.01, 0.0), - (self.tax_account_1, -33.33, 0.0), + (self.cash_basis_transfer_account, -0.01, -0.01), + (self.tax_account_1, -33.33, -33.33), (self.tax_account_2, 0.0, 0.0), ]) @@ -879,8 +879,8 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon): self.assertAmountsGroupByAccount([ # Account Balance Amount Currency (self.cash_basis_transfer_account, 0.0, 0.0), - (self.tax_account_1, -33.33, 0.0), - (self.tax_account_2, -0.01, 0.0), + (self.tax_account_1, -33.33, -33.33), + (self.tax_account_2, -0.01, -0.01), ]) def test_reconcile_cash_basis_workflow_multi_currency(self): diff --git a/addons/account/tests/test_account_payment.py b/addons/account/tests/test_account_payment.py index 147643e975d..3fba9143ccf 100644 --- a/addons/account/tests/test_account_payment.py +++ b/addons/account/tests/test_account_payment.py @@ -61,15 +61,15 @@ class TestAccountPayment(AccountTestInvoicingCommon): expected_liquidity_line = { 'debit': 50.0, 'credit': 0.0, - 'amount_currency': 0.0, - 'currency_id': False, + 'amount_currency': 50.0, + 'currency_id': self.company_data['currency'].id, 'account_id': self.payment_debit_account_id.id, } expected_counterpart_line = { 'debit': 0.0, 'credit': 50.0, - 'amount_currency': 0.0, - 'currency_id': False, + 'amount_currency': -50.0, + 'currency_id': self.company_data['currency'].id, 'account_id': copy_receivable.id, } @@ -129,16 +129,16 @@ class TestAccountPayment(AccountTestInvoicingCommon): (1, counterpart_lines.id, { 'debit': 0.0, 'credit': 75.0, - 'amount_currency': 0.0, - 'currency_id': False, + 'amount_currency': -75.0, + 'currency_id': self.company_data['currency'].id, 'account_id': copy_receivable.id, 'partner_id': self.partner_b.id, }), (1, liquidity_lines.id, { 'debit': 100.0, 'credit': 0.0, - 'amount_currency': 0.0, - 'currency_id': False, + 'amount_currency': 100.0, + 'currency_id': self.company_data['currency'].id, 'partner_id': self.partner_b.id, }), @@ -146,8 +146,8 @@ class TestAccountPayment(AccountTestInvoicingCommon): (0, 0, { 'debit': 0.0, 'credit': 25.0, - 'amount_currency': 0.0, - 'currency_id': False, + 'amount_currency': -25.0, + 'currency_id': self.company_data['currency'].id, 'account_id': self.company_data['default_account_revenue'].id, 'partner_id': self.partner_b.id, }), @@ -168,13 +168,14 @@ class TestAccountPayment(AccountTestInvoicingCommon): **expected_counterpart_line, 'debit': 0.0, 'credit': 75.0, + 'amount_currency': -75.0, 'partner_id': self.partner_b.id, }, { 'debit': 0.0, 'credit': 25.0, - 'amount_currency': 0.0, - 'currency_id': False, + 'amount_currency': -25.0, + 'currency_id': self.company_data['currency'].id, 'account_id': self.company_data['default_account_revenue'].id, 'partner_id': self.partner_b.id, }, @@ -182,6 +183,7 @@ class TestAccountPayment(AccountTestInvoicingCommon): **expected_liquidity_line, 'debit': 100.0, 'credit': 0.0, + 'amount_currency': 100.0, 'account_id': self.payment_debit_account_id.id, 'partner_id': self.partner_b.id, }, @@ -215,15 +217,15 @@ class TestAccountPayment(AccountTestInvoicingCommon): expected_liquidity_line = { 'debit': 50.0, 'credit': 0.0, - 'amount_currency': 0.0, - 'currency_id': False, + 'amount_currency': 50.0, + 'currency_id': self.company_data['currency'].id, 'account_id': self.payment_debit_account_id.id, } expected_counterpart_line = { 'debit': 0.0, 'credit': 50.0, - 'amount_currency': 0.0, - 'currency_id': False, + 'amount_currency': -50.0, + 'currency_id': self.company_data['currency'].id, 'account_id': copy_receivable.id, } @@ -276,20 +278,17 @@ class TestAccountPayment(AccountTestInvoicingCommon): move_form = Form(payment.move_id) with move_form.line_ids.edit(0) as line_form: - line_form.currency_id = self.env['res.currency'] - line_form.amount_currency = 0.0 - line_form.debit = 100.0 + line_form.currency_id = self.company_data['currency'] + line_form.amount_currency = 100.0 line_form.partner_id = self.partner_b with move_form.line_ids.edit(1) as line_form: - line_form.currency_id = self.env['res.currency'] - line_form.amount_currency = 0.0 - line_form.credit = 75.0 + line_form.currency_id = self.company_data['currency'] + line_form.amount_currency = -75.0 line_form.account_id = copy_receivable line_form.partner_id = self.partner_b with move_form.line_ids.new() as line_form: - line_form.currency_id = self.env['res.currency'] - line_form.amount_currency = 0.0 - line_form.credit = 25.0 + line_form.currency_id = self.company_data['currency'] + line_form.amount_currency = -25.0 line_form.account_id = self.company_data['default_account_revenue'] line_form.partner_id = self.partner_b move_form.save() @@ -304,13 +303,14 @@ class TestAccountPayment(AccountTestInvoicingCommon): **expected_counterpart_line, 'debit': 0.0, 'credit': 75.0, + 'amount_currency': -75.0, 'partner_id': self.partner_b.id, }, { 'debit': 0.0, 'credit': 25.0, - 'amount_currency': 0.0, - 'currency_id': False, + 'amount_currency': -25.0, + 'currency_id': self.company_data['currency'].id, 'account_id': self.company_data['default_account_revenue'].id, 'partner_id': self.partner_b.id, }, @@ -318,6 +318,7 @@ class TestAccountPayment(AccountTestInvoicingCommon): **expected_liquidity_line, 'debit': 100.0, 'credit': 0.0, + 'amount_currency': 100.0, 'account_id': self.payment_debit_account_id.id, 'partner_id': self.partner_b.id, }, @@ -345,15 +346,15 @@ class TestAccountPayment(AccountTestInvoicingCommon): expected_liquidity_line = { 'debit': 50.0, 'credit': 0.0, - 'amount_currency': 0.0, - 'currency_id': False, + 'amount_currency': 50.0, + 'currency_id': self.company_data['currency'].id, 'account_id': self.payment_debit_account_id.id, } expected_counterpart_line = { 'debit': 0.0, 'credit': 50.0, - 'amount_currency': 0.0, - 'currency_id': False, + 'amount_currency': -50.0, + 'currency_id': self.company_data['currency'].id, 'account_id': self.company_data['company'].transfer_account_id.id, } diff --git a/addons/account/tests/test_account_payment_register.py b/addons/account/tests/test_account_payment_register.py index db51a0efde6..6a04bdb0bd5 100644 --- a/addons/account/tests/test_account_payment_register.py +++ b/addons/account/tests/test_account_payment_register.py @@ -257,24 +257,24 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): { 'debit': 0.0, 'credit': 2200.0, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -2200.0, 'reconciled': False, }, # Liquidity line: { 'debit': 0.0, 'credit': 800.0, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -800.0, 'reconciled': False, }, # Payable line: { 'debit': 3000.0, 'credit': 0.0, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 3000.0, 'reconciled': True, }, ]) @@ -299,24 +299,24 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): { 'debit': 0.0, 'credit': 3100.0, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -3100.0, 'reconciled': False, }, # Writeoff line: { 'debit': 100.0, 'credit': 0.0, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 100.0, 'reconciled': False, }, # Payable line: { 'debit': 3000.0, 'credit': 0.0, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 3000.0, 'reconciled': True, }, ]) @@ -388,16 +388,16 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): { 'debit': 0.0, 'credit': 3000.0, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -3000.0, 'reconciled': False, }, # Payable line: { 'debit': 3000.0, 'credit': 0.0, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 3000.0, 'reconciled': True, }, # == Payment 2: to pay in_invoice_3 == @@ -439,16 +439,16 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): { 'debit': 0.0, 'credit': 1000.0, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -1000.0, 'reconciled': False, }, # Payable line: { 'debit': 1000.0, 'credit': 0.0, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 1000.0, 'reconciled': True, }, # == Payment 2: to pay in_invoice_2 == @@ -456,16 +456,16 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): { 'debit': 0.0, 'credit': 2000.0, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -2000.0, 'reconciled': False, }, # Payable line: { 'debit': 2000.0, 'credit': 0.0, - 'currency_id': False, - 'amount_currency': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 2000.0, 'reconciled': True, }, # == Payment 3: to pay in_invoice_3 == diff --git a/addons/account/tests/test_reconciliation.py b/addons/account/tests/test_reconciliation.py index e8bbf84da9e..32e433ce666 100644 --- a/addons/account/tests/test_reconciliation.py +++ b/addons/account/tests/test_reconciliation.py @@ -61,9 +61,9 @@ class TestReconciliationExec(TestAccountReconciliationCommon): ]) self.assertRecordValues(bank_stmt.line_ids.line_ids, [ - {'debit': 40.0, 'credit': 0.0, 'amount_currency': 0.0, 'currency_id': False}, - {'debit': 0.0, 'credit': 7.3, 'amount_currency': 0.0, 'currency_id': False}, - {'debit': 0.0, 'credit': 32.7, 'amount_currency': 0.0, 'currency_id': False}, + {'debit': 40.0, 'credit': 0.0, 'amount_currency': 40.0, 'currency_id': self.currency_euro_id}, + {'debit': 0.0, 'credit': 7.3, 'amount_currency': -7.3, 'currency_id': self.currency_euro_id}, + {'debit': 0.0, 'credit': 32.7, 'amount_currency': -32.7, 'currency_id': self.currency_euro_id}, ]) # The invoice should be paid, as the payments totally cover its total @@ -205,68 +205,6 @@ class TestReconciliationExec(TestAccountReconciliationCommon): self.assertEqual(aml.amount_residual, 0, 'The journal item should be totally reconciled') self.assertEqual(aml.amount_residual_currency, 0, 'The journal item should be totally reconciled') - def test_manual_reconcile_wizard_same_account(self): - move_ids = self.env['account.move'] - debit_line_vals = { - 'name': '1', - 'debit': 728.35, - 'credit': 0.0, - 'account_id': self.account_rcv.id, - 'amount_currency': 795.05, - 'currency_id': self.currency_swiss_id, - } - credit_line_vals = { - 'name': '1', - 'debit': 0.0, - 'credit': 728.35, - 'account_id': self.account_rsa.id, - 'amount_currency': -795.05, - 'currency_id': self.currency_swiss_id, - } - vals = { - 'journal_id': self.bank_journal_euro.id, - 'date': time.strftime('%Y') + '-02-15', - 'line_ids': [(0,0, debit_line_vals), (0, 0, credit_line_vals)] - } - move_ids += self.env['account.move'].create(vals) - debit_line_vals = { - 'name': '2', - 'debit': 0.0, - 'credit': 737.10, - 'account_id': self.account_rcv.id, - 'amount_currency': -811.25, - 'currency_id': self.currency_swiss_id, - } - credit_line_vals = { - 'name': '2', - 'debit': 737.10, - 'credit': 0.0, - 'account_id': self.account_rsa.id, - 'amount_currency': 811.25, - 'currency_id': self.currency_swiss_id, - } - vals = { - 'journal_id': self.bank_journal_euro.id, - 'date': time.strftime('%Y') + '-07-15', - 'line_ids': [(0,0, debit_line_vals), (0, 0, credit_line_vals)] - } - move_ids += self.env['account.move'].create(vals) - move_ids.action_post() - - account_move_line = move_ids.mapped('line_ids').filtered(lambda l: l.account_id == self.account_rcv) - writeoff_vals = [{ - 'account_id': self.account_rcv.id, - 'journal_id': self.bank_journal_euro.id, - 'date': time.strftime('%Y') + '-04-15', - 'debit': 8.75, - 'credit': 0.0 - }] - writeoff_line = account_move_line._create_writeoff(writeoff_vals) - (account_move_line + writeoff_line).reconcile() - self.assertEqual(len(writeoff_line), 1, "The writeoff_line (balance_line) should have only one moves line") - self.assertTrue(all(l.reconciled for l in writeoff_line), 'The balance lines should be totally reconciled') - self.assertTrue(all(l.reconciled for l in account_move_line), 'The move lines should be totally reconciled') - def test_partial_reconcile_currencies_01(self): # client Account (payable, rsa) # Debit Credit diff --git a/addons/account/tests/test_transfer_wizard.py b/addons/account/tests/test_transfer_wizard.py index 03b76235398..eb78a3dae80 100644 --- a/addons/account/tests/test_transfer_wizard.py +++ b/addons/account/tests/test_transfer_wizard.py @@ -233,16 +233,16 @@ class TestTransferWizard(AccountTestInvoicingCommon): groups = {} for line in transfer_move.line_ids: - key = (line.account_id, line.partner_id or None, line.currency_id or None) + key = (line.account_id, line.partner_id or None, line.currency_id) self.assertFalse(groups.get(key), "There should be only one line per (account, partner, currency) group in the transfer move.") groups[key] = line - self.assertAlmostEqual(groups[(self.accounts[0], self.partner_a, None)].balance, -800, self.company.currency_id.decimal_places) - self.assertAlmostEqual(groups[(self.accounts[1], None, None)].balance, 500, self.company.currency_id.decimal_places) - self.assertAlmostEqual(groups[(self.accounts[1], self.partner_b, None)].balance, -480, self.company.currency_id.decimal_places) - self.assertAlmostEqual(groups[(self.accounts[2], self.partner_a, None)].balance, 1030, self.company.currency_id.decimal_places) + self.assertAlmostEqual(groups[(self.accounts[0], self.partner_a, self.company_data['currency'])].balance, -800, self.company.currency_id.decimal_places) + self.assertAlmostEqual(groups[(self.accounts[1], None, self.company_data['currency'])].balance, 500, self.company.currency_id.decimal_places) + self.assertAlmostEqual(groups[(self.accounts[1], self.partner_b, self.company_data['currency'])].balance, -480, self.company.currency_id.decimal_places) + self.assertAlmostEqual(groups[(self.accounts[2], self.partner_a, self.company_data['currency'])].balance, 1030, self.company.currency_id.decimal_places) self.assertAlmostEqual(groups[(self.accounts[2], self.partner_a, self.test_currency_2)].balance, 512, self.company.currency_id.decimal_places) - self.assertAlmostEqual(groups[(self.accounts[3], self.partner_a, None)].balance, -250, self.company.currency_id.decimal_places) + self.assertAlmostEqual(groups[(self.accounts[3], self.partner_a, self.company_data['currency'])].balance, -250, self.company.currency_id.decimal_places) def test_transfer_wizard_currency_conversion(self): diff --git a/addons/account/views/account_move_views.xml b/addons/account/views/account_move_views.xml index 4293930f601..92ab0e8f727 100644 --- a/addons/account/views/account_move_views.xml +++ b/addons/account/views/account_move_views.xml @@ -694,7 +694,7 @@ + context="{'default_move_type': context.get('default_move_type'), 'journal_id': journal_id, 'default_partner_id': commercial_partner_id, 'default_currency_id': currency_id or company_currency_id}"> @@ -765,7 +765,6 @@ - @@ -845,7 +844,6 @@ -
@@ -900,7 +898,7 @@ This entry has been generated through the Invoicing app, before installing Accounting. Its balance has been imported separately. diff --git a/addons/account/wizard/account_automatic_entry_wizard.py b/addons/account/wizard/account_automatic_entry_wizard.py index 2259dacb922..c3f5cb49b47 100644 --- a/addons/account/wizard/account_automatic_entry_wizard.py +++ b/addons/account/wizard/account_automatic_entry_wizard.py @@ -112,9 +112,7 @@ class AutomaticEntryWizard(models.TransientModel): counterpart_currency = self.destination_account_id.currency_id counterpart_amount_currency = self.company_id.currency_id._convert(line.balance, self.destination_account_id.currency_id, self.company_id, line.date) - if counterpart_currency: - counterpart_balances[(line.partner_id, counterpart_currency)]['amount_currency'] += counterpart_amount_currency - + counterpart_balances[(line.partner_id, counterpart_currency)]['amount_currency'] += counterpart_amount_currency counterpart_balances[(line.partner_id, counterpart_currency)]['balance'] += line.balance grouped_source_lines[(line.partner_id, line.currency_id, line.account_id)] += line @@ -123,29 +121,29 @@ class AutomaticEntryWizard(models.TransientModel): source_accounts = self.move_line_ids.mapped('account_id') counterpart_label = len(source_accounts) == 1 and _("Transfer from %s", source_accounts.display_name) or _("Transfer counterpart") - if not self.company_id.currency_id.is_zero(counterpart_vals['balance']) or (counterpart_currency and not counterpart_currency.is_zero(counterpart_vals['amount_currency'])): + if not counterpart_currency.is_zero(counterpart_vals['amount_currency']): line_vals.append({ 'name': counterpart_label, 'debit': counterpart_vals['balance'] > 0 and self.company_id.currency_id.round(counterpart_vals['balance']) or 0, 'credit': counterpart_vals['balance'] < 0 and self.company_id.currency_id.round(-counterpart_vals['balance']) or 0, 'account_id': self.destination_account_id.id, 'partner_id': counterpart_partner.id or None, - 'amount_currency': counterpart_currency and counterpart_currency.round((counterpart_vals['balance'] < 0 and -1 or 1) * abs(counterpart_vals['amount_currency'])) or 0, - 'currency_id': counterpart_currency.id or None, + 'amount_currency': counterpart_currency.round((counterpart_vals['balance'] < 0 and -1 or 1) * abs(counterpart_vals['amount_currency'])) or 0, + 'currency_id': counterpart_currency.id, }) # Generate change_account lines' vals for (partner, currency, account), lines in grouped_source_lines.items(): account_balance = sum(line.balance for line in lines) - if not (currency or self.company_id.currency_id).is_zero(account_balance): - account_amount_currency = currency and currency.round(sum(line.amount_currency for line in lines)) or 0 + if not self.company_id.currency_id.is_zero(account_balance): + account_amount_currency = currency.round(sum(line.amount_currency for line in lines)) line_vals.append({ 'name': _('Transfer to %s', self.destination_account_id.display_name or _('[Not set]')), 'debit': account_balance < 0 and self.company_id.currency_id.round(-account_balance) or 0, 'credit': account_balance > 0 and self.company_id.currency_id.round(account_balance) or 0, 'account_id': account.id, 'partner_id': partner.id or None, - 'currency_id': currency.id or None, + 'currency_id': currency.id, 'amount_currency': (account_balance > 0 and -1 or 1) * abs(account_amount_currency), }) @@ -188,10 +186,7 @@ class AutomaticEntryWizard(models.TransientModel): # account.move.line data reported_debit = aml.company_id.currency_id.round((self.percentage / 100) * aml.debit) reported_credit = aml.company_id.currency_id.round((self.percentage / 100) * aml.credit) - if aml.currency_id: - reported_amount_currency = aml.currency_id.round((self.percentage / 100) * aml.amount_currency) - else: - reported_amount_currency = 0.0 + reported_amount_currency = aml.currency_id.round((self.percentage / 100) * aml.amount_currency) move_data['new_date']['line_ids'] += [ (0, 0, { diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 025363ab5d5..114085d29a5 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -405,7 +405,6 @@ class HrExpense(models.Model): account_date = expense.sheet_id.accounting_date or expense.date or fields.Date.context_today(expense) company_currency = expense.company_id.currency_id - different_currency = expense.currency_id and expense.currency_id != company_currency move_line_values = [] taxes = expense.tax_ids.with_context(round=True).compute_all(expense.unit_amount, expense.currency_id, expense.quantity, expense.product_id) @@ -414,17 +413,14 @@ class HrExpense(models.Model): partner_id = expense.employee_id.sudo().address_home_id.commercial_partner_id.id # source move line - amount = taxes['total_excluded'] - amount_currency = False - if different_currency: - amount = expense.currency_id._convert(amount, company_currency, expense.company_id, account_date) - amount_currency = taxes['total_excluded'] + balance = expense.currency_id._convert(taxes['total_excluded'], company_currency, expense.company_id, account_date) + amount_currency = taxes['total_excluded'] move_line_src = { 'name': move_line_name, 'quantity': expense.quantity or 1, - 'debit': amount if amount > 0 else 0, - 'credit': -amount if amount < 0 else 0, - 'amount_currency': amount_currency if different_currency else 0.0, + 'debit': balance if balance > 0 else 0, + 'credit': -balance if balance < 0 else 0, + 'amount_currency': amount_currency, 'account_id': account_src.id, 'product_id': expense.product_id.id, 'product_uom_id': expense.product_uom_id.id, @@ -434,37 +430,34 @@ class HrExpense(models.Model): 'partner_id': partner_id, 'tax_ids': [(6, 0, expense.tax_ids.ids)], 'tax_tag_ids': [(6, 0, taxes['base_tags'])], - 'currency_id': expense.currency_id.id if different_currency else False, + 'currency_id': expense.currency_id.id, } move_line_values.append(move_line_src) - total_amount += -move_line_src['debit'] or move_line_src['credit'] - total_amount_currency += -move_line_src['amount_currency'] if move_line_src['currency_id'] else (-move_line_src['debit'] or move_line_src['credit']) + total_amount -= balance + total_amount_currency -= move_line_src['amount_currency'] # taxes move lines for tax in taxes['taxes']: - amount = tax['amount'] - amount_currency = False - if different_currency: - amount = expense.currency_id._convert(amount, company_currency, expense.company_id, account_date) - amount_currency = tax['amount'] + balance = expense.currency_id._convert(tax['amount'], company_currency, expense.company_id, account_date) + amount_currency = tax['amount'] move_line_tax_values = { 'name': tax['name'], 'quantity': 1, - 'debit': amount if amount > 0 else 0, - 'credit': -amount if amount < 0 else 0, - 'amount_currency': amount_currency if different_currency else 0.0, + 'debit': balance if balance > 0 else 0, + 'credit': -balance if balance < 0 else 0, + 'amount_currency': amount_currency, 'account_id': tax['account_id'] or move_line_src['account_id'], 'tax_repartition_line_id': tax['tax_repartition_line_id'], 'tax_tag_ids': tax['tag_ids'], 'tax_base_amount': tax['base'], 'expense_id': expense.id, 'partner_id': partner_id, - 'currency_id': expense.currency_id.id if different_currency else False, + 'currency_id': expense.currency_id.id, 'analytic_account_id': expense.analytic_account_id.id if tax['analytic'] else False, 'analytic_tag_ids': [(6, 0, expense.analytic_tag_ids.ids)] if tax['analytic'] else False, } - total_amount -= amount - total_amount_currency -= move_line_tax_values['amount_currency'] or amount + total_amount -= balance + total_amount_currency -= move_line_tax_values['amount_currency'] move_line_values.append(move_line_tax_values) # destination move line @@ -474,8 +467,8 @@ class HrExpense(models.Model): 'credit': total_amount < 0 and -total_amount, 'account_id': account_dst, 'date_maturity': account_date, - 'amount_currency': total_amount_currency if different_currency else 0.0, - 'currency_id': expense.currency_id.id if different_currency else False, + 'amount_currency': total_amount_currency, + 'currency_id': expense.currency_id.id, 'expense_id': expense.id, 'partner_id': partner_id, } diff --git a/addons/hr_expense/tests/test_expenses.py b/addons/hr_expense/tests/test_expenses.py index 3a0224a0907..f2d1fd86676 100644 --- a/addons/hr_expense/tests/test_expenses.py +++ b/addons/hr_expense/tests/test_expenses.py @@ -59,10 +59,10 @@ class TestExpenses(TestExpenseCommon): { 'debit': 0.0, 'credit': 1150.0, - 'amount_currency': 0.0, + 'amount_currency': -1150.0, 'account_id': self.company_data['default_account_payable'].id, 'product_id': False, - 'currency_id': False, + 'currency_id': self.company_data['currency'].id, 'tax_line_id': False, 'analytic_account_id': False, }, @@ -92,10 +92,10 @@ class TestExpenses(TestExpenseCommon): { 'debit': 150.0, 'credit': 0.0, - 'amount_currency': 0.0, + 'amount_currency': 150.0, 'account_id': self.company_data['default_account_tax_purchase'].id, 'product_id': False, - 'currency_id': False, + 'currency_id': self.company_data['currency'].id, 'tax_line_id': self.company_data['default_tax_purchase'].id, 'analytic_account_id': False, }, @@ -114,10 +114,10 @@ class TestExpenses(TestExpenseCommon): { 'debit': 1000.0, 'credit': 0.0, - 'amount_currency': 0.0, + 'amount_currency': 1000.0, 'account_id': self.company_data['default_account_expense'].id, 'product_id': self.product_a.id, - 'currency_id': False, + 'currency_id': self.company_data['currency'].id, 'tax_line_id': False, 'analytic_account_id': self.analytic_account_1.id, }, diff --git a/addons/point_of_sale/tests/test_pos_other_currency_config.py b/addons/point_of_sale/tests/test_pos_other_currency_config.py index aad273ad083..496a26ad5f4 100644 --- a/addons/point_of_sale/tests/test_pos_other_currency_config.py +++ b/addons/point_of_sale/tests/test_pos_other_currency_config.py @@ -222,8 +222,8 @@ class TestPoSOtherCurrencyConfig(TestPoSCommon): +---------------------+------------+-----------------+ | sale_account | -7153.90 | -3576.95 | | pos_receivable-cash | 7153.90 | 3576.95 | - | expense_account | 2375.99 | 0.00 | - | output_account | -2375.99 | 0.00 | + | expense_account | 2375.99 | 2375.99 | + | output_account | -2375.99 | -2375.99 | +---------------------+------------+-----------------+ | Total balance | 0.00 | 0.00 | +---------------------+------------+-----------------+ @@ -258,19 +258,11 @@ class TestPoSOtherCurrencyConfig(TestPoSCommon): expense_line = session_account_move.line_ids.filtered(lambda line: line.account_id == self.expense_account) self.assertAlmostEqual(expense_line.balance, 2375.99) - self.assertFalse(expense_line.currency_id, msg='Should be no currency in the stock expense line.') - self.assertAlmostEqual( - expense_line.amount_currency, 0.00, - msg="Should be zero because the balance is calculated from amounts in company's currency.", - ) + self.assertAlmostEqual(expense_line.amount_currency, 2375.99) output_line = session_account_move.line_ids.filtered(lambda line: line.account_id == self.output_account) self.assertAlmostEqual(output_line.balance, -2375.99) - self.assertFalse(output_line.currency_id, msg='Should be no currency in the stock output line.') - self.assertAlmostEqual( - output_line.amount_currency, 0.00, - msg="Should be zero because the balance is calculated from amounts in company's currency.", - ) + self.assertAlmostEqual(output_line.amount_currency, -2375.99) self.assertTrue(receivable_line_cash.full_reconcile_id, msg='Cash receivable line should be fully-reconciled.') self.assertTrue(output_line.full_reconcile_id, msg='The stock output account line should be fully-reconciled.')