Skip to Content
Menu
This question has been flagged
3 Replies
6042 Views

Hello All,

I have managed to add a custom column on my invoices but I would like now as the tax, to impact the subtotal with these new field.

How can I do it ?

 

Thanks in advance

Avatar
Discard

can you paste the code of what you have achieved so far , so that we can help you

Best Answer

How did you add a custom column on the invoices? Can you help me with the steps?

Avatar
Discard
Best Answer

@Kuldeep

For adding a new column to Invoice line , first you need to inherit the account_invoice_line class. Create a custom module for that.

account_invoice.py:

class AccountInvoiceLine(models.Model):
    
_inherit = 'account.invoice.line'
     
    
@api.depends('quantity', 'price_unit')
    def _compute_gross_amount(self):
        """
        Compute the Gross amount of the IN line.
        """
        for line in self:
            line.gross_amount = line.quantity * line.price_unit


gross_amount = fields.Monetary(compute='_compute_gross_amount', string='Gross Amount', readonly=True, store=True)

In the account_invoice view.xml you need to inherit hte invoice view , I am here putting the customer invoice lines view for eg:

account_invoice_view.xml:


        <!-- Update account invoice !-->
        <record id="invoice_form_inherit" 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">   
        
            <xpath expr="/form/sheet/notebook/page/tree/field[@name='price_unit']" position="after">
                    <field name="gross_amount" readonly="0" widget='monetary' options="{'currency_field': 'currency_id'}"/>
                </xpath>   
          
   </field>
     </record>


Avatar
Discard