<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def query(self):
 """ Main accounts query """

        query = (
            self.book.session.query(Account)
            .join(Commodity)
            .filter(Commodity.namespace != "template")
            .filter(Account.type != AccountType.root.value)
        )
        return query