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

feat: link contact_person(LAN-699) (Sourcery refactored) #230

Closed
wants to merge 3 commits into from

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jun 28, 2023

Pull Request #226 refactored by Sourcery.

Since the original Pull Request was opened as a fork in a contributor's
repository, we are unable to create a Pull Request branching from it.

To incorporate these changes, you can either:

  1. Merge this Pull Request instead of the original, or

  2. Ask your contributor to locally incorporate these commits and push them to
    the original Pull Request

    Incorporate changes via command line
    git fetch https://github.com/alyf-de/landa pull/226/head
    git merge --ff-only FETCH_HEAD
    git push

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Help us improve this pull request!

frappe.delete_doc(
"User",
user,
ignore_permissions=True,
ignore_missing=True,
delete_permanently=True,
)

delete_dynamically_linked("Address", self.doctype, self.name)
delete_dynamically_linked("Contact", self.doctype, self.name)
delete_records_linked_to("LANDA Member", self.name)

self.revert_series()

def revert_series(self):
"""Decrease the naming counter when the newest member gets deleted."""
# reconstruct the key used to generate the name
number_part_len = len(self.name.split("-")[-1])
key = f"{self.name[:-number_part_len]}.{'#' * number_part_len}"
revert_series_if_last(key, self.name)
def autoname(self):
"""Generate the unique member number (name field)

Organization: AVL-001-0001, AVE-001-0001, ...
Local group: AVL-001-01-0001, AVL-001-02-0001, ...
"""
if self.name:
return
self.name = make_autoname(f"{self.organization}-.####", "LANDA Member")

def onload(self):
load_address_and_contact(self)

def validate(self):
if frappe.db.get_value("Organization", self.organization, "is_group"):
frappe.throw(
_("Cannot be a member of organization {} because it is a group.").format(
self.organization
)
)

self.full_name = get_full_name(self.first_name, self.last_name)

def on_trash(self):
current_member = get_member_and_organization(frappe.session.user)[0]
if current_member == self.name:
frappe.throw(_("You cannot delete your own member record."))

if user := frappe.db.exists("User", {"landa_member": self.name}):
Copy link
Author

Choose a reason for hiding this comment

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

Function LANDAMember.on_trash refactored with the following changes:

@barredterra barredterra deleted the sourcery/pull-226 branch October 19, 2023 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants