diff --git a/account.py b/account.py
index 14fc676c38..a424592997 100644
--- a/account.py
+++ b/account.py
@@ -372,6 +372,11 @@ class AccountTemplate(ModelSQL, ModelView):
deferral = fields.Boolean('Deferral', states={
'invisible': Eval('kind') == 'view',
}, depends=['kind'])
+ party_required = fields.Boolean('Party Required',
+ states={
+ 'invisible': Eval('kind') == 'view',
+ },
+ depends=['kind'])
@classmethod
def __setup__(cls):
@@ -424,6 +429,8 @@ class AccountTemplate(ModelSQL, ModelView):
res['reconcile'] = self.reconcile
if not account or account.deferral != self.deferral:
res['deferral'] = self.deferral
+ if not account or account.party_required != self.party_required:
+ res['party_required'] = self.party_required
if not account or account.template != self:
res['template'] = self.id
return res
@@ -582,6 +589,11 @@ class Account(ModelSQL, ModelView):
'Deferrals', readonly=True, states={
'invisible': Eval('kind') == 'view',
}, depends=['kind'])
+ party_required = fields.Boolean('Party Required',
+ states={
+ 'invisible': Eval('kind') == 'view',
+ },
+ depends=['kind'])
template = fields.Many2One('account.account.template', 'Template')
@classmethod
diff --git a/account.xml b/account.xml
index c62416d871..1ae79eea1a 100644
--- a/account.xml
+++ b/account.xml
@@ -326,6 +326,7 @@ this repository contains the full copyright notices and license terms. -->
+
receivable
@@ -334,6 +335,7 @@ this repository contains the full copyright notices and license terms. -->
+
payable
diff --git a/move.py b/move.py
index 904d46a155..a2cc7f98aa 100644
--- a/move.py
+++ b/move.py
@@ -592,7 +592,14 @@ class Line(ModelSQL, ModelView):
'required': Bool(Eval('amount_second_currency')),
},
depends=['amount_second_currency'])
- party = fields.Many2One('party.party', 'Party', select=True)
+ party = fields.Many2One('party.party', 'Party', select=True,
+ states={
+ 'required': Eval('party_required', False),
+ 'invisible': ~Eval('party_required', False),
+ },
+ depends=['party_required'])
+ party_required= fields.Function(fields.Boolean('Party Required'),
+ 'on_change_with_party_required')
maturity_date = fields.Date('Maturity Date',
help='This field is used for payable and receivable lines. \n'
'You can put the limit date for the payment.')
@@ -643,6 +650,8 @@ class Line(ModelSQL, ModelView):
'move_inactive_account': ('You can not create a move line '
'with account "%s" because it is inactive.'),
'already_reconciled': 'Line "%s" (%d) already reconciled.',
+ 'party_required': 'Party is required on line "%s"',
+ 'party_set': 'Party must not be set on line "%s"',
})
@classmethod
@@ -950,6 +959,12 @@ class Line(ModelSQL, ModelView):
self.account.second_currency.digits
return changes
+ @fields.depends('account')
+ def on_change_with_party_required(self, name=None):
+ if self.account:
+ return self.account.party_required
+ return False
+
def _compute_tax_lines(self, journal_type):
res = {}
pool = Pool()
@@ -1265,6 +1280,9 @@ class Line(ModelSQL, ModelView):
if not self.account.active:
self.raise_user_error('move_inactive_account', (
self.account.rec_name,))
+ if bool(self.party) != self.account.party_required:
+ error = 'party_set' if self.party else 'party_required'
+ self.raise_user_error(error, self.rec_name)
@classmethod
def check_journal_period_modify(cls, period, journal):
@@ -1454,11 +1472,14 @@ class Line(ModelSQL, ModelView):
lines = lines[:]
reconcile_account = None
+ reconcile_party = None
amount = Decimal('0.0')
for line in lines:
amount += line.debit - line.credit
if not reconcile_account:
reconcile_account = line.account
+ if not reconcile_party:
+ reconcile_party = line.party
amount = reconcile_account.currency.round(amount)
if not account and journal:
if amount >= 0:
@@ -1477,12 +1498,18 @@ class Line(ModelSQL, ModelView):
'lines': [
('create', [{
'account': reconcile_account.id,
+ 'party': (reconcile_party.id
+ if reconcile_party else None),
'debit': (amount < Decimal('0.0')
and - amount or Decimal('0.0')),
'credit': (amount > Decimal('0.0')
and amount or Decimal('0.0')),
}, {
'account': account.id,
+ 'party': (reconcile_party.id
+ if (account.party_required and
+ reconcile_party)
+ else None),
'debit': (amount > Decimal('0.0')
and amount or Decimal('0.0')),
'credit': (amount < Decimal('0.0')
diff --git a/tests/scenario_account_reconciliation.rst b/tests/scenario_account_reconciliation.rst
index 0e5832a5ae..8e4e3d7f26 100644
--- a/tests/scenario_account_reconciliation.rst
+++ b/tests/scenario_account_reconciliation.rst
@@ -147,7 +147,6 @@ Create Moves for direct reconciliation::
>>> line = move.lines.new()
>>> line.account = cash
>>> line.debit = Decimal(42)
- >>> line.party = customer
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.credit = Decimal(42)
@@ -190,7 +189,6 @@ Create Moves for writeoff reconciliation::
>>> line = move.lines.new()
>>> line.account = cash
>>> line.debit = Decimal(65)
- >>> line.party = customer
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.credit = Decimal(65)
diff --git a/tests/test_account.py b/tests/test_account.py
index e86ec63ab1..1c5d54e616 100644
--- a/tests/test_account.py
+++ b/tests/test_account.py
@@ -34,6 +34,7 @@ class AccountTestCase(unittest.TestCase):
self.balance_non_deferral = POOL.get(
'account.fiscalyear.balance_non_deferral', type='wizard')
self.tax = POOL.get('account.tax')
+ self.party = POOL.get('party.party')
def test0005views(self):
'Test views'
@@ -135,6 +136,8 @@ class AccountTestCase(unittest.TestCase):
'Test account debit/credit'
with Transaction().start(DB_NAME, USER,
context=CONTEXT) as transaction:
+ party = self.party(name='Party')
+ party.save()
fiscalyear, = self.fiscalyear.search([])
period = fiscalyear.periods[0]
journal_revenue, = self.journal.search([
@@ -168,6 +171,7 @@ class AccountTestCase(unittest.TestCase):
}, {
'account': receivable.id,
'debit': Decimal(100),
+ 'party': party.id,
}]),
],
},
@@ -182,6 +186,7 @@ class AccountTestCase(unittest.TestCase):
}, {
'account': payable.id,
'credit': Decimal(30),
+ 'party': party.id,
}]),
],
},
diff --git a/view/account_form.xml b/view/account_form.xml
index cb616a1ea7..828787a775 100644
--- a/view/account_form.xml
+++ b/view/account_form.xml
@@ -26,6 +26,8 @@ this repository contains the full copyright notices and license terms. -->
+
+