Skip to Content
Menu
This question has been flagged
3 Replies
6963 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
u'invoice_validate()'


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



invoice_edits()

and here is my view xml file 



<openerp>
<data>

<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">
<data>
<xpath expr="//field[@name='account_id']" position="after">
<field name="state_bool" attrs="{'readonly': [('state', '=', 'open')]}"/>
</xpath>
</data>
</field>
</record>
</data>
</openerp>

and here is my sequence file 



<?xml version="1.0" encoding="utf-8"?>
<openerp>
<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>

<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>
</record>
</data>
</openerp>

may i have some help please ?

Avatar
Discard
Best Answer

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):
        try:
            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)

Avatar
Discard
Best Answer

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.. 

Avatar
Discard
Best Answer

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.

Avatar
Discard
Related Posts Replies Views Activity
0
Oct 15
3013
0
Sep 24
181
2
Mar 24
1015
2
Oct 23
1764
2
Feb 23
1856