Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to add value form account invoice line and store in customer form in Odoo-9?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 207
    Comment on it

    In Odoo first install the accounting module and then if users want all customer related account invoice to be added only to the product price and the quantity of the product calculated and stored in the fields in res.partner, for this follow the steps given below:

     

    Step1- First we create module and then inherits the res.partner object in customer form and then create function and functional fields in test.py file.

    Use this code show below

    from openerp.osv import osv, fields
    #from openerp import api
    
    class test(osv.osv):   
       
        def mrg_partner(self, cr, uid, ids,field_name, args, context=None):
            if context is None:
                context = {}
            for order in self.browse(cr,uid,ids):
                rent_obj = self.browse(cr,uid,ids)
                print"=====rent_obj=====",rent_obj
                #inv_ids = rent_obj.partner_id.invoices_ids
                inv_obj = self.pool.get('account.invoice')
                inv_ids = inv_obj.search(cr, uid, [('partner_id','=',order.id)])
                print"=====inv_ids=====",inv_ids
                res = {}
                total = 0
                for inv in inv_obj.browse(cr, uid, inv_ids):
                    for product in inv.invoice_line_ids:
                        sub_total = product.price_unit * product.quantity
                        total += sub_total
                res[order.id] = total 
            return res   
        
        _inherit='res.partner'
        _columns={
                  'TOT': fields.function(string='Total Amount', fnct=mrg_partner, store=True, type='char'),         
                
                 
                  }
          
    test()

     

    Step2- Then create another file like test.xml file and inherits the views of the res.partner object in own module and add existing fields in test.xml file.

    Use this code given below

    <?xml version="1.0"?>
    <openerp>
    <data>	
    <record model="ir.ui.view" id="view_partner_form4">
        <field name="name">res.partner.form.inherit4</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
            
     
            <xpath expr="/form/sheet/group/group/field[@name='website']" position="after">
                 <field name="TOT"/>          
            </xpath> 
        </field>
    </record>      
    
    </data>
    </openerp>

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
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: