from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.addons.point_of_sale.tests.test_generic_localization import TestGenericLocalization
from odoo.tests import tagged


@tagged('post_install', '-at_install', 'post_install_l10n')
class TestGenericGCC(TestGenericLocalization):
    @classmethod
    @AccountTestInvoicingCommon.setup_country('sa')
    def setUpClass(cls):
        super().setUpClass()
        if cls.env['ir.module.module']._get('l10n_sa_edi').state == 'installed':
            cls.skipTest(cls, "l10n_sa_edi should not be installed")
        cls.main_pos_config.company_id.name = 'Generic GCC'
        cls.company.write({
            'email': 'info@company.saexample.com',
            'phone': '+966 51 234 5678',
            'street2': 'Testomania',
            'vat': '311111111111113',
            'state_id': cls.env['res.country.state'].create({
                'name': 'Riyadh',
                'code': 'RYA',
                'country_id': cls.company.country_id.id
            }),
            'street': 'Al Amir Mohammed Bin '
            'Abdul Aziz Street',
            'city': 'المدينة المنورة',
            'zip': '42317',
        })

    def test_generic_localization(self):
        self.main_pos_config.l10n_gcc_dual_language_receipt = True
        self.main_pos_config.cash_rounding = True
        self.main_pos_config.rounding_method = self.env['account.cash.rounding'].create({
            'name': 'Test rounding',
            'rounding': 0.05,
            'rounding_method': 'UP',
            'profit_account_id': self.company_data['default_account_revenue'].id,
            'loss_account_id': self.company_data['default_account_expense'].id,
        })
        _, html = super().test_generic_localization()
        self.assertTrue("Served by / خدم بواسطة" in html)
        self.assertTrue("Ticket / تذكرة" in html)
        self.assertTrue(" / الفاتورة الضريبية" in html)
        self.assertTrue("Subtotal / الإجمالي الفرعي" in html)
        self.assertTrue("Rounding / التقريب" in html)
        self.assertTrue("Total / اﻹجمالي" in html)
        self.assertTrue("Discount / الخصومات" in html)
        self.assertTrue("Change / الباقي" in html)
