[FIX] base_address_extended: sync city_id with children contacts
Steps to reproduce:
- Install contacts and base_address_extended
- Install a module adding "res.city" records (e.g. l10n_co_edi)
- Go to Contacts and create a new one:
* Name: [any]
* Country: Colombia
* City (city_id): [any]
- Create a "child" contact of "Contact" type
- Save the contact
Issue:
"city_id" field of the child contact is False.
It is not possible to set the address of a contact-type contact manually.
Some address fields ('street', 'street2', 'zip', 'city', 'state_id', 'country_id')
are synchronized with the parent contact.
"city_id" is not and is not settable at all for contact-type contact.
It could be an issue for Colombian or Mexican localizations if a child contact is
used for an invoice as some data have to be retrieved from "city_id" field to generate
the electronic invoice.
Solution:
Add "city_id" in the list of address fields to sync.
opw-3747296
closes odoo/odoo#158686
X-original-commit: ec059dfd0a3f57754bd481f0a651b01c92b10dea
Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
This commit is contained in:
@@ -16,6 +16,10 @@ class Partner(models.Model):
|
||||
city_id = fields.Many2one(comodel_name='res.city', string='City ID')
|
||||
country_enforce_cities = fields.Boolean(related='country_id.enforce_cities')
|
||||
|
||||
@api.model
|
||||
def _address_fields(self):
|
||||
return super()._address_fields() + ['city_id']
|
||||
|
||||
def _inverse_street_data(self):
|
||||
""" update self.street based on street_name, street_number and street_number2 """
|
||||
for partner in self:
|
||||
|
||||
@@ -36,3 +36,26 @@ class TestStreetFields(TransactionCase):
|
||||
partner.street_number = number
|
||||
partner.street_name = name
|
||||
self.assertEqual(partner.street, street.strip(), 'Wrongly formatted street: expected %s, received %s' % (street, partner.street))
|
||||
|
||||
def test_child_sync(self):
|
||||
""" Test that city_id is propagated to (contact-type) children contacts. """
|
||||
usa = self.env.ref('base.us')
|
||||
new_york_city = self.env['res.city'].create({
|
||||
'name': 'New York',
|
||||
'country_id': usa.id,
|
||||
})
|
||||
parent = self.env['res.partner'].create({
|
||||
'name': 'Parent Company',
|
||||
'country_id': usa.id,
|
||||
'city_id': new_york_city.id,
|
||||
})
|
||||
child = self.env['res.partner'].create({
|
||||
'name': 'Child Contact',
|
||||
'type': 'contact',
|
||||
'parent_id': parent.id,
|
||||
})
|
||||
self.assertRecordValues(child, [{
|
||||
'name': 'Child Contact',
|
||||
'country_id': usa.id,
|
||||
'city_id': new_york_city.id,
|
||||
}])
|
||||
|
||||
Reference in New Issue
Block a user