Browse Source

[IMP] base_location_nuts: add context on partner form and reload page after import

14.0
Andrii Skrypka 4 years ago
parent
commit
a02065d4d8
  1. 8
      base_location_nuts/models/res_partner.py
  2. 40
      base_location_nuts/views/res_partner_view.xml
  3. 5
      base_location_nuts/wizard/nuts_import.py

8
base_location_nuts/models/res_partner.py

@ -100,21 +100,21 @@ class ResPartner(models.Model):
def onchange_state_id_base_location_nuts(self): def onchange_state_id_base_location_nuts(self):
if self.state_id: if self.state_id:
self.country_id = self.state_id.country_id self.country_id = self.state_id.country_id
if self.state_id.country_id.state_level:
if self.country_id.state_level:
nuts_state = self.env["res.partner.nuts"].search( nuts_state = self.env["res.partner.nuts"].search(
[ [
("level", "=", self.state_id.country_id.state_level),
("level", "=", self.country_id.state_level),
("state_id", "=", self.state_id.id), ("state_id", "=", self.state_id.id),
], ],
limit=1, limit=1,
) )
if nuts_state: if nuts_state:
field = "nuts%d_id" % self.state_id.country_id.state_level
field = "nuts%d_id" % self.country_id.state_level
self[field] = nuts_state self[field] = nuts_state
@api.model @api.model
def _address_fields(self): def _address_fields(self):
fields = super(ResPartner, self)._address_fields()
fields = super()._address_fields()
if fields: if fields:
fields += ["nuts1_id", "nuts2_id", "nuts3_id", "nuts4_id"] fields += ["nuts1_id", "nuts2_id", "nuts3_id", "nuts4_id"]
return fields return fields

40
base_location_nuts/views/res_partner_view.xml

@ -6,19 +6,43 @@
<field name="inherit_id" ref="base.view_partner_form" /> <field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//sheet/group//field[@name='country_id']/.." position="after"> <xpath expr="//sheet/group//field[@name='country_id']/.." position="after">
<field name="nuts1_id" />
<field name="nuts2_id" />
<field name="nuts3_id" />
<field name="nuts4_id" />
<field
name="nuts1_id"
context="{'default_country_id': country_id, 'default_level': 1}"
/>
<field
name="nuts2_id"
context="{'default_country_id': country_id, 'default_level': 2, 'default_parent_id': nuts1_id}"
/>
<field
name="nuts3_id"
context="{'default_country_id': country_id, 'default_level': 3, 'default_parent_id': nuts2_id}"
/>
<field
name="nuts4_id"
context="{'default_country_id': country_id, 'default_level': 4, 'default_parent_id': nuts3_id}"
/>
</xpath> </xpath>
<xpath <xpath
expr="//field[@name='child_ids']/form//field[@name='country_id']/.." expr="//field[@name='child_ids']/form//field[@name='country_id']/.."
position="after" position="after"
> >
<field name="nuts1_id" />
<field name="nuts2_id" />
<field name="nuts3_id" />
<field name="nuts4_id" />
<field
name="nuts1_id"
context="{'default_country_id': country_id, 'default_level': 1}"
/>
<field
name="nuts2_id"
context="{'default_country_id': country_id, 'default_level': 2, 'default_parent_id': nuts1_id}"
/>
<field
name="nuts3_id"
context="{'default_country_id': country_id, 'default_level': 3, 'default_parent_id': nuts2_id}"
/>
<field
name="nuts4_id"
context="{'default_country_id': country_id, 'default_level': 4, 'default_parent_id': nuts3_id}"
/>
</xpath> </xpath>
</field> </field>
</record> </record>

5
base_location_nuts/wizard/nuts_import.py

@ -229,4 +229,7 @@ class NutsImport(models.TransientModel):
"The wizard to create NUTS entries from RAMON " "The wizard to create NUTS entries from RAMON "
"has been successfully completed." "has been successfully completed."
) )
return True
return {
"type": "ir.actions.client",
"tag": "reload",
}
Loading…
Cancel
Save