Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to add penalty in customer invoice in OpenERP-6.1?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 716
    Comment on it

    In OpenERP first, install the account module and then create the own module and relate it to the fields payment term in account module.

    Follow these steps given below:

    Step1- First create file in your own module and pass this file in your file. Then create a function and pass this function in button.

    Use this code given below:

    import time
    from lxml import etree
    import decimal_precision as dp
    from tools.translate import _
    import netsvc
    import pooler
    from osv import fields, osv, orm
    import datetime
    from datetime import datetime
    from datetime import date, timedelta
    import types
    class add_penalty(osv.osv):
        _name = 'add.penalty'
        def _get_result(self,cr,uid,ids,name,args,context=None):
            invoice = self.pool.get('account.invoice')
            cr.execute("select sum(amount_total) from account_invoice")
            invoices = cr.fetchone()
            if invoices:
                name = invoices[0]
                for inv in self.pool.get('add.penalty').browse(cr, uid, ids, context=context):
                    res[] = name
            return res    
        _columns ={
                    'test':fields.function(_get_result,'Grand Total', store = True),
        def get_result(self,cr,uid,ids,context=None):     
            invoice = self.pool.get('account.invoice')
            cr.execute("select sum(amount_total) from account_invoice")
            invoices = cr.fetchone()
            if invoices:
                name = invoices[0]            
            raise orm.except_orm(_('Sum'), str(name))
            return True
        def test_amount(self, cr, uid, ids,context=None):   
            res = {}
            date_diff = 0
            now =        
            now = now.strftime('%Y-%m-%d')
            date_now = datetime.strptime(now,'%Y-%m-%d')
            dt = date_now
            name = 'CD Break'
            comment = 'Write-Off'
            cd_flag = True
            tname = 'None'
            qty = 1
            rate = 1.00
            amount = 0.0
            amt = 0.0
            pay_option = 'without_writeoff'
            mline_state = 'valid'
            move_state = 'draft'
            ptype = 'dr'
            v_state = 'draft'
            v_type = 'sale'         
            seq_id = self.pool.get('ir.sequence').search(cr, uid, [('name','=','Sales Journal')])[0]
            vnumber = self.pool.get('ir.sequence').next_by_id(cr, uid, seq_id)
            ref = vnumber.replace('/','')
            account = self.pool.get('account.account')
            acc_id = 11
            acc_id1 = 39
            j_id = 1
            invoice = self.pool.get('account.invoice')        
            cr.execute("select * from account_invoice where state = 'open' and payment_term > 0 and cash_credit='Credit Tax Invoice'")
            invoices = invoice.browse(cr, uid, map(lambda x: x[0], cr.fetchall()) )
            for inv in invoices:            
                if (inv.penalty_date):
                    dt = datetime.strptime(inv.penalty_date,'%Y-%m-%d')
                elif inv.date_due:
                    dt = datetime.strptime(inv.date_due,'%Y-%m-%d')
                date_diff = date_now - dt
                if inv.state == 'open' and date_diff.days >=30:
                    amount = inv.residual * 0.03
                    inv.residual += amount
                    inv.amount_total += amount
                    orig = inv.origin              
                    if orig:
                        line = self.pool.get('account.move.line')
                        cr.execute("SELECT id FROM account_move_line WHERE ref = %s",(orig,))
                        lines = line.browse(cr, uid, map(lambda x: x[0], cr.fetchall()) )
                        product = self.pool.get('product.product')                    
                        credit_flag = 'true'                    
                        serial = str(name + '-' + inv.serial_number)
                        for l in lines:                        
                            if l.debit > 0.00:                            
                                l.debit += amount                            
                            if > 0.00 and > 0 and credit_flag == 'true':
                                credit_flag = 'false'                                               
                       += amount
                                cr.execute('insert into account_invoice_line (origin,account_id,name,invoice_id,price_unit,quantity,partner_id,price_subtotal,tax_name) values (%s, %s, %s, %s, %s, %s, %s, %s, %s)', (orig,,name,,amount,qty,,amount,tname)) 
                                cr.execute('insert into account_voucher (create_date,date,type,partner_id,comment,company_id,account_id,period_id,move_id,journal_id,amount,payment_rate_currency_id,payment_rate,payment_option,state,number) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) RETURNING id', (,,v_type,,comment,,acc_id,,,,amount,,rate,pay_option,v_state,vnumber,))
                                v_id = cr.fetchone()
                                cr.execute('insert into account_voucher_line (create_date,voucher_id,company_id,account_id,name,amount,type) values (%s,%s,%s,%s,%s,%s,%s)',(,v_id,,acc_id1,name,amount,ptype))
                                cr.execute('insert into account_move (name,journal_id,period_id,partner_id,date,state,ref) values(%s,%s,%s,%s,%s,%s,%s) RETURNING id' ,(vnumber,j_id,,,,move_state,ref))
                                move = cr.fetchone()
                                cr.execute('insert into account_move_line (create_date,journal_id,partner_id,credit,debit,ref,account_id,period_id,company_id,date,move_id,name,state) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',(,j_id,,amt,amount,ref,acc_id,,qty,,move,serial,mline_state))
                                cr.execute('insert into account_move_line (create_date,journal_id,partner_id,credit,debit,ref,account_id,period_id,company_id,date,move_id,name,state) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',(,j_id,,amount,amt,ref,acc_id1,,qty,,move,name,mline_state))
                        cr.execute("update account_invoice set penalty_date=%s, cd_break=%s where id=%s",(,cd_flag,,))
            return True
        def button_compute(self, cr, uid, ids, context=None, set_total=False):
            for line in self.browse(cr, uid, ids, context=context):
                if set_total:
                    self.pool.get('add.penalty').write(cr, uid, [], {'name':})
            return True


    Step2- Then create add_penalty.xml file in your own module and pass this file in file.

    Use this code given below:

    <?xml version="1.0" ?>
            <record id="view_invoice_penalty_form" model="ir.ui.view">
                <field name="name">penalty.form</field>
                <field name="model">add.penalty</field>
                <field name="type">form</field>
                <field name="arch" type="xml">
                    <form string="Penalty" >
    					<field name="date"/>
                        <button name="test_amount" string="Penalty" icon="gtk-execute" type="object"/>			
             <record id="ir_cron_mail_gateway_action" model="ir.cron">
                <field name="name">Auto Penalty</field>
                <field name="interval_number">1</field>
                <field name="interval_type">days</field>
                <field name="numbercall">-1</field>
                <field name="doall" eval="False"/>
                <field name="model">add.penalty</field>
                <field name="function">test_amount</field>
               <field eval="'()'" name="args"/>
    		<record model="ir.actions.act_window" id="action_penalty_form">
    			<field name="name">Add penalty</field>
    			<field name="res_model">add.penalty</field>
    		<menuitem name="Add Penalty" id="menu_penalty" parent="account.menu_finance" action="action_penalty_form" sequence="2"/>		

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: