Odoo Help

1

0
4 الإجابات
2
Ilusoria كولومبيا
31‏/10‏/2017 11:44 ص

I did it this way:

first I created a new field type Many2many:

objectA_ids = fields.Many2many('res.partner')

then a function that gets the value of the old Many2one field:

@api.model
    def _fill_objects(self):
        products = self.env['module.name'].search(
            ['&', ('objectA_id', '!=', False), ('objectA_ids', '=', False)])
        for r in products:
            if not r.objectA_ids and r.objectA_id:
                r.objectA_ids = [(4, r.objectA_id.id)]
            else:
                r.objectA_ids = False


and in the last step, i did make an XML call to the function when the module it's installing:


<odoo>
   <data noupdate="1">
    <function model="module.name" name="_fill_objects"/>
  </data>
</odoo>


after installing the module the new field has the values of the old field, there's no way for change the field type without lost data, so we have to create a new field, copy data from the old field, and make the old field invisible on view.


<odoo>
  <data>
    <record id="view_module_name_adjustment" model="ir.ui.view">
      <field name="name">module.name.view.form</field>
      <field name="model">module.name</field>
      <field name="inherit_id" ref="module_view_external_id"/>
      <field name="arch" type="xml">
        <field name="objectA_id" position="after">
          <field name="objectA_ids" widget="many2many_tags"/>
        </field>
        <field name="objectA_id" position="attributes">
          <attribute name="invisible">True</attribute>
        </field>
      </field>
    </record>
   </data>
</odoo>
اطرح سؤالاً
Writer
Keep Informed
1 متابعين
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