-
-
Notifications
You must be signed in to change notification settings - Fork 851
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
[14.0][ADD] partner_kind #1531
Conversation
There was a problem hiding this 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" |
There was a problem hiding this comment.
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")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we ll do together
partner_kind/models/res_partner.py
Outdated
("company", "Company"), | ||
] | ||
|
||
@api.depends("user_ids", "parent_id", "company_type") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@api.depends("user_ids", "parent_id", "company_type") | |
@api.depends("user_ids", "parent_id", "is_company") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
partner_kind/models/res_partner.py
Outdated
def _compute_kind(self): | ||
|
||
for rec in self.with_context(active_test=False): | ||
if rec.user_ids: |
There was a problem hiding this comment.
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:
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
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
partner_kind/models/res_partner.py
Outdated
rec.kind = "user" | ||
elif rec.parent_id: | ||
rec.kind = "address" | ||
elif rec.is_company is True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elif rec.is_company is True: | |
elif rec.is_company: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
partner_kind/models/res_partner.py
Outdated
elif rec.is_company is True: | ||
if not rec.parent_id: | ||
rec.kind = "company" | ||
elif rec.is_company is False: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elif rec.is_company is False: | |
elif not rec.is_company: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
partner_kind/models/res_partner.py
Outdated
for rec in self.with_context(active_test=False): | ||
if rec.kind == "user" and not rec.user_ids: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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")): |
partner_kind/models/res_partner.py
Outdated
elif rec.parent_id: | ||
rec.kind = "address" | ||
elif rec.is_company is True: | ||
if not rec.parent_id: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not rec.parent_id: |
also tested above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
partner_kind/readme/DESCRIPTION.rst
Outdated
- 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
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.
partner_kind/models/res_partner.py
Outdated
if not rec.parent_id: | ||
rec.kind = "company" | ||
elif rec.is_company is False: | ||
if not rec.user_ids: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not rec.user_ids: |
Already tested above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
partner_kind/readme/DESCRIPTION.rst
Outdated
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
partner_kind/models/res_partner.py
Outdated
def _compute_kind(self): | ||
|
||
for rec in self: | ||
if rec.kind == "user" and not any(rec.user_ids.mapped("active")): |
There was a problem hiding this comment.
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"] | ||
|
There was a problem hiding this comment.
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()
elif rec.is_company: | ||
rec.kind = "company" | ||
elif not rec.is_company: | ||
rec.kind = "person" |
There was a problem hiding this comment.
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 ;)
e7109a7
to
549cdda
Compare
@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. |
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. |
@sebastienbeau
Here the partner_kind module to be able to select a type de partner.