diff --git a/__init__.py b/__init__.py index 3264442..e28e3ac 100644 --- a/__init__.py +++ b/__init__.py @@ -3,6 +3,7 @@ #the full copyright notices and license terms. from trytond.pool import Pool from .account import * +from .move import * def register(): @@ -10,4 +11,5 @@ def register(): AccountTemplate, Account, Line, + Move, module='account_move_party_required', type_='model') diff --git a/move.py b/move.py new file mode 100644 index 0000000..090a715 --- /dev/null +++ b/move.py @@ -0,0 +1,35 @@ +#This file is part of Tryton. The COPYRIGHT file at the top level of +#this repository contains the full copyright notices and license terms. +from trytond.pool import Pool, PoolMeta +from trytond.transaction import Transaction + + +__all__ = ['Move'] +__metaclass__ = PoolMeta + + +class Move: + __name__ = 'account.move' + + @classmethod + def create(cls, vlist): + pool = Pool() + Account = pool.get('account.account') + MoveLine = pool.get('account.move.line') + context = Transaction().context + if context['active_model'] == 'account.move.line': + party = None + for active_id in context['active_ids']: + move_line = MoveLine(active_id) + if getattr(move_line, 'party'): + party = move_line.party + break + if party: + for value in vlist: + for line in value['lines']: + for line_values in line[1]: + account = Account(line_values['account']) + if (account.party_required + and 'party' not in line_values): + line_values['party'] = party + return super(Move, cls).create(vlist)