Use origin description as fallback description for account move and line
Closes #12571
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Use origin description as fallback description
|
||||
* Post write-off and exchange moves when reconcile posted lines
|
||||
* Post cancelled, grouped, rescheduled and delegated moves
|
||||
* Rename close state to closed
|
||||
|
||||
@@ -31,6 +31,7 @@ from .common import ActivePeriodMixin, ContextCompanyMixin, PeriodMixin
|
||||
from .exceptions import (
|
||||
AccountValidationError, ChartWarning, FiscalYearNotFoundError,
|
||||
SecondCurrencyError)
|
||||
from .move import DescriptionOriginMixin
|
||||
|
||||
|
||||
def TypeMixin(template=False):
|
||||
@@ -2322,7 +2323,7 @@ class OpenGeneralLedgerAccountParty(Wizard):
|
||||
return action, {}
|
||||
|
||||
|
||||
class GeneralLedgerLine(ModelSQL, ModelView):
|
||||
class GeneralLedgerLine(DescriptionOriginMixin, ModelSQL, ModelView):
|
||||
'General Ledger Line'
|
||||
__name__ = 'account.general_ledger.line'
|
||||
|
||||
@@ -2354,7 +2355,10 @@ class GeneralLedgerLine(ModelSQL, ModelView):
|
||||
'get_balance')
|
||||
origin = fields.Reference('Origin', selection='get_origin')
|
||||
description = fields.Char('Description')
|
||||
move_description = fields.Char('Move Description')
|
||||
move_description_used = fields.Function(
|
||||
fields.Char("Move Description"),
|
||||
'get_move_field',
|
||||
searcher='search_move_field')
|
||||
amount_second_currency = Monetary(
|
||||
"Amount Second Currency",
|
||||
currency='second_currency', digits='second_currency')
|
||||
@@ -2375,6 +2379,7 @@ class GeneralLedgerLine(ModelSQL, ModelView):
|
||||
super(GeneralLedgerLine, cls).__setup__()
|
||||
cls.__access__.add('account')
|
||||
cls._order.insert(0, ('date', 'ASC'))
|
||||
cls.description_used.setter = None
|
||||
|
||||
@classmethod
|
||||
def table_query(cls):
|
||||
@@ -2425,6 +2430,24 @@ class GeneralLedgerLine(ModelSQL, ModelView):
|
||||
).join(account, condition=line.account == account.id
|
||||
).select(*columns, where=line_query)
|
||||
|
||||
def get_move_field(self, name):
|
||||
field = getattr(self.__class__, name)
|
||||
if name.startswith('move_'):
|
||||
name = name[5:]
|
||||
value = getattr(self.move, name)
|
||||
if isinstance(value, ModelSQL):
|
||||
if field._type == 'reference':
|
||||
return str(value)
|
||||
return value.id
|
||||
return value
|
||||
|
||||
@classmethod
|
||||
def search_move_field(cls, name, clause):
|
||||
nested = clause[0][len(name):]
|
||||
if name.startswith('move_'):
|
||||
name = name[5:]
|
||||
return [('move.' + name + nested, *clause[1:])]
|
||||
|
||||
def get_currency(self, name):
|
||||
return self.company.currency.id
|
||||
|
||||
|
||||
@@ -910,7 +910,7 @@
|
||||
<text:p text:style-name="P32"><text:placeholder text:placeholder-type="text"><format_currency(line.balance, user.language, company.currency)></text:placeholder></text:p>
|
||||
</table:table-cell>
|
||||
<table:table-cell table:style-name="Lines.F6" office:value-type="string">
|
||||
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text"><line.description or ''></text:placeholder><text:line-break/><text:placeholder text:placeholder-type="text"><line.move_description or ''></text:placeholder></text:p>
|
||||
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text"><line.description or ''></text:placeholder><text:line-break/><text:placeholder text:placeholder-type="text"><line.move_description_used or ''></text:placeholder></text:p>
|
||||
</table:table-cell>
|
||||
<table:table-cell table:style-name="Lines.G6" office:value-type="string">
|
||||
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text"><getattr(line.origin, 'rec_name', '')></text:placeholder></text:p>
|
||||
@@ -976,4 +976,4 @@
|
||||
<text:p text:style-name="P8"><text:placeholder text:placeholder-type="text"></for></text:placeholder></text:p>
|
||||
</office:text>
|
||||
</office:body>
|
||||
</office:document>
|
||||
</office:document>
|
||||
|
||||
+48
-6
@@ -21,7 +21,7 @@ from trytond.pool import Pool
|
||||
from trytond.pyson import Bool, Eval, If, PYSONEncoder
|
||||
from trytond.report import Report
|
||||
from trytond.rpc import RPC
|
||||
from trytond.tools import grouped_slice, reduce_ids
|
||||
from trytond.tools import firstline, grouped_slice, reduce_ids
|
||||
from trytond.transaction import Transaction, check_access
|
||||
from trytond.wizard import (
|
||||
Button, StateAction, StateTransition, StateView, Wizard)
|
||||
@@ -39,7 +39,48 @@ _LINE_STATES = {
|
||||
}
|
||||
|
||||
|
||||
class Move(ModelSQL, ModelView):
|
||||
class DescriptionOriginMixin:
|
||||
__slots__ = ()
|
||||
|
||||
description_used = fields.Function(
|
||||
fields.Char("Description", states=_MOVE_STATES),
|
||||
'on_change_with_description_used',
|
||||
setter='set_description_used',
|
||||
searcher='search_description_used')
|
||||
|
||||
@fields.depends('description', 'origin')
|
||||
def on_change_with_description_used(self, name=None):
|
||||
description = self.description
|
||||
if not description and hasattr(self.origin, 'description'):
|
||||
description = firstline(self.origin.description or '')
|
||||
return description
|
||||
|
||||
@classmethod
|
||||
def set_description_used(cls, moves, name, value):
|
||||
moves = [m for m in moves if m.description_used != value]
|
||||
if moves:
|
||||
cls.write(moves, {'description': value})
|
||||
|
||||
@classmethod
|
||||
def search_description_used(cls, name, clause):
|
||||
pool = Pool()
|
||||
domain = ['OR', [
|
||||
('description', '!=', None),
|
||||
('description', '!=', ''),
|
||||
('description', *clause[1:]),
|
||||
],
|
||||
]
|
||||
for origin, _ in cls.get_origin():
|
||||
if not origin:
|
||||
continue
|
||||
Model = pool.get(origin)
|
||||
if 'description' in Model._fields:
|
||||
domain.append(
|
||||
('origin.description', *clause[1:3], origin, *clause[3:]))
|
||||
return domain
|
||||
|
||||
|
||||
class Move(DescriptionOriginMixin, ModelSQL, ModelView):
|
||||
'Account Move'
|
||||
__name__ = 'account.move'
|
||||
_rec_name = 'number'
|
||||
@@ -800,7 +841,7 @@ class MoveLineMixin:
|
||||
return [('account.rec_name',) + tuple(clause[1:])]
|
||||
|
||||
|
||||
class Line(MoveLineMixin, ModelSQL, ModelView):
|
||||
class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
|
||||
'Account Move Line'
|
||||
__name__ = 'account.move.line'
|
||||
|
||||
@@ -870,9 +911,10 @@ class Line(MoveLineMixin, ModelSQL, ModelView):
|
||||
fields.Reference("Move Origin", selection='get_move_origin'),
|
||||
'get_move_field', searcher='search_move_field')
|
||||
description = fields.Char('Description', states=_states)
|
||||
move_description = fields.Function(fields.Char('Move Description',
|
||||
states=_states),
|
||||
'get_move_field', setter='set_move_field',
|
||||
move_description_used = fields.Function(
|
||||
fields.Char("Move Description", states=_states),
|
||||
'get_move_field',
|
||||
setter='set_move_field',
|
||||
searcher='search_move_field')
|
||||
amount_second_currency = Monetary(
|
||||
"Amount Second Currency",
|
||||
|
||||
@@ -138,7 +138,7 @@ Group lines::
|
||||
Decimal('50')
|
||||
>>> delegate_to.maturity_date == period.start_date + dt.timedelta(days=2)
|
||||
True
|
||||
>>> delegate_to.move_description
|
||||
>>> delegate_to.move_description_used
|
||||
'Group lines'
|
||||
|
||||
Cancelling the delegation move::
|
||||
|
||||
@@ -6,8 +6,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="account" expand="1"/>
|
||||
<field name="party" expand="1" optional="0"/>
|
||||
<field name="move" optional="0"/>
|
||||
<field name="description" expand="1" optional="1"/>
|
||||
<field name="move_description" expand="1" optional="1"/>
|
||||
<field name="move_description_used" expand="1" optional="1"/>
|
||||
<field name="description_used" expand="1" optional="1"/>
|
||||
<field name="origin" optional="1"/>
|
||||
<field name="reconciliation" optional="1"/>
|
||||
<field name="state" optional="1"/>
|
||||
|
||||
@@ -19,8 +19,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="post_date"/>
|
||||
<label name="origin"/>
|
||||
<field name="origin" colspan="3"/>
|
||||
<label name="description"/>
|
||||
<field name="description" colspan="3"/>
|
||||
<label name="description_used"/>
|
||||
<field name="description_used" colspan="3"/>
|
||||
<notebook>
|
||||
<page name="lines">
|
||||
<field name="lines" colspan="4"
|
||||
|
||||
@@ -24,8 +24,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="move_origin"/>
|
||||
<label name="origin"/>
|
||||
<field name="origin"/>
|
||||
<label name="description"/>
|
||||
<field name="description" colspan="3"/>
|
||||
<label name="description_used"/>
|
||||
<field name="description_used" colspan="3"/>
|
||||
<notebook colspan="4">
|
||||
<page string="Other Info" id="info">
|
||||
<label name="date"/>
|
||||
|
||||
@@ -10,7 +10,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="move" optional="1"/>
|
||||
<field name="move_origin" optional="1"/>
|
||||
<field name="origin" optional="1"/>
|
||||
<field name="move_description" optional="1"/>
|
||||
<field name="description" optional="1"/>
|
||||
<field name="move_description_used" optional="1"/>
|
||||
<field name="description_used" optional="1"/>
|
||||
<field name="reconciliation" optional="1"/>
|
||||
</tree>
|
||||
|
||||
@@ -5,8 +5,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="move" optional="0"/>
|
||||
<field name="move_origin" optional="0"/>
|
||||
<field name="origin" optional="1"/>
|
||||
<field name="move_description" optional="1"/>
|
||||
<field name="description" optional="1"/>
|
||||
<field name="move_description_used" optional="1"/>
|
||||
<field name="description_used" optional="1"/>
|
||||
<field name="maturity_date"/>
|
||||
<field name="amount"/>
|
||||
</tree>
|
||||
|
||||
@@ -15,8 +15,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="second_currency" optional="1"/>
|
||||
<field name="delegated_amount" optional="0"/>
|
||||
<field name="tax_lines" optional="1"/>
|
||||
<field name="description" expand="1" optional="1"/>
|
||||
<field name="move_description" expand="1" optional="1"/>
|
||||
<field name="move_description_used" expand="1" optional="1"/>
|
||||
<field name="description_used" expand="1" optional="1"/>
|
||||
<field name="reconciliation" optional="1"/>
|
||||
<field name="state"/>
|
||||
<field name="move_state" optional="0"/>
|
||||
|
||||
@@ -10,6 +10,6 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="amount_second_currency" symbol="" optional="1"/>
|
||||
<field name="second_currency" optional="1"/>
|
||||
<field name="tax_lines" optional="1"/>
|
||||
<field name="description" expand="1" optional="1"/>
|
||||
<field name="description_used" expand="1" optional="1"/>
|
||||
<field name="reconciliation" optional="1"/>
|
||||
</tree>
|
||||
|
||||
@@ -10,7 +10,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="date"/>
|
||||
<field name="post_date" optional="1"/>
|
||||
<field name="origin" optional="0"/>
|
||||
<field name="description" expand="1" optional="1"/>
|
||||
<field name="description_used" expand="1" optional="1"/>
|
||||
<field name="state"/>
|
||||
<button name="post"/>
|
||||
</tree>
|
||||
|
||||
@@ -8,7 +8,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="amount_currency"/>
|
||||
<field name="move"/>
|
||||
<field name="origin"/>
|
||||
<field name="description"/>
|
||||
<field name="move_description"/>
|
||||
<field name="move_description_used"/>
|
||||
<field name="description_used"/>
|
||||
<field name="reconciliation" tree_invisible="1"/>
|
||||
</tree>
|
||||
|
||||
@@ -8,7 +8,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="move" optional="1"/>
|
||||
<field name="move_origin" optional="1"/>
|
||||
<field name="origin" optional="1"/>
|
||||
<field name="move_description" optional="1"/>
|
||||
<field name="description" optional="1"/>
|
||||
<field name="move_description_used" optional="1"/>
|
||||
<field name="description_used" optional="1"/>
|
||||
<field name="reconciliation" optional="1"/>
|
||||
</tree>
|
||||
|
||||
@@ -110,8 +110,8 @@ class MoveLineGroup(MoveLineMixin, ModelSQL, ModelView):
|
||||
move_origin = fields.Function(fields.Reference(
|
||||
"Move Origin", selection='get_move_origin'),
|
||||
'get_move_field', searcher='search_move_field')
|
||||
move_description = fields.Function(fields.Char(
|
||||
"Move Description"),
|
||||
move_description_used = fields.Function(
|
||||
fields.Char("Move Description"),
|
||||
'get_move_field', searcher='search_move_field')
|
||||
move_state = fields.Function(fields.Selection(
|
||||
'get_move_states', "Move State"),
|
||||
|
||||
@@ -17,8 +17,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<label name="move_origin"/>
|
||||
<field name="move_origin"/>
|
||||
|
||||
<label name="move_description"/>
|
||||
<field name="move_description" colspan="3"/>
|
||||
<label name="move_description_used"/>
|
||||
<field name="move_description_used" colspan="3"/>
|
||||
|
||||
<field name="lines" colspan="4" view_ids="account.move_line_view_list_payable_receivable"/>
|
||||
</form>
|
||||
|
||||
@@ -9,7 +9,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="party" expand="1"/>
|
||||
<field name="debit" sum="1"/>
|
||||
<field name="credit" sum="1"/>
|
||||
<field name="move_description" expand="1" optional="1"/>
|
||||
<field name="move_description_used" expand="1" optional="1"/>
|
||||
<field name="reconciled" optional="1"/>
|
||||
<field name="state"/>
|
||||
<field name="move_state" optional="0"/>
|
||||
|
||||
+1
-1
@@ -9,6 +9,6 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="payable_receivable_balance" string="Balance"/>
|
||||
<field name="move" optional="1"/>
|
||||
<field name="move_origin" optional="1"/>
|
||||
<field name="move_description" optional="1"/>
|
||||
<field name="move_description_used" optional="1"/>
|
||||
<field name="reconciled" optional="1"/>
|
||||
</tree>
|
||||
|
||||
@@ -6,8 +6,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="move"/>
|
||||
<field name="move_origin" expand="1" optional="1"/>
|
||||
<field name="origin" expand="1" optional="1"/>
|
||||
<field name="description" expand="1" optional="1"/>
|
||||
<field name="move_description" expand="1" optional="1"/>
|
||||
<field name="move_description_used" expand="1" optional="1"/>
|
||||
<field name="description_used" expand="1" optional="1"/>
|
||||
<field name="date"/>
|
||||
<field name="account" expand="1"/>
|
||||
<field name="party" expand="1"/>
|
||||
|
||||
Reference in New Issue
Block a user