Created
May 3, 2021 22:48
-
-
Save ofelix03/f607ea9f96e3e3ff35fe2d577d1dd6fd to your computer and use it in GitHub Desktop.
code-with-complexity-issues-refactored
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @api.model | |
| def create(self, vals): | |
| if "amount" not in vals: | |
| raise ValidationError(_("Cheque amount must be provided")) | |
| if "amount" in vals and vals["amount"] <= 0: | |
| raise ValidationError(_("Cheque amount must be greater than zero")) | |
| if "special_clearing" in vals and vals["special_clearing"]: | |
| vals["special_note"] = "Special Clearing" | |
| if "internal_hold" in vals and vals["internal_hold"]: | |
| vals["state"] = "internally_held" | |
| else: | |
| vals["state"] = "draft" | |
| 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) | |
| if cheques: | |
| raise ValidationError(_("This cheque/slip has already been recorded")) | |
| if ( | |
| "branch_code" in vals | |
| and not self._model_partner_cheque_account().cheque_account_exists( | |
| account_number=vals["acc_no"], branch_id=vals["branch"] | |
| ) | |
| ): | |
| self._model_partner_cheque_account().create_cheque_account( | |
| partner_id=vals["partner"], | |
| branch_id=vals["branch"], | |
| currency_id=vals["currency_id"], | |
| account_number=vals["acc_no"], | |
| ) | |
| return super(QuantumCheque, self).create(vals) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment