diff --git a/account_credit_control/account.py b/account_credit_control/account.py index 3eaf23950..9e8011b0b 100644 --- a/account_credit_control/account.py +++ b/account_credit_control/account.py @@ -20,6 +20,7 @@ ############################################################################## from openerp.osv import orm, fields + class AccountAccount(orm.Model): """Add a link to a credit control policy on account.account""" @@ -33,6 +34,15 @@ class AccountAccount(orm.Model): readonly=True), } + def copy_data(self, cr, uid, id, default=None, context=None): + if default is None: + default = {} + else: + default = default.copy() + default['credit_control_line_ids'] = False + return super(AccountAccount, self).copy_data( + cr, uid, id, default=default, context=context) + class AccountInvoice(orm.Model): """Add a link to a credit control policy on account.account""" @@ -54,24 +64,12 @@ class AccountInvoice(orm.Model): readonly=True), } - def action_move_create(self, cr, uid, ids, context=None): - """ Write the id of the invoice in the generated moves. """ - 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}, context=ctxt) - return res - - -class AccountMoveLine(orm.Model): - - _inherit = "account.move.line" - - _columns = {'invoice_id': fields.many2one('account.invoice', 'Invoice')} + def copy_data(self, cr, uid, id, default=None, context=None): + if default is None: + default = {} + else: + default = default.copy() + default = default.copy() + default['credit_control_line_ids'] = False + return super(AccountInvoice, self).copy_data( + cr, uid, id, default=default, context=context) diff --git a/account_credit_control/line.py b/account_credit_control/line.py index 5b6378e25..d450e0697 100644 --- a/account_credit_control/line.py +++ b/account_credit_control/line.py @@ -130,7 +130,7 @@ class CreditControlLine(orm.Model): data['date_due'] = move_line.date_maturity data['state'] = 'draft' data['channel'] = level.channel - data['invoice_id'] = move_line.invoice_id.id if move_line.invoice_id else False + data['invoice_id'] = move_line.invoice.id if move_line.invoice else False data['partner_id'] = move_line.partner_id.id data['amount_due'] = (move_line.amount_currency or move_line.debit or move_line.credit) diff --git a/account_credit_control/partner.py b/account_credit_control/partner.py index 57e88561d..0e4605081 100644 --- a/account_credit_control/partner.py +++ b/account_credit_control/partner.py @@ -41,3 +41,12 @@ class ResPartner(orm.Model): string='Credit Control Lines', readonly=True) } + + def copy_data(self, cr, uid, id, default=None, context=None): + if default is None: + default = {} + else: + default = default.copy() + default['credit_control_line_ids'] = False + return super(ResPartner, self).copy_data( + cr, uid, id, default=default, context=context) diff --git a/account_credit_control/policy.py b/account_credit_control/policy.py index a7d104961..6e4a49c1a 100644 --- a/account_credit_control/policy.py +++ b/account_credit_control/policy.py @@ -34,8 +34,8 @@ class CreditControlPolicy(Model): 'Policy Levels'), 'do_nothing': fields.boolean('Do nothing', - help=('For policies which should not', - 'generate lines or are obsolete')), + help='For policies which should not ' + 'generate lines or are obsolete'), 'company_id': fields.many2one('res.company', 'Company'), diff --git a/account_credit_control/run.py b/account_credit_control/run.py index 656de6bd4..1fc739b9f 100644 --- a/account_credit_control/run.py +++ b/account_credit_control/run.py @@ -61,6 +61,18 @@ class CreditControlRun(orm.Model): readonly=True), } + def copy_data(self, cr, uid, id, default=None, context=None): + if default is None: + default = {} + else: + default = default.copy() + default.update({ + 'report': False, + 'manual_ids': False, + }) + return super(CreditControlRun, self).copy_data( + cr, uid, id, default=default, context=context) + def _get_policies(self, cr, uid, context=None): return self.pool['credit.control.policy'].search(cr, uid, [], context=context)