from odoo.tests.common import TransactionCase


class QuickTemplateCommon(TransactionCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.company = cls.env.company
        cls.Template = cls.env['mail.quick.template']
        cls.Category = cls.env['mail.quick.template.category']
        cls.Favorite = cls.env['mail.quick.template.favorite']
        cls.Log = cls.env['mail.quick.template.log']

        cls.category = cls.Category.create({
            'name': 'General',
            'sequence': 10,
        })
        cls.model_partner = cls.env['ir.model']._get('res.partner')

        # A manager user and a plain user for permission tests.
        cls.manager = cls.env['res.users'].create({
            'name': 'Template Manager',
            'login': 'mqt_manager',
            'email': 'mqt_manager@example.com',
            'group_ids': [(6, 0, [
                cls.env.ref('base.group_user').id,
                cls.env.ref('do_mail_quick_templates.group_template_manager').id,
            ])],
        })
        cls.user = cls.env['res.users'].create({
            'name': 'Template User',
            'login': 'mqt_user',
            'email': 'mqt_user@example.com',
            'group_ids': [(6, 0, [cls.env.ref('base.group_user').id])],
        })

    def _make_template(self, **vals):
        values = {
            'name': 'Hello',
            'category_id': self.category.id,
            'body_html': '<p>Hello world</p>',
        }
        values.update(vals)
        return self.Template.create(values)
