Odoo Help

Welcome!

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

0

Create a new invoice sequence

By
Mostafa Mohamed Abdelmonam Abdo
on 6/11/15, 11:23 AM 893 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 ?

0

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)

0

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

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

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

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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