Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
2871 Vistas

Odoo version: 17.0

 I am trying to change the "street" field of the view_partner_form form from a custom module but when I do so my changes do not take effect, records are still being made with the "street" field empty.



Details here

Al realizar los cambios desde el modelo me aparece el siguiente mensaje:


Avatar
Descartar
Mejor respuesta


Avatar
Descartar
Mejor respuesta

Hello Mario Ivan,


Hope you are doing well.


Add below snippet code in your xml file first. after that just go to the point 1 for further process.


//Code in Comment//

1 Add XML file in manifest as mentioned in below snippet code. 

2 Update Module:

-> After making changes to your custom module, ensure you update the module to apply the changes:

3 Enable Developer Mode:

-> In Odoo, enable Developer Mode (Debug Mode) to inspect the view and ensure your changes are being loaded. 

    You can also use the "View Fields" feature to verify the properties of the street field.


Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari

Avatar
Descartar

Code :

<record id="view_partner_form_inherit" model="ir.ui.view">
<field name="name">partner.form.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="street" position="attributes">
<attribute name="required">True</attribute>
</field>
</field>
</record>

Mejor respuesta

Hi Mario:

Did you restart the server and upgrade your customize module ? 

 If you did not set your development config with "--dev=xml" or "--dev=all" ,  you might need to restart and upgrade the module to activate your change.

Personally i think your code shown as your image looks good. By the way, if you want to locate to a specific field, you can try using directly the field element locator   :

    <field name="street" position="attributes">

        <attribute="..."> ...  </attribute>

    </field>

   


 


Avatar
Descartar
Autor

Yes, I have restarted the server and updated the module manually. But still the changes have no effect. I wanted to make this change only in the form view "view.partner.form", for now I solved it from the "res.partner" model, even though the change works when doing it this way an error appears in the log with the following message: "Table 'res_partner': unable to set NOT NULL on column 'street'".

Hi Mario:

The error log actually means the setting "required=True" on the field already works. It's generated by sql constraint : since the field has been set to 'required', the ORM or say the database will check if any value allocated to such field before writing. If no valid value, It will raise an error like your log and abort writing into the database.

Two ways can verify:
1、Check the column's properties in pgAdmin :
open your database in pgAdmin -> go to the table 'res_partner', right-click on it -> open the 'properties' window -> click on the tab 'column' , you can see the if the option 'NOT NULL' is checked on the field 'street';

2、create a new record
You can try to create a new record , leave the field 'street' empty and save, a notification must popup at the upper right corner of the page indicating ** field can be empty.

In one word, ‘required=True’ will pass an instruction to database that the column(field) must be NOT NULL (not empty)and vice versa.

Publicaciones relacionadas Respuestas Vistas Actividad
1
mar 21
9214
5
ago 24
46568
2
abr 24
2517
3
jun 23
5725
2
jun 23
4687