Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][IMP] partner_firstname: add is_address_readonly and is_individual for more UI customizable #1890

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions partner_firstname/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ class ResPartner(models.Model):
readonly=False,
)

is_address_readonly = fields.Boolean(compute="_compute_contact_type")
is_individual = fields.Boolean(compute="_compute_contact_type")

@api.depends("is_company", "type", "parent_id")
def _compute_contact_type(self):
for partner in self:
partner.is_address_readonly = not (
partner.is_company
or not partner.parent_id
or partner.type not in ["contact"]
)
partner.is_individual = not partner.is_company and partner.type in [
"contact",
"other",
]

@api.model
def name_fields_in_vals(self, vals):
"""Method to check if any name fields are in `vals`."""
Expand Down
92 changes: 65 additions & 27 deletions partner_firstname/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_simple_form" />
<field name="arch" type="xml">
<field name="is_company" position="after">
<field name="is_individual" invisible="1" />
</field>
<xpath expr="//field[@id='individual']" position="attributes">
<attribute name="invisible">is_company</attribute>
<attribute name="readonly">not is_company</attribute>
<attribute name="required">type == 'contract' and is_company</attribute>
<attribute name="readonly">is_individual</attribute>
<attribute name="required">is_individual</attribute>
</xpath>
<xpath expr="//field[@id='company']" position="attributes">
<attribute name="invisible">is_company == False</attribute>
<attribute name="readonly">not is_company</attribute>
<attribute name="required">type == 'contract' and is_company</attribute>
<attribute name="invisible">not is_company</attribute>
<attribute name="required">is_company</attribute>
</xpath>
<xpath expr="//h1//field[@id='company']/.." position="before">
<group invisible="is_company">
<field
name="lastname"
required="not firstname and not is_company and type == 'contact'"
/>
<field
name="firstname"
required="not lastname and not is_company and type == 'contact'"
/>
<group invisible="not is_individual">
<field name="lastname" required="not firstname and is_individual" />
<field name="firstname" required="not lastname and is_individual" />
</group>
</xpath>
</field>
Expand All @@ -31,55 +27,97 @@
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="is_company" position="after">
<field name="is_individual" invisible="1" />
<field name="is_address_readonly" invisible="1" />
</field>
<xpath expr="//field[@id='individual']" position="attributes">
<attribute name="invisible">is_company</attribute>
<attribute name="readonly">not is_company</attribute>
<attribute name="required">type == 'contract' and is_company</attribute>
<attribute name="required">is_individual</attribute>
<attribute name="readonly">is_individual</attribute>
</xpath>
<xpath expr="//field[@id='company']" position="attributes">
<attribute name="invisible">not is_company</attribute>
<attribute name="readonly">not is_company</attribute>
<attribute name="required">type == 'contract' and is_company</attribute>
<attribute name="required">is_company</attribute>
</xpath>
<xpath
expr="//div[hasclass('oe_title')]//field[@id='company']/.."
position="after"
>
<div class="oe_edit_only">
<group invisible="is_company">
<group invisible="not is_individual">
<field
name="lastname"
required="not firstname and not is_company and type == 'contact'"
required="not firstname and is_individual"
/>
<field
name="firstname"
required="not lastname and not is_company and type == 'contact'"
required="not lastname and is_individual"
/>
</group>
</div>
</xpath>

<xpath
expr="//div[hasclass('o_address_format')]//field[@name='street']"
position="attributes"
>
<attribute name="readonly">is_address_readonly</attribute>
</xpath>
<xpath
expr="//div[hasclass('o_address_format')]//field[@name='street2']"
position="attributes"
>
<attribute name="readonly">is_address_readonly</attribute>
</xpath>
<xpath
expr="//div[hasclass('o_address_format')]//field[@name='city']"
position="attributes"
>
<attribute name="readonly">is_address_readonly</attribute>
</xpath>
<xpath
expr="//div[hasclass('o_address_format')]//field[@name='state_id']"
position="attributes"
>
<attribute name="readonly">is_address_readonly</attribute>
</xpath>
<xpath
expr="//div[hasclass('o_address_format')]//field[@name='zip']"
position="attributes"
>
<attribute name="readonly">is_address_readonly</attribute>
</xpath>
<xpath
expr="//div[hasclass('o_address_format')]//field[@name='country_id']"
position="attributes"
>
<attribute name="readonly">is_address_readonly</attribute>
</xpath>

<!-- Modify inner contact form of child_ids -->
<xpath
expr="//field[@name='child_ids']/form//field[@name='name']"
position="attributes"
>
<attribute name="readonly">not is_company</attribute>
<attribute name="required">is_company</attribute>
<attribute name="readonly">is_individual</attribute>
<attribute name="required">is_individual</attribute>
</xpath>
<xpath
expr="//field[@name='child_ids']/form//field[@name='name']"
position="after"
>
<div class="oe_edit_only" colspan="2">
<field name="is_company" invisible="True" />
<group invisible="is_company">
<field name="is_individual" invisible="1" />
<field name="is_company" invisible="1" />
<group invisible="not is_individual">
<field
name="lastname"
required="not firstname and not is_company and type == 'contact'"
required="not firstname and is_individual"
/>
<field
name="firstname"
required="not lastname and not is_company and type == 'contact'"
required="not lastname and is_individual"
/>
</group>
</div>
Expand Down
Loading