mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[FIX+IMP] account_credit_control
* Fix failure to confirm invoice when both account_credit_control and account_constraints are installed * use except_orm instead of except_osv * reindent code * Cleanup * use of deprecated field user_email causes permission error in multicompany setting fixed by using the correct 'email' field in the template
This commit is contained in:
committed by
Pedro M. Baeza
parent
c62d4d2daf
commit
fb703ab8d1
@@ -20,45 +20,53 @@
|
||||
##############################################################################
|
||||
from openerp.osv import orm, fields
|
||||
|
||||
|
||||
class AccountAccount(orm.Model):
|
||||
"""Add a link to a credit control policy on account.account"""
|
||||
|
||||
_inherit = "account.account"
|
||||
|
||||
_columns = {'credit_control_line_ids': fields.one2many('credit.control.line',
|
||||
'account_id',
|
||||
string='Credit Lines',
|
||||
readonly=True)
|
||||
}
|
||||
_columns = {
|
||||
'credit_control_line_ids':
|
||||
fields.one2many('credit.control.line',
|
||||
'account_id',
|
||||
string='Credit Lines',
|
||||
readonly=True),
|
||||
}
|
||||
|
||||
|
||||
class AccountInvoice(orm.Model):
|
||||
"""Add a link to a credit control policy on account.account"""
|
||||
|
||||
_inherit = "account.invoice"
|
||||
_columns = {'credit_policy_id': fields.many2one('credit.control.policy',
|
||||
'Credit Control Policy',
|
||||
help=("The Credit Control Policy "
|
||||
"used for this invoice. "
|
||||
"If nothing is defined, "
|
||||
"it will use the account "
|
||||
"setting or the partner "
|
||||
"setting.")),
|
||||
|
||||
'credit_control_line_ids': fields.one2many('credit.control.line',
|
||||
'invoice_id',
|
||||
string='Credit Lines',
|
||||
readonly=True)
|
||||
}
|
||||
_columns = {
|
||||
'credit_policy_id':
|
||||
fields.many2one('credit.control.policy',
|
||||
'Credit Control Policy',
|
||||
help=("The Credit Control Policy used for this "
|
||||
"invoice. If nothing is defined, it will "
|
||||
"use the account setting or the partner "
|
||||
"setting.")
|
||||
),
|
||||
'credit_control_line_ids':
|
||||
fields.one2many('credit.control.line',
|
||||
'invoice_id',
|
||||
string='Credit Lines',
|
||||
readonly=True),
|
||||
}
|
||||
|
||||
def action_move_create(self, cr, uid, ids, context=None):
|
||||
""" Write the id of the invoice in the generated moves. """
|
||||
res = super(AccountInvoice, self).action_move_create(cr, uid, ids, context=context)
|
||||
for inv in self.browse(cr, uid, ids, context=context):
|
||||
if context is None:
|
||||
context = {}
|
||||
# add from_parent_object to the conxtext to let the line.write
|
||||
# call pass through account_constraints
|
||||
ctxt = context.copy()
|
||||
ctxt['from_parent_object'] = True
|
||||
res = super(AccountInvoice, self).action_move_create(cr, uid, ids, context=ctxt)
|
||||
for inv in self.browse(cr, uid, ids, context=ctxt):
|
||||
if inv.move_id:
|
||||
for line in inv.move_id.line_id:
|
||||
line.write({'invoice_id': inv.id})
|
||||
line.write({'invoice_id': inv.id}, context=ctxt)
|
||||
return res
|
||||
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
<p>Thank you for choosing ${object.company_id.name}! </p>
|
||||
|
||||
-- more info here --
|
||||
<p>${object.user_id.name} ${object.user_id.user_email and '<%s>'%(object.user_id.user_email) or ''}<br/>
|
||||
<p>${object.user_id.name} ${object.user_id.email and '<%s>'%(object.user_id.email) or ''}<br/>
|
||||
${object.company_id.name}<br/>
|
||||
% if object.company_id.street:
|
||||
${object.company_id.street or ''}<br/>
|
||||
|
||||
@@ -186,7 +186,7 @@ class CreditControlLine(orm.Model):
|
||||
def unlink(self, cr, uid, ids, context=None, check=True):
|
||||
for line in self.browse(cr, uid, ids, context=context):
|
||||
if line.state != 'draft':
|
||||
raise osv.except_osv(
|
||||
raise orm.except_orm(
|
||||
_('Error !'),
|
||||
_('You are not allowed to delete a credit control line that '
|
||||
'is not in draft state.'))
|
||||
|
||||
@@ -28,16 +28,16 @@ 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',
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import logging
|
||||
|
||||
from openerp.osv import orm, fields
|
||||
from openerp.tools.translate import _
|
||||
from openerp.osv.osv import except_osv
|
||||
|
||||
logger = logging.getLogger('credit.control.run')
|
||||
|
||||
@@ -35,12 +34,13 @@ class CreditControlRun(orm.Model):
|
||||
_description = """Credit control line generator"""
|
||||
_columns = {
|
||||
'date': fields.date('Controlling Date', required=True),
|
||||
'policy_ids': fields.many2many('credit.control.policy',
|
||||
rel="credit_run_policy_rel",
|
||||
id1='run_id', id2='policy_id',
|
||||
string='Policies',
|
||||
readonly=True,
|
||||
states={'draft': [('readonly', False)]}),
|
||||
'policy_ids':
|
||||
fields.many2many('credit.control.policy',
|
||||
rel="credit_run_policy_rel",
|
||||
id1='run_id', id2='policy_id',
|
||||
string='Policies',
|
||||
readonly=True,
|
||||
states={'draft': [('readonly', False)]}),
|
||||
|
||||
'report': fields.text('Report', readonly=True),
|
||||
|
||||
@@ -50,14 +50,16 @@ class CreditControlRun(orm.Model):
|
||||
required=True,
|
||||
readonly=True),
|
||||
|
||||
'manual_ids': fields.many2many('account.move.line',
|
||||
rel="credit_runreject_rel",
|
||||
string='Lines to handle manually',
|
||||
help=('If a credit control line has been generated on a policy'
|
||||
' and the policy has been changed meantime,'
|
||||
' it has to be handled manually'),
|
||||
readonly=True),
|
||||
}
|
||||
'manual_ids':
|
||||
fields.many2many('account.move.line',
|
||||
rel="credit_runreject_rel",
|
||||
string='Lines to handle manually',
|
||||
help=('If a credit control line has been generated'
|
||||
'on a policy and the policy has been changed '
|
||||
'in the meantime, it has to be handled '
|
||||
'manually'),
|
||||
readonly=True),
|
||||
}
|
||||
|
||||
def _get_policies(self, cr, uid, context=None):
|
||||
return self.pool['credit.control.policy'].search(cr, uid, [], context=context)
|
||||
@@ -72,9 +74,9 @@ class CreditControlRun(orm.Model):
|
||||
order='date DESC', limit=1, context=context)
|
||||
if lines:
|
||||
line = line_obj.browse(cr, uid, lines[0], context=context)
|
||||
raise except_osv(
|
||||
_('Error'),
|
||||
_('A run has already been executed more recently than %s') % (line.date))
|
||||
raise orm.except_orm(_('Error'),
|
||||
_('A run has already been executed more '
|
||||
'recently than %s') % (line.date))
|
||||
return True
|
||||
|
||||
def _generate_credit_lines(self, cr, uid, run_id, context=None):
|
||||
@@ -92,9 +94,8 @@ class CreditControlRun(orm.Model):
|
||||
|
||||
policies = run.policy_ids
|
||||
if not policies:
|
||||
raise except_osv(
|
||||
_('Error'),
|
||||
_('Please select a policy'))
|
||||
raise orm.except_orm(_('Error'),
|
||||
_('Please select a policy'))
|
||||
|
||||
report = ''
|
||||
for policy in policies:
|
||||
@@ -137,9 +138,9 @@ class CreditControlRun(orm.Model):
|
||||
' LIMIT 1 FOR UPDATE NOWAIT')
|
||||
except Exception as exc:
|
||||
# in case of exception openerp will do a rollback for us and free the lock
|
||||
raise except_osv(_('Error'),
|
||||
_('A credit control run is already running'
|
||||
' in background, please try later.'), repr(exc))
|
||||
raise orm.except_orm(_('Error'),
|
||||
_('A credit control run is already running'
|
||||
' in background, please try later.'))
|
||||
|
||||
self._generate_credit_lines(cr, uid, run_id, context)
|
||||
return True
|
||||
|
||||
@@ -19,12 +19,11 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv.orm import TransientModel, fields
|
||||
from openerp.osv.osv import except_osv
|
||||
from openerp.osv import orm, fields
|
||||
from openerp.tools.translate import _
|
||||
|
||||
|
||||
class CreditControlEmailer(TransientModel):
|
||||
class CreditControlEmailer(orm.TransientModel):
|
||||
"""Send emails for each selected credit control lines."""
|
||||
|
||||
_name = "credit.control.emailer"
|
||||
@@ -71,7 +70,7 @@ class CreditControlEmailer(TransientModel):
|
||||
form = self.browse(cr, uid, wiz_id, context)
|
||||
|
||||
if not form.line_ids:
|
||||
raise except_osv(_('Error'), _('No credit control lines selected.'))
|
||||
raise orm.except_orm(_('Error'), _('No credit control lines selected.'))
|
||||
|
||||
line_ids = [l.id for l in form.line_ids]
|
||||
filtered_ids = self._filter_line_ids(
|
||||
|
||||
@@ -18,12 +18,11 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from openerp.osv.orm import TransientModel, fields
|
||||
from openerp.osv.osv import except_osv
|
||||
from openerp.osv import orm, fields
|
||||
from openerp.tools.translate import _
|
||||
|
||||
|
||||
class CreditControlMarker(TransientModel):
|
||||
class CreditControlMarker(orm.TransientModel):
|
||||
"""Change the state of lines in mass"""
|
||||
|
||||
_name = 'credit.control.marker'
|
||||
@@ -81,7 +80,7 @@ class CreditControlMarker(TransientModel):
|
||||
form = self.browse(cr, uid, wiz_id, context)
|
||||
|
||||
if not form.line_ids:
|
||||
raise except_osv(_('Error'), _('No credit control lines selected.'))
|
||||
raise orm.except_orm(_('Error'), _('No credit control lines selected.'))
|
||||
|
||||
line_ids = [l.id for l in form.line_ids]
|
||||
|
||||
|
||||
@@ -20,11 +20,10 @@
|
||||
##############################################################################
|
||||
import base64
|
||||
|
||||
from openerp.osv.orm import TransientModel, fields
|
||||
from openerp.osv.osv import except_osv
|
||||
from openerp.osv import orm, fields
|
||||
from openerp.tools.translate import _
|
||||
|
||||
class CreditControlPrinter(TransientModel):
|
||||
class CreditControlPrinter(orm.TransientModel):
|
||||
"""Print lines"""
|
||||
|
||||
_name = "credit.control.printer"
|
||||
@@ -72,7 +71,7 @@ class CreditControlPrinter(TransientModel):
|
||||
form = self.browse(cr, uid, wiz_id, context)
|
||||
|
||||
if not form.line_ids and not form.print_all:
|
||||
raise except_osv(_('Error'), _('No credit control lines selected.'))
|
||||
raise orm.except_orm(_('Error'), _('No credit control lines selected.'))
|
||||
|
||||
line_ids = [l.id for l in form.line_ids]
|
||||
comms = comm_obj._generate_comm_from_credit_line_ids(cr, uid, line_ids,
|
||||
|
||||
Reference in New Issue
Block a user