From 054906a94a0182e4d097b2c3e5458cb7a8fccd1f Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Tue, 28 Feb 2017 12:47:25 +0100 Subject: [PATCH] [IMP] account, usability: improved account.move form view * proposal of the next line debit/credit * name of account.move.line isn't required anymore, but reference of account.move is --- addons/account/models/account_move.py | 19 ++++++++++++++++++- addons/account/views/account_view.xml | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 1252aa647bf..df8eeb63348 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -369,7 +369,7 @@ class AccountMoveLine(models.Model): counterpart = list(counterpart)[0:2] + ["..."] self.counterpart = ",".join(counterpart) - name = fields.Char(required=True, string="Label") + name = fields.Char(string="Label") quantity = fields.Float(digits=(16, 2), help="The optional quantity expressed by this line, eg: number of product sold. The quantity is not a legal requirement but is very useful for some reports.") product_uom_id = fields.Many2one('product.uom', string='Unit of Measure') @@ -434,6 +434,23 @@ class AccountMoveLine(models.Model): ('credit_debit2', 'CHECK (credit+debit>=0)', 'Wrong credit or debit value in accounting entry !'), ] + @api.model + def default_get(self, fields): + rec = super(AccountMoveLine, self).default_get(fields) + if 'line_ids' not in self._context: + return rec + + #compute the default credit/debit of the next line in case of a manual entry + balance = 0 + for line in self._context['line_ids']: + if line[2]: + balance += line[2]['debit'] - line[2]['credit'] + if balance < 0: + rec.update({'debit': -balance}) + if balance > 0: + rec.update({'credit': balance}) + return rec + @api.multi @api.constrains('currency_id', 'account_id') def _check_currency(self): diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml index 3d2c6697b5f..5a3b4f58a1c 100644 --- a/addons/account/views/account_view.xml +++ b/addons/account/views/account_view.xml @@ -1299,7 +1299,7 @@ - +