[FIX] account: update balance when changing amount in currency
Before it wasn't done for simplicity, but turns out it is actually quite simple to do. task-3167055 closes odoo/odoo#112043 X-original-commit: 21cb20a284a98a59bf5885ad56d231ae337105e1 Signed-off-by: Quentin De Paoli <qdp@odoo.com> Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -1507,6 +1507,11 @@ class AccountMove(models.Model):
|
||||
# ONCHANGE METHODS
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
@api.onchange('date')
|
||||
def _onchange_date(self):
|
||||
if not self.is_invoice(True):
|
||||
self.line_ids._inverse_amount_currency()
|
||||
|
||||
@api.onchange('invoice_vendor_bill_id')
|
||||
def _onchange_invoice_vendor_bill(self):
|
||||
if self.invoice_vendor_bill_id:
|
||||
|
||||
@@ -1110,6 +1110,12 @@ class AccountMoveLine(models.Model):
|
||||
for line in self:
|
||||
if line.currency_id == line.company_id.currency_id and line.balance != line.amount_currency:
|
||||
line.balance = line.amount_currency
|
||||
elif (
|
||||
line.currency_id != line.company_id.currency_id
|
||||
and not line.move_id.is_invoice(True)
|
||||
and not self.env.is_protected(self._fields['balance'], line)
|
||||
):
|
||||
line.balance = line.company_id.currency_id.round(line.amount_currency / line.currency_rate)
|
||||
|
||||
@api.onchange('debit')
|
||||
def _inverse_debit(self):
|
||||
|
||||
@@ -441,20 +441,41 @@ class TestAccountMove(AccountTestInvoicingCommon):
|
||||
[
|
||||
{
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'amount_currency': 1200.0,
|
||||
'amount_currency': -1200.0,
|
||||
'debit': 0.0,
|
||||
'credit': 0.0,
|
||||
'credit': 400.0,
|
||||
},
|
||||
{
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'amount_currency': -1200.0,
|
||||
'debit': 0.0,
|
||||
'amount_currency': 1200.0,
|
||||
'debit': 400.0,
|
||||
'credit': 0.0,
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
# Balance and amount currency are totally independant in journal entries if the line has a foreign currency
|
||||
# Change the date to change the currency conversion's rate
|
||||
with Form(move) as move_form:
|
||||
move_form.date = fields.Date.from_string('2017-01-01')
|
||||
|
||||
self.assertRecordValues(
|
||||
move.line_ids.sorted('debit'),
|
||||
[
|
||||
{
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'amount_currency': -1200.0,
|
||||
'debit': 0.0,
|
||||
'credit': 600.0,
|
||||
},
|
||||
{
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'amount_currency': 1200.0,
|
||||
'debit': 600.0,
|
||||
'credit': 0.0,
|
||||
},
|
||||
],
|
||||
)
|
||||
# You can change the balance manually without changing the currency amount
|
||||
with Form(move) as move_form:
|
||||
with move_form.line_ids.edit(0) as line_form:
|
||||
line_form.debit = 200
|
||||
|
||||
Reference in New Issue
Block a user