53
56
type='many2one', relation="res.partner", readonly=True),
56
def action_move_create(self, cr, uid, ids, context={}):
59
def action_reconcile_direct_invoice(self, cr, uid, ids, context={}):
58
61
Reconcile move line if invoice is a Direct Invoice
59
62
NB: In order to define that an invoice is a Direct Invoice, we need to have register_line_ids not null
61
res = super(account_invoice, self).action_move_create(cr, uid, ids, context)
63
for inv in self.browse(cr, uid, ids):
64
# Verify that this invoice is linked to a register line and have a move
65
if inv.move_id and inv.register_line_ids:
66
ml_obj = self.pool.get('account.move.line')
67
# First search move line that becomes from invoice
68
res_ml_ids = ml_obj.search(cr, uid, [('move_id', '=', inv.move_id.id), ('account_id', '=', inv.account_id.id)])
69
if len(res_ml_ids) > 1:
70
raise osv.except_osv(_('Error'), _('More than one journal items found for this invoice.'))
71
invoice_move_line_id = res_ml_ids[0]
72
# Then search move line that corresponds to the register line
73
reg_line = inv.register_line_ids[0]
74
reg_ml_ids = ml_obj.search(cr, uid, [('move_id', '=', reg_line.move_ids[0].id), ('account_id', '=', reg_line.account_id.id)])
75
if len(reg_ml_ids) > 1:
76
raise osv.except_osv(_('Error'), _('More than one journal items found for this register line.'))
77
register_move_line_id = reg_ml_ids[0]
78
# Finally do reconciliation
79
ml_reconcile_id = ml_obj.reconcile_partial(cr, uid, [invoice_move_line_id, register_move_line_id])
64
# res = super(account_invoice, self).action_move_create(cr, uid, ids, context)
66
for inv in self.browse(cr, uid, ids):
67
# Verify that this invoice is linked to a register line and have a move
68
if inv.move_id and inv.register_line_ids:
69
ml_obj = self.pool.get('account.move.line')
70
# First search move line that becomes from invoice
71
res_ml_ids = ml_obj.search(cr, uid, [('move_id', '=', inv.move_id.id), ('account_id', '=', inv.account_id.id)])
72
if len(res_ml_ids) > 1:
73
raise osv.except_osv(_('Error'), _('More than one journal items found for this invoice.'))
74
invoice_move_line_id = res_ml_ids[0]
75
# Then search move line that corresponds to the register line
76
reg_line = inv.register_line_ids[0]
77
reg_ml_ids = ml_obj.search(cr, uid, [('move_id', '=', reg_line.move_ids[0].id), ('account_id', '=', reg_line.account_id.id)])
78
if len(reg_ml_ids) > 1:
79
raise osv.except_osv(_('Error'), _('More than one journal items found for this register line.'))
80
register_move_line_id = reg_ml_ids[0]
81
# Finally do reconciliation
82
ml_reconcile_id = ml_obj.reconcile_partial(cr, uid, [invoice_move_line_id, register_move_line_id])
82
def refresh_wizard_direct_invoice(self, cr, uid, ids, context={}):
84
Permit to refresh the wizard for direct invoice in order to compute the total of amount given by the invoices lines
85
def invoice_open(self, cr, uid, ids, context=None):
87
No longer fills the date automatically, but requires it to be set
89
wf_service = netsvc.LocalService("workflow")
90
for inv in self.browse(cr, uid, ids):
91
if not inv.date_invoice:
92
raise osv.except_osv(_('No invoice date !'), _('Please indicate an invoice date before approving the invoice!'))
93
wf_service.trg_validate(uid, 'account.invoice', inv.id, 'invoice_open', cr)