Skip to content

Instantly share code, notes, and snippets.

View ofelix03's full-sized avatar

Felix Otoo ofelix03

View GitHub Profile
@ofelix03
ofelix03 / refactoring-simplifying-and-merging-if-conditionals.py
Created May 5, 2021 08:55
refactoring-simplifyin-and-merging-if-conditionals
if "internal_hold" in vals and vals["internal_hold"]:
vals["state"] = "internally_held"
else
vals["state"] = "draft"
@ofelix03
ofelix03 / refactoring-simplifying-and-merging-if-conditionals-using-ternary.py
Created May 5, 2021 08:57
refactoring-simplifying-and-merging-if-conditionals-using-ternary
vals['state'] = 'internally_held' if 'internal_hold' in vals and vals['internal_hold'] else 'draft'
@ofelix03
ofelix03 / extract-from-create-method-line-12-to-17.py
Created May 7, 2021 17:47
extract-from-create-method-line-12-to-17.py
if "internal_hold" in vals and vals["internal_hold"]:
vals["state"] = "internally_held"
elif "internal_hold" in vals and not vals["internal_hold"]:
vals["state"] = "draft"
else:
vals["state"] = "draft"
@ofelix03
ofelix03 / extract-from-line-19-to-63.py
Last active May 7, 2021 18:00
extract-from-line-19-to-63
if "acc_no" in vals and vals["acc_no"]:
if "branch_code" in vals:
cheques = self.search(
[
("reference", "=", vals["reference"]),
("acc_no", "=", vals["acc_no"]),
("branch_code", "=", vals["branch_code"]),
("state", "!=", "cancelled"),
]
)
@ofelix03
ofelix03 / extract-from-line-52-to-63.py
Created May 7, 2021 17:57
extract-from-line-52-to-63
cheques = self.search(
[
("reference", "=", vals["reference"]),
("acc_no", "=", vals["acc_no"]),
("state", "!=", "cancelled"),
]
)
if cheques:
raise ValidationError(
@ofelix03
ofelix03 / revised-version-of-extract-from-line-19-to-63.py
Last active May 7, 2021 18:18
revised-version-of-extract-from-line-19-to-63
cheque_exists_domain_filter = [("reference", "=", vals["reference"]), ("state", "!=", "cancelled")]
if "acc_no" in vals and vals["acc_no"]:
cheque_exists_domain_filter += [("acc_no", "=", vals["acc_no"])]
if "branch_code" in vals:
cheque_exists_domain_filter += [("branch_code", "=", vals["branch_code"])]
cheques = self.search(cheque_exists_domain_filter)
@ofelix03
ofelix03 / example-table-joins-with-on.sql
Last active September 6, 2021 07:55
Example: Table Joins With ON
SELECT ie.name "invoice_number",
pj.name "payment_journal",
apr.amount "reconciliation_amount"
FROM account_move_line iel --- invoice entry line
INNER JOIN account_move ie --- invoice entry
ON iel.move_id = ie.id
INNER JOIN account_partial_reconcile apr
ON apr.debit_move_id = iel.id
INNER JOIN account_move_line pel --- payment entry line
ON apr.credit_move_id = pel.id
@ofelix03
ofelix03 / example-table-joins-with-where-clause.sql
Created September 3, 2021 20:42
Example: Table joins with WHERE clause
SELECT ie.name "invoice_number",
pj.name "payment_journal",
apr.amount "reconciliation_amount"
FROM account_move_line iel, --- invoice entry line
account_move ie, --- invoice entry
account_partial_reconcile apr, --- partial payment
account_move_line pel, --- payment entry line
account_move pe, --- payment entry
account_journal pj --- journal
WHERE
id name gender age
1 Donetta Brody Female 24
2 Otis Revell Male 52
3 Kecia Bollman Female 43
4 Retha Cottingham Female 24
5 Jerrold Villeda Male 32
6 Tawanda Sandridge Female 22
7 Ila Shingleton Male 24
8 Jean Gruner Female 60
9 Leonard Devino Male 55
id phone_number street_address person_id
1 (770) 936-5965 60 East Hickory Drive Mokena, IL 60448 1
2 (202) 911-3723 130 East Randall Mill St. Hoffman Estates, IL 60169 2
3 (309) 589-5589 76 Fulton Ave. Wantagh, NY 11793 NULL
4 (299) 505-4199 5 S. Lake View Street Windsor, CT 06095 4
5 (572) 968-5020 464 Pilgrim Drive Menomonee Falls, WI 53051 NULL
6 (488) 466-4899 999 Winding Way Avenue Newport News, VA 23601 6
7 (391) 304-8813 501 Sheffield Street Milledgeville, GA 31061 7
8 (422) 972-4219 38 Euclid Street Bergenfield, NJ 07621 NULL
9 (542) 582-8379 62 S. Brown St. Auburn, NY 13021 NULL