Improve usability of account.move creation/edition

Default value for account_id, debit, credit, similar to v8 behavior
This commit is contained in:
Alexis de Lattre
2018-11-19 19:21:23 +01:00
parent 7d359d6730
commit c196343ec0
3 changed files with 30 additions and 1 deletions

View File

@@ -31,6 +31,7 @@ This module has been written by Alexis de Lattre from Akretion <alexis.delattre@
'website': 'http://www.akretion.com', 'website': 'http://www.akretion.com',
'depends': [ 'depends': [
'account', 'account',
'base_view_inheritance_extension',
'base_usability', # needed only to access base_usability.group_nobody 'base_usability', # needed only to access base_usability.group_nobody
# in v12, I may create a module only for group_nobody # in v12, I may create a module only for group_nobody
], ],

View File

@@ -282,6 +282,28 @@ class AccountMove(models.Model):
# which seems a bit lazy for me... # which seems a bit lazy for me...
ref = fields.Char(states={'posted': [('readonly', True)]}) ref = fields.Char(states={'posted': [('readonly', True)]})
date = fields.Date(copy=False) date = fields.Date(copy=False)
default_account_id = fields.Many2one(
related='journal_id.default_debit_account_id', readonly=True)
default_credit = fields.Float(
compute='_compute_default_credit_debit', readonly=True)
default_debit = fields.Float(
compute='_compute_default_credit_debit', readonly=True)
@api.depends('line_ids.credit', 'line_ids.debit')
def _compute_default_credit_debit(self):
for move in self:
total_debit = total_credit = default_debit = default_credit = 0.0
for l in move.line_ids:
total_debit += l.debit
total_credit += l.credit
# I could use float_compare, but I don't think it's really needed
# in this context
if total_debit > total_credit:
default_credit = total_debit - total_credit
else:
default_debit = total_credit - total_debit
move.default_credit = default_credit
move.default_debit = default_debit
class AccountMoveLine(models.Model): class AccountMoveLine(models.Model):

View File

@@ -288,9 +288,15 @@ module -->
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="ref" position="after"> <field name="ref" position="after">
<field name="default_move_line_name"/> <field name="default_move_line_name"/>
<field name="default_account_id" invisible="1"/>
<field name="default_credit" invisible="0"/>
<field name="default_debit" invisible="0"/>
</field> </field>
<xpath expr="//field[@name='line_ids']" position="attributes"> <xpath expr="//field[@name='line_ids']" position="attributes">
<attribute name="context">{'line_ids': line_ids, 'journal_id': journal_id, 'default_name': default_move_line_name}</attribute> <attribute name="context" operation="python_dict" key="default_name">default_move_line_name</attribute>
<attribute name="context" operation="python_dict" key="default_account_id">default_account_id</attribute>
<attribute name="context" operation="python_dict" key="default_credit">default_credit</attribute>
<attribute name="context" operation="python_dict" key="default_debit">default_debit</attribute>
</xpath> </xpath>
<xpath expr="//field[@name='line_ids']/tree/field[@name='date_maturity']" position="after"> <xpath expr="//field[@name='line_ids']/tree/field[@name='date_maturity']" position="after">
<field name="full_reconcile_id"/> <field name="full_reconcile_id"/>