Make party mandatory / invisible according to account configuration
issue3731 review14341002
This commit is contained in:
+12
@@ -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
|
||||
|
||||
@@ -326,6 +326,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="type" ref="account_type_template_asset_current_receivable"/>
|
||||
<field name="reconcile" eval="True"/>
|
||||
<field name="deferral" eval="True"/>
|
||||
<field name="party_required" eval="True"/>
|
||||
<field name="parent" ref="account_template_root"/>
|
||||
<field name="kind">receivable</field>
|
||||
</record>
|
||||
@@ -334,6 +335,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="type" ref="account_type_template_liability_current_payable"/>
|
||||
<field name="reconcile" eval="True"/>
|
||||
<field name="deferral" eval="True"/>
|
||||
<field name="party_required" eval="True"/>
|
||||
<field name="parent" ref="account_template_root"/>
|
||||
<field name="kind">payable</field>
|
||||
</record>
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
}]),
|
||||
],
|
||||
},
|
||||
|
||||
@@ -26,6 +26,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="currency"/>
|
||||
<label name="second_currency"/>
|
||||
<field name="second_currency"/>
|
||||
<label name="party_required"/>
|
||||
<field name="party_required"/>
|
||||
<field name="taxes" colspan="4"/>
|
||||
</page>
|
||||
<page string="Children" id="children">
|
||||
|
||||
Reference in New Issue
Block a user