Skip to content

[IMP] academic_split_name: update firstname and lastname fields to in… #269

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

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
2 changes: 1 addition & 1 deletion academic_split_name/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Academic Split Name",
"version": "18.0.1.0.0",
"version": "18.0.1.1.0",
"sequence": 14,
"summary": "",
"author": "ADHOC SA",
Expand Down
18 changes: 16 additions & 2 deletions academic_split_name/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,27 @@ class ResPartner(models.Model):
store=True,
readonly=False,
)
firstname = fields.Char("Primer Nombre")
firstname = fields.Char("Primer Nombre", compute="_compute_firstname", store=True, readonly=False)
middlename = fields.Char("Segundo Nombre")
lastname = fields.Char("Primer Apellido")
lastname = fields.Char("Primer Apellido", compute="_compute_lastname", store=True, readonly=False)
second_lastname = fields.Char("Segundo Apellido")

@api.depends("firstname", "lastname", "second_lastname", "middlename")
def _compute_name(self):
for rec in self.filtered(lambda x: x.partner_type in ("student", "family", "parent")):
name_parts = filter(None, [rec.firstname, rec.middlename, rec.lastname, rec.second_lastname])
rec.name = " ".join(name_parts)

@api.depends("name")
def _compute_firstname(self):
for rec in self.filtered(lambda x: x.partner_type in ("student", "parent")):
parts = (rec.name or "").strip().split()
rec.firstname = parts[0] if parts else False

@api.depends("name")
def _compute_lastname(self):
for rec in self.filtered(lambda x: x.partner_type == "family"):
rec.lastname = rec.name or False
for rec in self.filtered(lambda x: x.partner_type in ("student", "parent")):
parts = (rec.name or "").strip().split()
rec.lastname = " ".join(parts[1:]) if len(parts) > 1 else False