Assign a party in write off move lines without it

This commit is contained in:
jmartin 2014-07-15 15:50:26 +02:00
parent b0edd121c2
commit 8326f68e0b
2 changed files with 37 additions and 0 deletions

View File

@ -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')

35
move.py Normal file
View File

@ -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)