mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Merge pull request #48 from acsone/7.0-account_partner_required_refactor-sbi
7.0 refactor account_partner_required
This commit is contained in:
@@ -6,14 +6,12 @@ python:
|
|||||||
- "2.7"
|
- "2.7"
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- VERSION="7.0" ODOO_REPO="odoo/odoo" EXCLUDE="account_constraints,account_partner_required,async_move_line_importer,account_move_validation_improvement,account_default_draft_move,account_move_batch_validate"
|
- VERSION="7.0" ODOO_REPO="odoo/odoo" EXCLUDE="account_constraints,async_move_line_importer,account_move_validation_improvement,account_default_draft_move,account_move_batch_validate"
|
||||||
- VERSION="7.0" ODOO_REPO="odoo/odoo" INCLUDE="account_constraints,account_move_validation_improvement,account_default_draft_move,account_move_batch_validate"
|
- VERSION="7.0" ODOO_REPO="odoo/odoo" INCLUDE="account_constraints,account_move_validation_improvement,account_default_draft_move,account_move_batch_validate"
|
||||||
- VERSION="7.0" ODOO_REPO="odoo/odoo" INCLUDE="account_partner_required"
|
|
||||||
- VERSION="7.0" ODOO_REPO="odoo/odoo" INCLUDE="async_move_line_importer"
|
- VERSION="7.0" ODOO_REPO="odoo/odoo" INCLUDE="async_move_line_importer"
|
||||||
|
|
||||||
- VERSION="7.0" ODOO_REPO="OCA/OCB" EXCLUDE="account_constraints, account_partner_required,async_move_line_importer,account_move_validation_improvement,account_default_draft_move,account_move_batch_validate"
|
- VERSION="7.0" ODOO_REPO="OCA/OCB" EXCLUDE="account_constraints, async_move_line_importer,account_move_validation_improvement,account_default_draft_move,account_move_batch_validate"
|
||||||
- VERSION="7.0" ODOO_REPO="OCA/OCB" INCLUDE="account_constraints,account_move_validation_improvement,account_default_draft_move,account_move_batch_validate"
|
- VERSION="7.0" ODOO_REPO="OCA/OCB" INCLUDE="account_constraints,account_move_validation_improvement,account_default_draft_move,account_move_batch_validate"
|
||||||
- VERSION="7.0" ODOO_REPO="OCA/OCB" INCLUDE="account_partner_required"
|
|
||||||
- VERSION="7.0" ODOO_REPO="OCA/OCB" INCLUDE="async_move_line_importer"
|
- VERSION="7.0" ODOO_REPO="OCA/OCB" INCLUDE="async_move_line_importer"
|
||||||
|
|
||||||
virtualenv:
|
virtualenv:
|
||||||
|
|||||||
@@ -27,12 +27,17 @@ from openerp.tools.translate import _
|
|||||||
class account_account_type(orm.Model):
|
class account_account_type(orm.Model):
|
||||||
_inherit = "account.account.type"
|
_inherit = "account.account.type"
|
||||||
|
|
||||||
|
def _get_policies(self, cr, uid, context=None):
|
||||||
|
"""This is the method to be inherited for adding policies"""
|
||||||
|
return [('optional', _('Optional')),
|
||||||
|
('always', _('Always')),
|
||||||
|
('never', _('Never'))]
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'partner_policy': fields.selection(
|
'partner_policy': fields.selection(
|
||||||
[('optional', 'Optional'),
|
lambda self, *args, **kwargs: self._get_policies(*args, **kwargs),
|
||||||
('always', 'Always'),
|
|
||||||
('never', 'Never')],
|
|
||||||
'Policy for partner field',
|
'Policy for partner field',
|
||||||
|
required=True,
|
||||||
help="Set the policy for the partner field : if you select "
|
help="Set the policy for the partner field : if you select "
|
||||||
"'Optional', the accountant is free to put a partner "
|
"'Optional', the accountant is free to put a partner "
|
||||||
"on an account move line with this type of account ; "
|
"on an account move line with this type of account ; "
|
||||||
@@ -50,47 +55,41 @@ class account_account_type(orm.Model):
|
|||||||
class account_move_line(orm.Model):
|
class account_move_line(orm.Model):
|
||||||
_inherit = "account.move.line"
|
_inherit = "account.move.line"
|
||||||
|
|
||||||
def check_partner_required(self, cr, uid, ids, vals, context=None):
|
def _get_partner_policy(self, cr, uid, account, context=None):
|
||||||
if 'account_id' in vals or 'partner_id' in vals or \
|
""" Extension point to obtain analytic policy for an account """
|
||||||
'debit' in vals or 'credit' in vals:
|
return account.user_type.partner_policy
|
||||||
if isinstance(ids, (int, long)):
|
|
||||||
ids = [ids]
|
|
||||||
for move_line in self.browse(cr, uid, ids, context):
|
|
||||||
if move_line.debit == 0 and move_line.credit == 0:
|
|
||||||
continue
|
|
||||||
policy = move_line.account_id.user_type.partner_policy
|
|
||||||
if policy == 'always' and not move_line.partner_id:
|
|
||||||
raise orm.except_orm(_('Error :'),
|
|
||||||
_("Partner policy is set to 'Always' "
|
|
||||||
"with account %s '%s' but the "
|
|
||||||
"partner is missing in the account "
|
|
||||||
"move line with label '%s'." %
|
|
||||||
(move_line.account_id.code,
|
|
||||||
move_line.account_id.name,
|
|
||||||
move_line.name)))
|
|
||||||
elif policy == 'never' and move_line.partner_id:
|
|
||||||
raise orm.except_orm(_('Error :'),
|
|
||||||
_("Partner policy is set to 'Never' "
|
|
||||||
"with account %s '%s' but the "
|
|
||||||
"account move line with label '%s' "
|
|
||||||
"has a partner '%s'." %
|
|
||||||
(move_line.account_id.code,
|
|
||||||
move_line.account_id.name,
|
|
||||||
move_line.name,
|
|
||||||
move_line.partner_id.name)))
|
|
||||||
|
|
||||||
def create(self, cr, uid, vals, context=None, check=True):
|
def _check_partner_required_msg(self, cr, uid, ids, context=None):
|
||||||
line_id = super(account_move_line, self).create(cr, uid, vals,
|
for move_line in self.browse(cr, uid, ids, context):
|
||||||
context=context,
|
if move_line.debit == 0 and move_line.credit == 0:
|
||||||
check=check)
|
continue
|
||||||
self.check_partner_required(cr, uid, line_id, vals, context=context)
|
policy = self._get_partner_policy(cr, uid,
|
||||||
return line_id
|
move_line.account_id,
|
||||||
|
context=context)
|
||||||
|
if policy == 'always' and not move_line.partner_id:
|
||||||
|
return _("Partner policy is set to 'Always' "
|
||||||
|
"with account %s '%s' but the "
|
||||||
|
"partner is missing in the account "
|
||||||
|
"move line with label '%s'." %
|
||||||
|
(move_line.account_id.code,
|
||||||
|
move_line.account_id.name,
|
||||||
|
move_line.name))
|
||||||
|
elif policy == 'never' and move_line.partner_id:
|
||||||
|
return _("Partner policy is set to 'Never' "
|
||||||
|
"with account %s '%s' but the "
|
||||||
|
"account move line with label '%s' "
|
||||||
|
"has a partner '%s'." %
|
||||||
|
(move_line.account_id.code,
|
||||||
|
move_line.account_id.name,
|
||||||
|
move_line.name,
|
||||||
|
move_line.partner_id.name))
|
||||||
|
|
||||||
def write(self, cr, uid, ids, vals, context=None, check=True,
|
def _check_partner_required(self, cr, uid, ids, context=None):
|
||||||
update_check=True):
|
return not self._check_partner_required_msg(cr, uid, ids,
|
||||||
res = super(account_move_line, self).write(cr, uid, ids, vals,
|
context=context)
|
||||||
context=context,
|
|
||||||
check=check,
|
_constraints = [
|
||||||
update_check=update_check)
|
(_check_partner_required,
|
||||||
self.check_partner_required(cr, uid, ids, vals, context=context)
|
_check_partner_required_msg,
|
||||||
return res
|
['partner_id', 'account_id', 'debit', 'credit']),
|
||||||
|
]
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class test_account_partner_required(common.TransactionCase):
|
|||||||
self._set_partner_policy('always')
|
self._set_partner_policy('always')
|
||||||
line_id = self._create_move(with_partner=True)
|
line_id = self._create_move(with_partner=True)
|
||||||
with self.assertRaises(orm.except_orm):
|
with self.assertRaises(orm.except_orm):
|
||||||
self.move_line_obj.write(self.cr, self.uid, line_id,
|
self.move_line_obj.write(self.cr, self.uid, [line_id],
|
||||||
{'partner_id': False})
|
{'partner_id': False})
|
||||||
|
|
||||||
def test_change_account(self):
|
def test_change_account(self):
|
||||||
@@ -117,13 +117,13 @@ class test_account_partner_required(common.TransactionCase):
|
|||||||
line_id = self._create_move(with_partner=False)
|
line_id = self._create_move(with_partner=False)
|
||||||
# change account to a_pay with policy always but missing partner
|
# change account to a_pay with policy always but missing partner
|
||||||
with self.assertRaises(orm.except_orm):
|
with self.assertRaises(orm.except_orm):
|
||||||
self.move_line_obj.write(self.cr, self.uid, line_id,
|
self.move_line_obj.write(self.cr, self.uid, [line_id],
|
||||||
{'account_id': self.ref('account.a_pay')})
|
{'account_id': self.ref('account.a_pay')})
|
||||||
# change account to a_pay with policy always with partner -> ok
|
# change account to a_pay with policy always with partner -> ok
|
||||||
self.move_line_obj.write(
|
self.move_line_obj.write(
|
||||||
self.cr,
|
self.cr,
|
||||||
self.uid,
|
self.uid,
|
||||||
line_id,
|
[line_id],
|
||||||
{
|
{
|
||||||
'account_id': self.ref('account.a_pay'),
|
'account_id': self.ref('account.a_pay'),
|
||||||
'partner_id': self.ref('base.res_partner_1')
|
'partner_id': self.ref('base.res_partner_1')
|
||||||
|
|||||||
Reference in New Issue
Block a user