Odoo Help


Create a new invoice sequence

Mostafa Mohamed Abdel Monaem
on 6/11/15, 11:23 AM 1,960 views

Hi there i'm creating a module to make 2 kinds of invoice with 2 different sequence ...first one with tax and the other with out 

i create a Boolean field to check the kind of invoice and when i press Validate i got that error 

ValueError: "invoice_validate() takes at least 4 arguments (4 given)" while evaluating

here is my module code 

the .py file 

from openerp import models, fields, api

class invoice_edits(models.Model):

_inherit = 'account.invoice'
state_bool = fields.Boolean(string='Active Tax', default=True)

def invoice_validate(self, cr, uid, vals, context=None):
if context is None:
context = {}
if vals.get('state_bool') == True:
vals['number'] = self.pool.get('ir.sequence').get(cr, uid, 'sequence_sale_tax') or '/'
if vals.get('state_bool') == False:
vals['number'] = self.pool.get('ir.sequence').get(cr, uid, 'sequence_sale_without_tax') or '/'
res = super(invoice_edits, self).invoice_validate(cr, uid, vals, context=context)
return res


and here is my view xml file 


<record model="ir.ui.view" id="net2do_invoice_edits_form_inherit">

<field name="name">account.invoice.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='account_id']" position="after">
<field name="state_bool" attrs="{'readonly': [('state', '=', 'open')]}"/>

and here is my sequence file 

<?xml version="1.0" encoding="utf-8"?>
<data noupdate="1">

<record id="sequence_sale_tax" model="ir.sequence">
<field name="name">Account Tax</field>
<field eval="1" name="padding"/>
<field name="prefix">SAJ/%(year)s/</field>

<record id="sequence_sale_without_tax" model="ir.sequence">
<field name="name">Account Default Sales Journal</field>
<field eval="1" name="padding"/>
<field name="prefix">JAS/%(year)s/</field>

may i have some help please ?


Try this

This code works for us :)

def invoice_validate(self, cr, uid, ids, context=None):
    for invoice in self.browse(cr, uid, ids, context=context):
            if not invoice.custom_field:
                raise openerp.exceptions.Warning("Custom error")
        except ValueError:
            raise openerp.exceptions.Warning("Custom")
    super(account_invoice,self).invoice_validate(cr, uid, ids, context=context)




| 5 4 6
Zagreb | Karlovac, Croatia

there is only 10 kind of people the ones that understand binary ... and others

On 6/15/15, 5:47 AM

1. You declared different class, invoice_edits, so calling super to invoice_validate makes no sense.. 
declare account_invoice class ( and _inherit = 'account.invoice') 

2. overriding invoice_validate method does nothing, since the original method only writes state=open and has nothing to do with selecting sequence for invoice...

Maybe the easiest way to achieve what you want.. is to define 2 different journals, and assign different number sequences to each journal... that way, you can easily add more sequences/journals, and define the sequence simply by selecting appropriate journal before validating invoice... no coding needed at all for it.. or, if you want you can code come check on selected journal.. 

Sander Kruger
On 6/12/15, 4:58 AM

The invoice_validate function of account.invoice takes only 1 arguments (self). This function is called from account_invoice_workflow.xml with only 1 argument.

You override the function with a different signature, just like the purchase and portal_sale modules do. But I think you also need to rework the workflow XML document.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/11/15, 11:23 AM
Seen: 1960 times
Last updated: 8/10/15, 1:24 PM