summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorForam Katharotiya <fka@openerp.com>2017-08-28 11:47:11 +0530
committerLaurent Smet <las@openerp.com>2017-08-28 08:17:11 +0200
commitfa3ff5b41a179706bf99e81c9698f2600a98ece2 (patch)
tree77ff9fc82e1cd88d53efa9f8e2836860d27fdf41
parente0ef188147c7634b52064cd076c8a1170cbb561f (diff)
[IMP] account: compute debit/credit based on amount currency in account.move
Recompute automatically the debit/credit fields on account.move.line depending of amount_currency, date or currency_id in order to deal more easily with multi-currency. task: https://www.odoo.com/web#id=33084&view_type=form&model=project.task&action=333&active_id=131&menu_id=4720 PR: #16826
-rw-r--r--addons/account/models/account_move.py22
-rw-r--r--addons/account/views/account_view.xml1
2 files changed, 23 insertions, 0 deletions
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index 6be3e8a75fb..184bad0184c 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -78,6 +78,14 @@ class AccountMove(models.Model):
partner = move.line_ids.mapped('partner_id')
move.partner_id = partner.id if len(partner) == 1 else False
+ @api.onchange('date')
+ def _onchange_date(self):
+ '''On the form view, a change on the date will trigger onchange() on account.move
+ but not on account.move.line even the date field is related to account.move.
+ Then, trigger the _onchange_amount_currency manually.
+ '''
+ self.line_ids._onchange_amount_currency()
+
name = fields.Char(string='Number', required=True, copy=False, default='/')
ref = fields.Char(string='Reference', copy=False)
date = fields.Date(required=True, states={'posted': [('readonly', True)]}, index=True, default=fields.Date.context_today)
@@ -493,6 +501,20 @@ class AccountMoveLine(models.Model):
if (line.amount_currency > 0.0 and line.credit > 0.0) or (line.amount_currency < 0.0 and line.debit > 0.0):
raise ValidationError(_('The amount expressed in the secondary currency must be positive when account is debited and negative when account is credited.'))
+ @api.onchange('amount_currency', 'currency_id')
+ def _onchange_amount_currency(self):
+ '''Recompute the debit/credit based on amount_currency/currency_id and date.
+ However, date is a related field on account.move. Then, this onchange will not be triggered
+ by the form view by changing the date on the account.move.
+ To fix this problem, see _onchange_date method on account.move.
+ '''
+ for line in self:
+ amount = line.amount_currency
+ if line.currency_id and line.currency_id != line.company_currency_id:
+ amount = self.currency_id.with_context(date=line.date).compute(amount, line.company_currency_id)
+ line.debit = amount > 0 and amount or 0.0
+ line.credit = amount < 0 and amount or 0.0
+
####################################################
# Reconciliation interface methods
####################################################
diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml
index 20da92ee8fb..e8689e54846 100644
--- a/addons/account/views/account_view.xml
+++ b/addons/account/views/account_view.xml
@@ -1397,6 +1397,7 @@
<field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
<field name="amount_currency" groups="base.group_multi_currency"/>
<field name="company_currency_id" invisible="1"/>
+ <field name="company_id" invisible="1"/>
<field name="currency_id" options="{'no_create': True}" groups="base.group_multi_currency"/>
<field name="debit" sum="Total Debit"/>
<field name="credit" sum="Total Credit"/>