[IMP] account: improve journal entries recording

Task 1943019
onchange should ensure that you don't have both a credit and a debit <>0
prefill account/partner if the user is recording several lines a row with the same account/partner
the journal should be set by default

closes odoo/odoo#31593

Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
This commit is contained in:
wan
2019-03-06 15:58:01 +00:00
parent 0bae5e2402
commit becb4dc636
+25
View File
@@ -22,6 +22,13 @@ class AccountMove(models.Model):
_order = 'date desc, id desc'
_inherit = ['mail.thread', 'mail.activity.mixin']
@api.model
def default_get(self, fields):
rec = super(AccountMove, self).default_get(fields)
if not rec.get('journal_id'):
rec.update({'journal_id': self.env['account.journal'].search([('type', '=', 'general'), ('company_id', '=', self.env.user.company_id.id)], limit=1).id})
return rec
@api.multi
@api.depends('name', 'state')
def name_get(self):
@@ -497,6 +504,18 @@ class AccountMoveLine(models.Model):
for line in self:
line.recompute_tax_line = True
@api.onchange('debit')
def _onchange_debit(self):
self.ensure_one()
if self.debit != 0:
self.credit = 0
@api.onchange('credit')
def _onchange_credit(self):
self.ensure_one()
if self.credit != 0:
self.debit = 0
@api.model_cr
def init(self):
""" change index on partner_id to a multi-column index on (partner_id, ref), the new index will behave in the
@@ -682,6 +701,12 @@ class AccountMoveLine(models.Model):
for line in self.move_id.resolve_2many_commands(
'line_ids', self._context['line_ids'], fields=['credit', 'debit']):
balance += line.get('debit', 0) - line.get('credit', 0)
if len(self._context['line_ids']) > 1:
lines = self.move_id.resolve_2many_commands('line_ids', self._context['line_ids'][-2:], fields=['partner_id', 'account_id'])
if lines[0].get('partner_id', False) == lines[1].get('partner_id', False):
rec.update({'partner_id': lines[0].get('partner_id', False)})
if lines[0].get('account_id', False) == lines[1].get('account_id', False):
rec.update({'account_id': lines[0].get('account_id', False)})
if balance < 0:
rec.update({'debit': -balance})
if balance > 0: