This question has been flagged

I extended res_partner and linked to a "unique code" model like this:

Partner Model :

class Partner(models.Model): _inherit='res.partner'... anagrafiche_codiceunivoco_ids = fields.One2many('utilitypower.codiceunivoco','id_anagrafica',string ='Anagrafica Codice Univoco')

CodiceUnivoco model:

class CodiceUnivoco(models.Model): _name ='utilitypower.codiceunivoco' _description = 'Codice Univoco' codice = fields.Char('Codice Univoco',required=True) id_anagrafica = fields.Many2one('res.partner', string='Cliente')

Res_partner view :

<xpath expr="//notebook" position="inside">  <page name="codice_univoco" string="Codice Univoco"> <field name="anagrafiche_codiceunivoco_ids" string="Codice Univoco" widget="one2many_list" >  <tree> <field name="codice"></field> </tree> </field> </page>

codiceunivoco_view :

<record id="view_form_codiceunivoco" model="ir.ui.view">  <field name="name">Codice Univoco Form</field>  <field name="model">utilitypower.codiceunivoco</field> <field name="arch" type="xml">  <form string="Codice Univoco"> <header></header> <sheet> <group> <field name="codice"></field> <field name="id_anagrafica" widget="man2one_list" /> </group> </sheet> </form> </field> </record>

what I want is that when from the res_partner view I add a record to "univocal code" (via widget one2many_list) and the module view of "univocal code" opens, the record with the client is set with the one from which I opened the module or in alternatively the customer field is hidden.

How can i do this?

Avatar
Discard
Best Answer

One2many already adds by default an active partner into the field id_anagrafica. It is done as soon as you save a partner (no when you add a line). In order to show a partner right when you press 'Add a line', add to your field a context:

<field name="anagrafiche_codiceunivoco_ids" context="{'default_id_anagrafica': active_id}"/>

 Hiding a related partner might be also reasonable, since it anyway would be saved. To that end:

<field name="id_anagrafica" invisible="1"/>



Avatar
Discard
Author

thank you for your answer, i tried your first solution and let me know if i correctly understand :

with context i know that i can pass some informations and in this case with default_fieldname we try to set the default value, active_id i guess that is the active id of the partner from wich we open the insert form of a "codiceunivoco".

so in res_partner form_extended view i added:

<field name="anagrafiche_codiceunivoco_ids" string="Codice Univoco" widget="one2many_list" context="{'default_id_anagrafica': active_id}">

<tree>

<field name="codice"></field>

</tree>

</field>

but when i click to add line the many2one_list in "codiceunivoco" form view doesn't have the client selected.

For the second option i forgot to explaine that i have to hide the field when is called by the partner form but it must be visible when the "codiceunivoco" form view is called by another menu_action.

I think that i can do this with context or domain in id_anagrafica but i can't find how to have the partner_id.

Author

First option is exactly what i want, thank you for your answer.