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

[14.0][ADD] partner_kind #1531

Closed
wants to merge 1 commit into from
Closed

[14.0][ADD] partner_kind #1531

wants to merge 1 commit into from

Conversation

syera94
Copy link

@syera94 syera94 commented May 31, 2023

@sebastienbeau

Here the partner_kind module to be able to select a type de partner.

Copy link

@Kev-Roche Kev-Roche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!
Please rename the PR with the version number : [14.0][ADD] partner_kind
And add the readme authors part with you and @sebastienbeau in it.

#: model_terms:ir.ui.view,arch_db:partner_kind.view_partner_form
#: model_terms:ir.ui.view,arch_db:partner_kind.view_res_partner_filter
msgid "kind"
msgstr "Type"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The French translation need to be updated (for exemple "Individual", "Company")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we ll do together

("company", "Company"),
]

@api.depends("user_ids", "parent_id", "company_type")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@api.depends("user_ids", "parent_id", "company_type")
@api.depends("user_ids", "parent_id", "is_company")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment on lines 33 to 50
def _compute_kind(self):

for rec in self.with_context(active_test=False):
if rec.user_ids:
Copy link

@Kev-Roche Kev-Roche Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With context active_test=False, the kind of an active partner will stay as "user" even if the related res.user was archived.
I recommend the following:

Suggested change
def _compute_kind(self):
for rec in self.with_context(active_test=False):
if rec.user_ids:
def _compute_kind(self):
for rec in self:
if any(rec.user_ids.mapped("active")):

also add "user_ids.active" in @api.depends

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need both user_ids and user_ids.active

rec.kind = "user"
elif rec.parent_id:
rec.kind = "address"
elif rec.is_company is True:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
elif rec.is_company is True:
elif rec.is_company:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

elif rec.is_company is True:
if not rec.parent_id:
rec.kind = "company"
elif rec.is_company is False:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
elif rec.is_company is False:
elif not rec.is_company:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment on lines 51 to 64
for rec in self.with_context(active_test=False):
if rec.kind == "user" and not rec.user_ids:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for rec in self.with_context(active_test=False):
if rec.kind == "user" and not rec.user_ids:
for rec in self:
if rec.kind == "user" and not any(rec.user_ids.mapped("active")):

elif rec.parent_id:
rec.kind = "address"
elif rec.is_company is True:
if not rec.parent_id:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not rec.parent_id:

also tested above

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment on lines 4 to 7
- The recordset address : for the company or person linked to a parent
- the recordset user : for company internal person which cannot be concerned by the kind
- the recordset company : for the other case if it's a company
- the recordset person : as the field is required, there is a default value

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not recordset, just selection options, please change it in all the readme.
Maybe " - Address : for the company or person linked to a parent" is enough.
Also, you can use the interface term for users.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

self.Partner4 = self.env["res.partner"].create(
{
"name": "Test",
"company_type": "person",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required as it's the default kind.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only line 18 "company_type": "person", was unnecessary, you have to keep self.Partner4 and the related test.

if not rec.parent_id:
rec.kind = "company"
elif rec.is_company is False:
if not rec.user_ids:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not rec.user_ids:

Already tested above

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@syera94 syera94 changed the title [ADD] partner_kind [14.0][ADD] partner_kind Jun 16, 2023
Comment on lines 9 to 16
The way to use this module:

In the method _get_partner_kind, add the selection you need as partner kind.
Once is done,if you want to remove all of the initial recordset, you can also remove the compute field or change it to fit better to your case
if you only want to remove some of the initial recordset, you have to remove in the compute field the linked conditions
After, the same thing as to be done in a contrains.

For the tests, as they are linked to this specifiques initials recordsets, thet won't worked if you remove or change this initial recordsets.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of USAGE.srt.
I'm not sure but I think that the readme needs to describe the module itself, not the potential changes that we can do on it.

@@ -0,0 +1,16 @@
This module add kind of partner to partners.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the typos on the file

def _compute_kind(self):

for rec in self:
if rec.kind == "user" and not any(rec.user_ids.mapped("active")):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for res in self:
    rec._get_default_kind()

class ResPartner(models.Model):

_inherit = ["res.partner"]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the view hide the field "company_type"

is_company = fields.Boolean(                                    
    compute="_compute_is_company",
    compute_sudo=True,
    store=True,
)

def _get_is_company_kind(self):
    return ["company"]

@api.depends("kind")                      
def _compute_is_company(self):            
    for record in self:                   
         record.is_company =  record.kind in self._get_is_company_kind()      

Comment on lines +40 to +45
elif rec.is_company:
rec.kind = "company"
elif not rec.is_company:
rec.kind = "person"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove it if the is_company is a computed field ;)

@syera94 syera94 force-pushed the partner_kind branch 2 times, most recently from e7109a7 to 549cdda Compare June 22, 2023 10:05
@syera94
Copy link
Author

syera94 commented Jun 23, 2023

@Kev-Roche : the changes which has been modified since our conversation this morning (23/06/2023) --> as the field parent_id is linked to the field company_type, if i hide it, the field parent_id does not appear anymore.
In my opinion, it's better to let it visible.
Check and see
@sebastienbeau FYI

@github-actions
Copy link

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Oct 29, 2023
@github-actions github-actions bot closed this Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants