mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[IMP] new constraint to ensure a filtering mechanisme between account and policies
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#
|
||||
##############################################################################
|
||||
from openerp.osv import orm, fields
|
||||
from openerp.tools.translate import _
|
||||
|
||||
|
||||
class ResPartner(orm.Model):
|
||||
@@ -28,21 +29,44 @@ class ResPartner(orm.Model):
|
||||
_inherit = "res.partner"
|
||||
|
||||
_columns = {
|
||||
'credit_policy_id':
|
||||
fields.many2one('credit.control.policy',
|
||||
'Credit Control Policy',
|
||||
help=("The Credit Control Policy used for this "
|
||||
"partner. This setting can be forced on the "
|
||||
"invoice. If nothing is defined, it will use "
|
||||
"the company setting.")),
|
||||
'credit_control_line_ids':
|
||||
fields.one2many('credit.control.line',
|
||||
'invoice_id',
|
||||
string='Credit Control Lines',
|
||||
readonly=True)
|
||||
'credit_policy_id': fields.many2one(
|
||||
'credit.control.policy',
|
||||
'Credit Control Policy',
|
||||
domain="[('account_ids', 'in', property_account_receivable)]",
|
||||
help=("The Credit Control Policy used for this "
|
||||
"partner. This setting can be forced on the "
|
||||
"invoice. If nothing is defined, it will use "
|
||||
"the company setting.")
|
||||
),
|
||||
'credit_control_line_ids': fields.one2many(
|
||||
'credit.control.line',
|
||||
'invoice_id',
|
||||
string='Credit Control Lines',
|
||||
readonly=True
|
||||
)
|
||||
}
|
||||
|
||||
def _check_credit_policy(self, cr, uid, part_ids, context=None):
|
||||
"""Ensure that policy on partner are limited to the account policy"""
|
||||
if isinstance(part_ids, (int, long)):
|
||||
part_ids = [part_ids]
|
||||
policy_obj = self.pool['credit.control.policy']
|
||||
for partner in self.browse(cr, uid, part_ids, context):
|
||||
account = partner.property_account_receivable
|
||||
policy_obj.check_policy_against_account(
|
||||
cr, uid,
|
||||
account.id,
|
||||
partner.credit_policy_id.id,
|
||||
context=context
|
||||
)
|
||||
return True
|
||||
|
||||
_constraints = [(_check_credit_policy,
|
||||
'The policy must be related to the receivable account',
|
||||
['credit_policy_id'])]
|
||||
|
||||
def copy_data(self, cr, uid, id, default=None, context=None):
|
||||
"""Remove credit lines when copying partner"""
|
||||
if default is None:
|
||||
default = {}
|
||||
else:
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from openerp.osv.orm import Model, fields
|
||||
from openerp.osv import orm, fields
|
||||
from openerp.tools.translate import _
|
||||
|
||||
|
||||
class CreditControlPolicy(Model):
|
||||
class CreditControlPolicy(orm.Model):
|
||||
"""Define a policy of reminder"""
|
||||
|
||||
_name = "credit.control.policy"
|
||||
@@ -103,7 +103,10 @@ class CreditControlPolicy(Model):
|
||||
my_obj = self.pool.get(model)
|
||||
move_l_obj = self.pool.get('account.move.line')
|
||||
|
||||
default_domain = self._move_lines_domain(cr, uid, policy, controlling_date, context=context)
|
||||
default_domain = self._move_lines_domain(cr, uid,
|
||||
policy,
|
||||
controlling_date,
|
||||
context=context)
|
||||
to_add_ids = set()
|
||||
to_remove_ids = set()
|
||||
|
||||
@@ -206,8 +209,26 @@ class CreditControlPolicy(Model):
|
||||
different_lines.update([x[0] for x in res])
|
||||
return different_lines
|
||||
|
||||
def check_policy_against_account(self, cr, uid, account_id, policy_id,
|
||||
context=None):
|
||||
"""Ensure that policy correspond to account relation"""
|
||||
policy = self.browse(cr, uid, policy_id, context=context)
|
||||
account = self.pool['account.account'].browse(cr, uid, account_id,
|
||||
context=context)
|
||||
policies_id = self.search(cr, uid, [],
|
||||
context=context)
|
||||
policies = self.browse(cr, uid, policies_id, context=context)
|
||||
allowed = [x for x in policies if
|
||||
account in x.account_ids or x.do_nothing]
|
||||
if policy not in allowed:
|
||||
allowed_names = u"\n".join(x.name for x in allowed)
|
||||
raise orm.except_orm(
|
||||
_('You can only use a policy set on account %s') % account.name,
|
||||
_("Please choose one of the following policies:\n %s") % allowed_names)
|
||||
return True
|
||||
|
||||
class CreditControlPolicyLevel(Model):
|
||||
|
||||
class CreditControlPolicyLevel(orm.Model):
|
||||
"""Define a policy level. A level allows to determine if
|
||||
a move line is due and the level of overdue of the line"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user