~unifield-team/unifield-addons/sync-wm

« back to all changes in this revision

Viewing changes to register_accounting/invoice.py

  • Committer: jf
  • Date: 2011-05-16 12:25:06 UTC
  • mfrom: (93.2.49 pa_219)
  • Revision ID: jf@tempo4-20110516122506-z79mm1wsb1rcvnlu
[MERGE] from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
from osv import osv
25
25
from osv import fields
 
26
from tools.translate import _
 
27
 
 
28
import netsvc
26
29
 
27
30
class account_invoice(osv.osv):
28
31
    _name = 'account.invoice'
53
56
            type='many2one', relation="res.partner", readonly=True),
54
57
    }
55
58
 
56
 
    def action_move_create(self, cr, uid, ids, context={}):
 
59
    def action_reconcile_direct_invoice(self, cr, uid, ids, context={}):
57
60
        """
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
60
63
        """
61
 
        res = super(account_invoice, self).action_move_create(cr, uid, ids, context)
62
 
        if res:
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)
 
65
#        if res:
 
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])
80
83
        return True
81
 
 
82
 
    def refresh_wizard_direct_invoice(self, cr, uid, ids, context={}):
83
 
        """
84
 
        Permit to refresh the wizard for direct invoice in order to compute the total of amount given by the invoices lines
85
 
        """
 
84
    
 
85
    def invoice_open(self, cr, uid, ids, context=None):
 
86
        """
 
87
        No longer fills the date automatically, but requires it to be set
 
88
        """
 
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)
86
94
        return True
87
95
 
88
96
account_invoice()