Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to calculate fields with total in account invoice line in Odoo-9?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.64k
    Comment on it

    In Odoo first, you have to install accounting module and in our system add existing fields and inherit the accounting module in our own module.

    We will follow these step given below:


    Step1- First we create our own module and inherits the account.invoice.line object and also inherits the account.invoice object then add our existing fields in an file, and also add this file in file.

    Use this code show in below

    import json
    from lxml import etree
    from datetime import datetime
    from dateutil.relativedelta import relativedelta
    from openerp import api, fields, models, _
    from import float_is_zero, float_compare
    from import formatLang
    class AccountInvoice(models.Model):
        _inherit = 'account.invoice'  
        def get_taxes_values(self):
            tax_grouped = {}
            for line in self.invoice_line_ids:
                price_unit = line.price_unit * (1 - ( or 0.0) / 100.0) + line. yourfield
                taxes = line.invoice_line_tax_ids.compute_all(price_unit, self.currency_id, line.quantity, line.product_id, self.partner_id)['taxes']
                for tax in taxes:
                    val = {
                        'name': tax['name'],
                        'tax_id': tax['id'],
                        'amount': tax['amount'],
                        'manual': False,
                        'sequence': tax['sequence'],
                        'account_analytic_id': tax['analytic'] and or False,
                        'account_id': self.type in ('out_invoice', 'in_invoice') and (tax['account_id'] or or (tax['refund_account_id'] or,
                    if not val.get('account_analytic_id') and line.account_analytic_id and val['account_id'] ==
                        val['account_analytic_id'] =
                    key = tax['id']
                    if key not in tax_grouped:
                        tax_grouped[key] = val
                        tax_grouped[key]['amount'] += val['amount']
            return tax_grouped
    class AccountInvoiceLine(models.Model):
        _inherit = "account.invoice.line"
        _description = "Invoice Line"
        yourfield = fields.Integer(string='Your fields name', default=10) 
        @api.depends('price_unit', 'discount', 'invoice_line_tax_ids', 'quantity',
            'product_id', 'invoice_id.partner_id', 'invoice_id.currency_id', 'invoice_id.company_id')
        def _compute_price(self):
            currency = self.invoice_id and self.invoice_id.currency_id or None
            price = self.price_unit * (1 - ( or 0.0) / 100.0) + self. yourfield
            taxes = False
            if self.invoice_line_tax_ids:
                taxes = self.invoice_line_tax_ids.compute_all(price, currency, self.quantity, product=self.product_id, partner=self.invoice_id.partner_id)
            self.price_subtotal = price_subtotal_signed = taxes['total_excluded'] if taxes else self.quantity * price
            if self.invoice_id.currency_id and self.invoice_id.currency_id != self.invoice_id.company_id.currency_id:
                price_subtotal_signed = self.invoice_id.currency_id.compute(price_subtotal_signed, self.invoice_id.company_id.currency_id)
            sign = self.invoice_id.type in ['in_refund', 'out_refund'] and -1 or 1
            self.price_subtotal_signed = price_subtotal_signed * sign


    Step2- Then we have to create an invoice.XML file in our module and inherits the view of account.invoice.line object and then add it to our existing fields in this file and pass this file in file in module.

    Use this show in given below

     <record id="invoice_form" model="ir.ui.view">
    		<field name="name">account.invoice.form.inherit</field>
    		<field name="model">account.invoice</field>
    		<field name="inherit_id" ref="account.invoice_form" />
    		<field name="arch" type="xml">
    				<field name="quantity" position="after">
    				<field name="yourfield"/>


 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: