Skip to Content
Menu
This question has been flagged

Im using _inherit and adding new field in 'account.move'

in the view 

The problem is that 'tax_totals_json' variable is holding all the taxes and totals So that when I use position 'before' or 'after' it doesn't work I want my custom variable to be Before total value,

 I mean inside that Json variable 


any help please !




Avatar
Discard
Author

Hi and thank you , my problem is that tax_totals_json contains all the taxes and final total , and i want to add my custom value between the taxes values and the final amount value

Best Answer

Hi Zied dams,
tax_totals_json is a computed field and the method that computes the value is "_compute_tax_totals_json". You need make the following changes to add field inside tax_totals_json field.

  • You need to change this method and append your key, value pair in the tax_total_json. here is an example: 


    import json

    class AccountMove(models.Model):
    _inherit = "account.move"

    your_field = ....

    def _compute_tax_totals_json(self):
    super(SaleOrder, self)._compute_tax_totals_json()
    for rec in self:
    tax_totals_json_dict = json.loads(rec.tax_totals_json)
    tax_totals_json_dict.update(
    {'your_field': rec.your_field})
    rec.tax_totals_json = json.dumps(tax_totals_json_dict)

  • Now you have to inherit the "account.TaxtotalsField" template  in extension mode.this xml file should under  "static/src/xml/"
  • Then using xpath add your desired field in the position you prefer. here is an example for steps 2,3:
     


    Sorry unable to incule the example, Dosen't let me add it here


     
  • Lastly, you have to include the xml in the menifest as 'asstes'.  Add the following key, values to your manifest dict```
    'assets': {
    'web.assets_qweb': [
    'you_moduel_name/static/src/xml/your_xml_file_name.xml',
    ],
    },
    ``` 

Hope this helps.

Avatar
Discard

Thanks alot it worked for me

Best Answer

Hello, Zied dams

I hope you are doing well.

You can add the any custom field after or before the field 'tax_totals_json', I think you didn't give the xpath in correct way.

You can try this,

Please find code in comment. 

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard

--> py:

class AccountMove(models.Model):
_inherit = "account.move"

custom_field = fields.Char()

--> xml:

<record id="view_invoice" model="ir.ui.view">
<field name="name">view.invoice</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='tax_totals_json']" position="pos"> # pos = before / after
<field name="custom_field"/>
</xpath>
</field>
</record>

Related Posts Replies Views Activity
2
Jul 23
2494
2
Jan 23
3247
4
Dec 22
6782
1
Jun 22
1568
1
May 22
1957