Browse Source

[IMP] partner_contact_address_default: black, isort, prettier

14.0
manu 4 years ago
committed by Zar21
parent
commit
f273e9d76f
  1. 28
      partner_contact_address_default/__manifest__.py
  2. 12
      partner_contact_address_default/models/res_partner.py
  3. 53
      partner_contact_address_default/tests/test_partner_contact_address_default.py
  4. 39
      partner_contact_address_default/views/res_partner_views.xml

28
partner_contact_address_default/__manifest__.py

@ -2,20 +2,16 @@
# Copyright 2020 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
'name': 'Partner Contact address default',
'summary': 'Set a default delivery and invoice address for contacts',
'version': '12.0.1.0.0',
'development_status': 'Beta',
'category': 'Generic Modules/Base',
'website': 'https://github.com/OCA/partner-contact',
'author': 'Tecnativa, Odoo Community Association (OCA)',
'license': 'AGPL-3',
'application': False,
'installable': True,
'depends': [
'base',
],
'data': [
'views/res_partner_views.xml',
],
"name": "Partner Contact address default",
"summary": "Set a default delivery and invoice address for contacts",
"version": "12.0.1.0.0",
"development_status": "Beta",
"category": "Generic Modules/Base",
"website": "https://github.com/OCA/partner-contact",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["base",],
"data": ["views/res_partner_views.xml",],
}

12
partner_contact_address_default/models/res_partner.py

@ -5,26 +5,24 @@ from odoo import fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
_inherit = "res.partner"
partner_delivery_id = fields.Many2one(
comodel_name='res.partner',
string='Shipping address',
comodel_name="res.partner", string="Shipping address",
)
partner_invoice_id = fields.Many2one(
comodel_name='res.partner',
string='Invoice address',
comodel_name="res.partner", string="Invoice address",
)
def get_address_default_type(self):
return ['delivery', 'invoice']
return ["delivery", "invoice"]
def address_get(self, adr_pref=None):
res = super().address_get(adr_pref)
default_address_type_list = self.get_address_default_type()
for partner in self:
for addr_type in default_address_type_list:
default_address_id = partner['partner_{}_id'.format(addr_type)]
default_address_id = partner["partner_{}_id".format(addr_type)]
if default_address_id:
res[addr_type] = default_address_id
return res

53
partner_contact_address_default/tests/test_partner_contact_address_default.py

@ -5,40 +5,37 @@ from odoo.tests import common
class TestPartnerContactAddressDefault(common.TransactionCase):
def setUp(self):
super().setUp()
self.Partner = self.env['res.partner']
self.partner = self.Partner.create({
'name': 'Parent partner',
})
self.partner_child_delivery1 = self.Partner.create({
'name': 'Child delivery 1',
'type': 'delivery',
'parent_id': self.partner.id,
})
self.partner_child_delivery2 = self.Partner.create({
'name': 'Child delivery 2',
'type': 'delivery',
'parent_id': self.partner.id,
})
self.partner_child_invoice = self.Partner.create({
'name': 'Child invoice',
'type': 'invoice',
'parent_id': self.partner.id,
})
self.Partner = self.env["res.partner"]
self.partner = self.Partner.create({"name": "Parent partner",})
self.partner_child_delivery1 = self.Partner.create(
{
"name": "Child delivery 1",
"type": "delivery",
"parent_id": self.partner.id,
}
)
self.partner_child_delivery2 = self.Partner.create(
{
"name": "Child delivery 2",
"type": "delivery",
"parent_id": self.partner.id,
}
)
self.partner_child_invoice = self.Partner.create(
{"name": "Child invoice", "type": "invoice", "parent_id": self.partner.id,}
)
def test_contact_address_default(self):
self.partner.partner_delivery_id = self.partner
self.partner.partner_invoice_id = self.partner
res = self.partner.address_get()
self.assertEqual(res['delivery'], self.partner)
self.assertEqual(res['invoice'], self.partner)
self.assertEqual(res["delivery"], self.partner)
self.assertEqual(res["invoice"], self.partner)
self.partner_child_delivery2.partner_delivery_id =\
self.partner_child_delivery2
self.partner_child_delivery2.partner_invoice_id =\
self.partner_child_delivery2
self.partner_child_delivery2.partner_delivery_id = self.partner_child_delivery2
self.partner_child_delivery2.partner_invoice_id = self.partner_child_delivery2
res = self.partner_child_delivery2.address_get()
self.assertEqual(res['delivery'], self.partner_child_delivery2)
self.assertEqual(res['invoice'], self.partner_child_delivery2)
self.assertEqual(res["delivery"], self.partner_child_delivery2)
self.assertEqual(res["invoice"], self.partner_child_delivery2)

39
partner_contact_address_default/views/res_partner_views.xml

@ -1,40 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_partner_form" model="ir.ui.view">
<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="//field[@name='child_ids']" position="before">
<group>
<group>
<field name="partner_delivery_id" domain="[('id', 'child_of', commercial_partner_id)]"/>
<field
name="partner_delivery_id"
domain="[('id', 'child_of', commercial_partner_id)]"
/>
</group>
<group>
<field name="partner_invoice_id" domain="[('id', 'child_of', commercial_partner_id)]"/>
<field
name="partner_invoice_id"
domain="[('id', 'child_of', commercial_partner_id)]"
/>
</group>
</group>
</xpath>
<xpath expr="//field[@name='child_ids']//form//group" position="after">
<group string="Force addresses" attrs="{'invisible': [('type', '=', 'private')]}">
<group
string="Force addresses"
attrs="{'invisible': [('type', '=', 'private')]}"
>
<group colspan="4">
<field name="commercial_partner_id" invisible="1"/>
<field name="commercial_partner_id" invisible="1" />
<div class="oe_grey">
<div>You can force and delivery and invoice address for this contacts.</div>
<div>If you keep empty this fields the Odoo's behavior will be normal</div>
<div
>You can force and delivery and invoice address for this contacts.</div>
<div
>If you keep empty this fields the Odoo's behavior will be normal</div>
</div>
</group>
<group colspan="4">
<group>
<field name="partner_delivery_id" domain="[('id', 'child_of', commercial_partner_id)]"/>
<field
name="partner_delivery_id"
domain="[('id', 'child_of', commercial_partner_id)]"
/>
</group>
<group>
<field name="partner_invoice_id" domain="[('id', 'child_of', commercial_partner_id)]"/>
<field
name="partner_invoice_id"
domain="[('id', 'child_of', commercial_partner_id)]"
/>
</group>
</group>
</group>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save