0
votes

I need to change the state of a invoice using it's payment method.

    def _payment_type_get(self, cr, uid, ids, field_name, arg, context={}):
    result = {}
    invoice_obj = self.pool.get('account.move.line')
    for rec in self.browse(cr, uid, ids, context):
        result[rec.id] = (0, 0)
        invoice_id = invoice_obj.search(cr, uid, [(
            'move_id', '=', rec.move_id.id)], context=context)
        if invoice_id:
            inv = invoice_obj.browse(cr, uid, invoice_id[0], context)
            if inv.payment_type:
                result[rec.id] = (inv.payment_type.id, self.pool.get(
                    'payment.type').browse(cr, uid, inv.payment_type.id, context).name)
        else:
            result[rec.id] = (0, 0)
    return result
    if result != '1':
        return self.write(cr, uid, ids, {'state_cheque': 'usado'})
    else:
        return self.write(cr, uid, ids, {'state_cheque': 'caixa'})

I need to get the payment type at the creation of the "cheque", during the invoice closing, so I can set it to Caixa, if it's a Cheque or to Usado if it is not. I don't know if all the names are correct, since I copied it from a guy here who said it would(Shame on me if I let it pass).

The Cheque, like any payment is saved at a journal, cheque is saved at an specific journal with it's name(ChequeJournal), if I can use that to create the default state, It would be better.

Every single way I tried to do it, failed. Recently I've found that the payment type is saved as a int and not as a char or string, but changing it still give no results.

I could not use a self.write , since I'm editing the account_move_line.py, OpenERP can't find what I'm trying to add the state to. So, I need to get the invoice ID in order to change that state. A new problem arises?

1

1 Answers

0
votes

Once a return statement is called, the function immediately exits, so your last 4 lines aren't being executed. (Or maybe that's a formatting error?)