Odoo Help

0

[Odoo 11] How to add an editable field in a treeview.

By
Valentin
on 2/13/18, 10:18 AM 1,219 views

Hello,

I try to add a new editable column on tree view of payments in POS Orders to add the date of receipt of check method payments.

I already add the column, but I can't edit it.

This is my xml :

<record id="date_receipt_check" model="ir.ui.view">

<field name="name">pos.order.form.view.inherit</field>

<field name="model">pos.order</field>

<field name="inherit_id" ref="point_of_sale.view_pos_pos_form"></field>

<field name="arch" type="xml">

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

<attribute name="editable">tpo</attribute>

</xpath>

<xpath expr="//field[@name='amount']" position="after">

<field name="date_receipt" readonly="False" />

</xpath>

</field>

</record>


Currently, when I click on the "date_receipt" field in tree, it opens a popup "Open: Payments" and therefore, I can not edit my date.

What I need to do to make it editable ?

Seems like Typo/Spell mistake while making editable treeview .

<attribute name="editable">tpo</attribute>

It should be like <attribute name="editable">top</attribute>

Dipak Shah
on 2/13/18, 10:53 AM

This is an error made when I created this post. My xml does not have this error.

Valentin
on 2/13/18, 11:11 AM
1
Valentin
On 2/14/18, 11:05 AM

I have resolved my problème.

First I have overrided field "statement_ids" to make readonly at false

class PosOrder(models.Model):

_inherit = 'pos.order'

# Override the statement_ids field to make readonly at false

    statement_ids = fields.One2many('account.bank.statement.line', 'pos_statement_id', string='Payments', readonly=False)

And in my view :

  1. I have disable creation and deletion to the treeview,

  2. Enable readonly for all fields of the treeview,

  3. And add my new field with readonly at "False".

<record id="receipt_checks_date" model="ir.ui.view">

<field name="name">pos.order.form.view.inherit</field>

<field name="model">pos.order</field>

<field name="inherit_id" ref="point_of_sale.view_pos_pos_form"></field>

<field name="arch" type="xml">

<!--Disable creation and deletion to the treeview of the statement ordres-->

<xpath expr="//field[@name='statement_ids']/tree" position="attributes">

<attribute name="create">false</attribute>

<attribute name="delete">false</attribute>

</xpath>

<!--Make all fields readonly except receipt_date-->

<xpath expr="//field[@name='journal_id']" position="attributes">

<attribute name="readonly">1</attribute>

</xpath>

<xpath expr="//field[@name='statement_id']" position="attributes">

<attribute name="readonly">1</attribute>

</xpath>

<xpath expr="//field[@name='amount']" position="attributes">

<attribute name="readonly">1</attribute>

</xpath>

<!--Add column "Receipt date" in the treeview of payment lines-->

<xpath expr="//field[@name='amount']" position="after">

<field name="receipt_date" readonly="0" />

</xpath>

</field>

</record>


I don't no if it's the best solution, but it work.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 2/13/18, 10:18 AM
Seen: 1219 times
Last updated: 2/14/18, 11:05 AM