This question has been flagged

Hi! I want to extend the base accounting module via my own created module. I added two fields to the database with the following code in my models.py file:


class AccountMove(models.Model):

    _inherit = "account.move"

    my_new_selection = fields.Selection([('0', 'Zero Something'), ('1', 'One Something'),], string="Important Numbers", store=True, default='0')

    my_new_datefield = fields.Datetime(string='Important Dates', store=True)


Now my question is, what is the best way to import those fields into the existing account module views? I want to be able to select something from my_new_selection for each invoice, as well as my_new_datefield. I would also like to be able to add those fields to the columns in the Accounting Overview/Bills and Accounting Overview/Invoices views and to add a filter for those columns. The filter can be done via Add Custom Filter if it is too much work, but i dont know how to add those fields in a) the invoice-creation form and b) the view listing all invoices.


 

Avatar
Discard
Best Answer

Hello,

To do this you need to use the same idea, for this you would need to use the exact same concept as you have with the model with the views. 

You need to inherit the view which you want, the documentation can be found here. You would do this on the filter and the form view as well. Here is an example for inheriting the list (tree) view of the account.move: 

<odoo>
  <data>
    <record id = "odoo_help_3.move_tree_inherit" model = "ir.ui.view">
      <field name = "name"> Account Move Inherit </field>
      <field name = "model"> account.move </field>
      <field name = "inherit_id" ref = "account.view_invoice_tree" />
      <field name = "arch" type = "xml"> <xpath expr = "// field [@ name = 'name']" position = "after">
          <field name = "my_new_datefield" />
        </xpath>
      </field>
    </record>
  </data>
</odoo>

Here is more about xpath . This will be very helpful knowing the different positions and how to get different elements based on attributes. 

Make sure to add the XML files to the manifest data attribute and use the same concept for the other views. 

To find the external id of views you wish to amend, you can enter debug mode and once on a form click on the bug->Edit View:{view type}. 

I hope this helps,

Thanks, 

Avatar
Discard
Author

Thank you Jack, this helped me alot to understand the concept of xpath! Everything works very well!

I want to mark a field in my inherited tree view with a decorator (e.g. decoration-danger) or simply mark the entry red when a certain selection is made, do you have an idea for that aswell? I tried adding the xpath expr /tree[1] to the end, but i am really not certain how it all fits together.

Glad to help,

I have tried this code on the res.partner table at it seems to work in a similar way, you will just need to change some variables.

<xpath expr="//tree" position="attributes">

<attribute name="decoration-danger">is_company == True</attribute>

</xpath>

The idea is you use the position attributes to add the decorator to the tree, just make sure the field you are using for the condition is somewhere in the view.

Thanks,

Author

Wow youre quick. Again, great help, works !! Thank you so much Jack.