Browse Source

Black, isort and other pre-commit stuff

14.0
Alexis de Lattre 4 years ago
committed by Simone Orsi
parent
commit
dc876eeeab
  1. 26
      partner_address_street3/__manifest__.py
  2. 3
      partner_address_street3/models/res_country.py
  3. 9
      partner_address_street3/models/res_partner.py
  4. 41
      partner_address_street3/tests/test_street_3.py
  5. 56
      partner_address_street3/views/res_partner.xml

26
partner_address_street3/__manifest__.py

@ -3,17 +3,17 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Street3 in addresses',
'summary': 'Add a third address line on partners',
'license': 'AGPL-3',
'version': '14.0.1.0.0',
'author': "Camptocamp,Odoo Community Association (OCA)",
'maintainer': 'Camptocamp',
'category': 'Sales',
'depends': ['base_view_inheritance_extension'],
'website': 'https://github.com/OCA/partner-contact',
'data': ['views/res_partner.xml'],
'post_init_hook': 'post_init_hook',
'uninstall_hook': 'uninstall_hook',
'installable': True,
"name": "Street3 in addresses",
"summary": "Add a third address line on partners",
"license": "AGPL-3",
"version": "14.0.1.0.0",
"author": "Camptocamp,Odoo Community Association (OCA)",
"maintainer": "Camptocamp",
"category": "Sales",
"depends": ["base_view_inheritance_extension"],
"website": "https://github.com/OCA/partner-contact",
"data": ["views/res_partner.xml"],
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
"installable": True,
}

3
partner_address_street3/models/res_country.py

@ -7,7 +7,8 @@ from odoo import fields, models
class ResCountry(models.Model):
"""Override default adresses formatting of countries"""
_inherit = 'res.country'
_inherit = "res.country"
address_format = fields.Text(
default=(

9
partner_address_street3/models/res_partner.py

@ -7,19 +7,20 @@ from odoo import api, fields, models
class ResPartner(models.Model):
"""Add third field in address"""
_inherit = "res.partner"
street3 = fields.Char('Street 3')
street3 = fields.Char("Street 3")
@api.model
def _address_fields(self):
res = super()._address_fields()
res.append('street3')
res.append("street3")
return res
def _display_address(self, without_company=False):
"""Remove empty lines which can happen when street3 field is empty."""
res = super()._display_address(without_company=without_company)
while '\n\n' in res:
res = res.replace('\n\n', '\n')
while "\n\n" in res:
res = res.replace("\n\n", "\n")
return res

41
partner_address_street3/tests/test_street_3.py

@ -8,29 +8,32 @@ from odoo.tests.common import TransactionCase
class TestStreet3(TransactionCase):
def test_partner(self):
# Test address_format has been updated on existing countries
us_country = self.env.ref('base.us')
self.assertTrue('%(street3)s' in us_country.address_format)
us_country = self.env.ref("base.us")
self.assertTrue("%(street3)s" in us_country.address_format)
homer = self.env['res.partner'].create({
'name': 'Homer Simpson',
'city': 'Springfield',
'street': '742 Evergreen Terrace',
'street2': 'Donut Lane',
'street3': 'Tho',
'country_id': us_country.id,
})
homer = self.env["res.partner"].create(
{
"name": "Homer Simpson",
"city": "Springfield",
"street": "742 Evergreen Terrace",
"street2": "Donut Lane",
"street3": "Tho",
"country_id": us_country.id,
}
)
# test synchro of street3 on create
bart = self.env['res.partner'].create({
'name': 'Bart Simpson',
'parent_id': homer.id,
'type': 'contact',
})
self.assertEqual(bart.street3, 'Tho')
bart = self.env["res.partner"].create(
{
"name": "Bart Simpson",
"parent_id": homer.id,
"type": "contact",
}
)
self.assertEqual(bart.street3, "Tho")
# test synchro of street3 on write
homer.write({'street3': 'in OCA we trust'})
self.assertEqual(bart.street3, 'in OCA we trust')
homer.write({"street3": "in OCA we trust"})
self.assertEqual(bart.street3, "in OCA we trust")

56
partner_address_street3/views/res_partner.xml

@ -3,27 +3,37 @@
<record id="view_partner_form" model="ir.ui.view">
<field name="name">add street3 in form view</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<xpath
expr="/form/sheet/group/group/div/field[@name='street2']"
position="after">
<field name="street3"
placeholder="Street 3..."
class="o_address_street"
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"/>
expr="/form/sheet/group/group/div/field[@name='street2']"
position="after"
>
<field
name="street3"
placeholder="Street 3..."
class="o_address_street"
attrs="{'readonly': [('type', '=', 'contact'),('parent_id', '!=', False)]}"
/>
</xpath>
<xpath expr='//field[@name="child_ids"]' position="attributes">
<attribute name="context" operation="python_dict"
key="default_street3">street3</attribute>
<attribute
name="context"
operation="python_dict"
key="default_street3"
>street3</attribute>
</xpath>
<xpath expr="/form//field[@name='child_ids']/form//field[@name='street2']"
position="after">
<field name="street3" placeholder="Street 3..." class="o_address_street"/>
<xpath
expr="/form//field[@name='child_ids']/form//field[@name='street2']"
position="after"
>
<field name="street3" placeholder="Street 3..." class="o_address_street" />
</xpath>
<xpath expr="/form//field[@name='child_ids']/kanban/field[@name='street2']"
position="after">
<field name="street3"/>
<xpath
expr="/form//field[@name='child_ids']/kanban/field[@name='street2']"
position="after"
>
<field name="street3" />
</xpath>
</field>
</record>
@ -31,10 +41,10 @@
<record id="res_partner_kanban_view" model="ir.ui.view">
<field name="name">add street 3 in kanban</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.res_partner_kanban_view"/>
<field name="inherit_id" ref="base.res_partner_kanban_view" />
<field name="arch" type="xml">
<field name="street2" position="after">
<field name="street3"/>
<field name="street3" />
</field>
</field>
</record>
@ -42,10 +52,10 @@
<record id="view_partner_address_form" model="ir.ui.view">
<field name="name">add street 3 in res.partner.form.address</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_address_form"/>
<field name="inherit_id" ref="base.view_partner_address_form" />
<field name="arch" type="xml">
<field name="street2" position="after">
<field name="street3" placeholder="Street 3..." class="o_address_street"/>
<field name="street3" placeholder="Street 3..." class="o_address_street" />
</field>
</field>
</record>
@ -53,10 +63,14 @@
<record id="res_partner_view_form_private" model="ir.ui.view">
<field name="name">add street 3 in res.partner.form.private</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.res_partner_view_form_private"/>
<field name="inherit_id" ref="base.res_partner_view_form_private" />
<field name="arch" type="xml">
<field name="street2" position="after">
<field name="street3" placeholder="Street 3..." class="o_address_street"/>
<field
name="street3"
placeholder="Street 3..."
class="o_address_street"
/>
</field>
</field>
</record>

Loading…
Cancel
Save