Merge pull request #12107 from frappe/letter-head-disabled-and-default-validation

fix: letter head disabled and default validation issues
This commit is contained in:
mergify[bot] 2021-02-09 17:01:08 +00:00 committed by GitHub
commit 67d2c165c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import is_image
from frappe.model.document import Document
from frappe import _
class LetterHead(Document):
def before_insert(self):
@ -13,8 +14,14 @@ class LetterHead(Document):
def validate(self):
self.set_image()
if not self.is_default:
if not frappe.db.sql("""select count(*) from `tabLetter Head` where ifnull(is_default,0)=1"""):
self.validate_disabled_and_default()
def validate_disabled_and_default(self):
if self.disabled and self.is_default:
frappe.throw(_("Letter Head cannot be both disabled and default"))
if not self.is_default and not self.disabled:
if not frappe.db.exists('Letter Head', dict(is_default=1)):
self.is_default = 1
def set_image(self):