Пример #1
0
    def test_source_change_cleanup(self):
        journal = self.AccountJournal.create({
            "name": "Bank",
            "type": "bank",
            "code": "BANK"
        })
        with common.Form(journal) as journal_form:
            journal_form.bank_statements_source = "online"
            journal_form.online_bank_statement_provider = "dummy"
        journal_form.save()

        self.assertTrue(journal.online_bank_statement_provider_id)
        save_provider_id = journal.online_bank_statement_provider_id.id

        # Stuff should not change when doing unrelated write.
        journal.write({"code": "BIGBANK"})
        self.assertTrue(journal.online_bank_statement_provider_id)
        self.assertEqual(journal.online_bank_statement_provider_id.id,
                         save_provider_id)

        with common.Form(journal) as journal_form:
            journal_form.bank_statements_source = "undefined"
        journal_form.save()

        self.assertFalse(journal.online_bank_statement_provider_id)
        self.assertFalse(
            self.OnlineBankStatementProvider.search([
                ("id", "=", save_provider_id),
            ]))
Пример #2
0
    def test_onchange(self):
        # check computations of 'bar' (readonly) and 'baz' (editable)
        form = common.Form(self.env['test_new_api.compute.onchange'])
        self.assertEqual(form.bar, "r")
        self.assertEqual(form.baz, False)
        form.active = True
        self.assertEqual(form.bar, "r")
        self.assertEqual(form.baz, "z")
        form.foo = "foo1"
        self.assertEqual(form.bar, "foo1r")
        self.assertEqual(form.baz, "foo1z")
        form.baz = "baz2"
        self.assertEqual(form.bar, "foo1r")
        self.assertEqual(form.baz, "baz2")
        form.active = False
        self.assertEqual(form.bar, "foo1r")
        self.assertEqual(form.baz, "baz2")
        form.foo = "foo3"
        self.assertEqual(form.bar, "foo3r")
        self.assertEqual(form.baz, "baz2")
        form.active = True
        self.assertEqual(form.bar, "foo3r")
        self.assertEqual(form.baz, "foo3z")

        with form.line_ids.new() as line:
            # check computation of 'bar' (readonly)
            self.assertEqual(line.foo, False)
            self.assertEqual(line.bar, "r")
            line.foo = "foo"
            self.assertEqual(line.foo, "foo")
            self.assertEqual(line.bar, "foor")

        record = form.save()
        self.assertEqual(record.bar, "foo3r")
        self.assertEqual(record.baz, "foo3z")

        form = common.Form(record)
        self.assertEqual(form.bar, "foo3r")
        self.assertEqual(form.baz, "foo3z")
        form.foo = "foo4"
        self.assertEqual(form.bar, "foo4r")
        self.assertEqual(form.baz, "foo4z")
        form.baz = "baz5"
        self.assertEqual(form.bar, "foo4r")
        self.assertEqual(form.baz, "baz5")
        form.active = False
        self.assertEqual(form.bar, "foo4r")
        self.assertEqual(form.baz, "baz5")
        form.foo = "foo6"
        self.assertEqual(form.bar, "foo6r")
        self.assertEqual(form.baz, "baz5")
Пример #3
0
    def test_journal_type_change(self):
        self.assertTrue(self.sale_journal.check_chronology)

        with common.Form(self.sale_journal) as form:
            form.type = "general"
        self.assertFalse(self.sale_journal.check_chronology)

        with common.Form(self.sale_journal) as form:
            form.type = "sale"
        self.assertFalse(self.sale_journal.check_chronology)

        with common.Form(self.sale_journal) as form:
            form.check_chronology = True
        self.assertTrue(self.sale_journal.check_chronology)
Пример #4
0
    def test_attendance_hourly(self):
        payslip_form = common.Form(self.env['hr.payslip'])
        payslip_form.date_from = '2020-01-06'
        payslip_form.date_to = '2020-01-19'
        payslip_form.employee_id = self.employee
        self.payslip = payslip_form.save()
        self.assertTrue(self.payslip.contract_id, 'No auto-discovered contract!')
        self.payslip.compute_sheet()
        # 58.97 => 40hr regular, 18.97hr OT
        # 68.4  => 40hr regular, 28.4hr  OT
        # (80 * 21.50) + (47.37 * 21.50 * 1.5) = 3247.6825
        cats = self._getCategories()
        self.assertAlmostEqual(cats['BASIC'], 3247.68, 2)

        # ensure unlink behavior.
        self.payslip.attendance_ids = self.env['hr.attendance'].browse()
        self.payslip.state = 'draft'
        self.payslip.flush()
        self.payslip._onchange_employee()
        self.payslip.compute_sheet()
        cats = self._getCategories()
        self.assertAlmostEqual(cats['BASIC'], 3247.68, 2)

        self.payslip.write({'attendance_ids': [(5, 0, 0)]})
        self.payslip.state = 'draft'
        self.payslip.flush()
        self.payslip._onchange_employee()
        self.payslip.compute_sheet()
        cats = self._getCategories()
        self.assertAlmostEqual(cats['BASIC'], 3247.68, 2)
Пример #5
0
    def test_currency_revaluation_field(self):
        with common.Form(self.AccountAccount,
                         view='account.view_account_form') as form:
            form.name = 'Test Account'
            form.company_id = self.company
            form.code = 'TEST'
            form.user_type_id = self.account_type_current_liabilities
            account = form.save()

        self.assertFalse(account.currency_revaluation)

        with common.Form(account, view='account.view_account_form') as form:
            form.user_type_id = self.account_type_liquidity
            account = form.save()

        self.assertTrue(account.currency_revaluation)
Пример #6
0
    def setUpClass(cls):
        super().setUpClass()

        cls.company = cls.env.ref("base.main_company")
        cls.partner_2 = cls.env.ref("base.res_partner_2")
        cls.today = fields.Date.today()
        cls.yesterday = cls.today - timedelta(days=1)
        cls.tomorrow = cls.today + timedelta(days=1)

        cls.AccountJournal = cls.env["account.journal"]
        cls.sale_journal = cls.AccountJournal.create(
            {
                "name": "Sale journal",
                "code": "SALE",
                "type": "sale",
                "check_chronology": True,
            }
        )

        cls.ProductProduct = cls.env["product.product"]
        cls.product = cls.ProductProduct.create({"name": "Product"})

        cls.AccountMove = cls.env["account.move"]
        with common.Form(
            cls.AccountMove.with_context(default_move_type="out_invoice")
        ) as invoice_form:
            invoice_form.invoice_date = cls.today
            invoice_form.partner_id = cls.partner_2
            invoice_form.journal_id = cls.sale_journal
            with invoice_form.invoice_line_ids.new() as line_form:
                line_form.product_id = cls.product
            cls.invoice_1 = invoice_form.save()
        cls.invoice_2 = cls.invoice_1.copy()

        cls.AccountMoveReversal = cls.env["account.move.reversal"]
Пример #7
0
    def test_onchange_one2many(self):
        record = self.env['test_new_api.model_parent_m2o'].create({
            'name': 'Family',
            'child_ids': [
                (0, 0, {'name': 'W', 'cost': 10}),
                (0, 0, {'name': 'X', 'cost': 10}),
                (0, 0, {'name': 'Y'}),
                (0, 0, {'name': 'Z'}),
            ],
        })
        record.flush()
        self.assertEqual(record.child_ids.mapped('name'), list('WXYZ'))
        self.assertEqual(record.cost, 22)

        # modifying a line should not recompute the cost on other lines
        with common.Form(record) as form:
            with form.child_ids.edit(1) as line:
                line.name = 'XXX'
            self.assertEqual(form.cost, 15)

            with form.child_ids.edit(1) as line:
                line.cost = 20
            self.assertEqual(form.cost, 32)

            with form.child_ids.edit(2) as line:
                line.cost = 30
            self.assertEqual(form.cost, 61)
Пример #8
0
 def test_onchange_default(self):
     form = common.Form(self.env['test_new_api.compute.onchange'].with_context(
         default_active=True, default_foo="foo", default_baz="baz",
     ))
     # 'baz' is computed editable, so when given a default value it should
     # 'not be recomputed, even if a dependency also has a default value
     self.assertEqual(form.foo, "foo")
     self.assertEqual(form.bar, "foor")
     self.assertEqual(form.baz, "baz")
Пример #9
0
    def test_source_change_cleanup(self):
        journal = self.AccountJournal.create({
            'name': 'Bank',
            'type': 'bank',
            'code': 'BANK',
        })
        with common.Form(journal) as journal_form:
            journal_form.bank_statements_source = 'online'
            journal_form.online_bank_statement_provider = 'dummy'
        journal_form.save()

        self.assertTrue(journal.online_bank_statement_provider_id)

        with common.Form(journal) as journal_form:
            journal_form.bank_statements_source = 'undefined'
        journal_form.save()

        self.assertFalse(journal.online_bank_statement_provider_id)
        self.assertFalse(self.OnlineBankStatementProvider.search([]))
Пример #10
0
 def test_translated_description(self):
     """PO description rendered in supplier lang."""
     self.env["res.lang"].load_lang("es_ES")
     self.order.partner_id.lang = "es_ES"
     self.product.with_context(
         lang="es_ES"
     ).description_purchase = "descripción para compras"
     with common.Form(self.order.sudo(self.test_user)) as order:
         with order.order_line.new() as line:
             line.product_id = self.product
             self.assertEqual(line.name, "descripción para compras")
Пример #11
0
    def test_02_onchange_vat(self, _check_vies):
        """Retrieve company data from VIES when VAT is valid.

        Case: no address included.
        """
        with common.Form(self.ResPartner) as partner:
            partner.is_company = True
            partner.vat = 'LT123456'
            self.assertEqual(partner.name, 'P1')
            self.assertEqual(partner.country_id, self.country_lt)
            self.assertFalse(partner.street)
Пример #12
0
 def test_03_onchange_vat(self, _check_vies):
     """Retrieve company data from VIES when VAT is invalid."""
     # ResPartner = self.ResPartner.with_context(no_vat_validation=True)
     with self.assertRaises(ValidationError):
         with common.Form(self.ResPartner) as partner:
             partner.is_company = True
             # Passing valid VAT, to, make sure patch forced
             # valid=False return_value is used.
             partner.vat = 'LT100010958410'
             partner.name = 'P1'
             self.assertEqual(partner.country_id, self.country_lt)
             self.assertFalse(partner.street)
Пример #13
0
 def test_import_statement_mapping_en(self):
     with common.Form(
             self.AccountBankStatementImportPayPalMappingWizard) as form:
         form.filename = 'fixtures/statement_en.csv'
         form.data_file = self._data_file('fixtures/statement_en.csv')
         self.assertEqual(
             len(
                 self.AccountBankStatementImportPayPalMappingWizard.
                 with_context(header=form.header, ).statement_columns()),
             18)
         wizard = form.save()
     wizard.import_mapping()
Пример #14
0
 def test_onchange_one2many_first(self):
     partner = self.env['res.partner'].create({
         'name': 'X',
         'country_id': self.env.ref('base.be').id,
     })
     with common.Form(self.env['test_new_api.multi']) as form:
         form.partner = partner
         self.assertEqual(form.partner, partner)
         self.assertEqual(form.name, partner.name)
         with form.lines.new() as line:
             # the first onchange() must have computed partner
             self.assertEqual(line.partner, partner)
Пример #15
0
    def test_update_public_key(self):
        journal = self.AccountJournal.create({
            'name':
            'Bank',
            'type':
            'bank',
            'code':
            'BANK',
            'currency_id':
            self.currency_eur.id,
            'bank_statements_source':
            'online',
            'online_bank_statement_provider':
            'transferwise',
        })

        provider = journal.online_bank_statement_provider_id
        provider.origin = '1234567891'
        provider.password = '******'

        with common.Form(provider) as provider_form:
            provider_form.certificate_private_key = """
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAxC7aYWigCwPIB4mfyLpsALYPnqDm3/IC8I/3GdEwfK8eqXoF
sU1BHnVytFycBDEObmJ2Acpxe8Dk61FnbWPrrl6rXVnXfIRqfFl94TvgwFsuwG7u
8crncD6gPfe1QGkEykHcfBURr74OcSE8590ngNJcKMGvac0cuyZ2/NEszTw7EFJg
obpMWjp0m5ItgZ/UNsPLR/D4gFE9vZz7a4+FYQMa9Wbv+xaVxUS6z9rQCJfUQx7N
iih4etIvAafbfAnX6rFv8PwPzz+XvexPWWJxnbS4iV1LN2atrPDxqw73g5hc3W88
a0V2AVubtxhw9L2VK1VmRb/gnqsZpRXhDPSUIwIDAQABAoIBAQCMvnRLV80hudfC
mJh6YEvlgrfX/OVFmpFDVnVXHz2i5dugiHsXBS6HlIjzHlGLrEoHJTo19K/PscZJ
kEAcOYg2s5JLSY4PtcvTZDyr3tJSDdiPk8Z2zzOU0kkRy+lLyUv3cqKknlTu+PHR
daAFVCLoB4K4dqPKyq0nEuRgYgy7O42SPBY5DHgWYBKqkYGlTu+ImwpDD9unbv3e
mwvdcBCp9hAlYAArc1Ip/6aUkZdKxJYgVhovruaH309yuOmBfAEgguhsy3vR18t5
IZXbAF3C6iXCQXi8l+S1NUu8XWPLEavldb+ZA2hI2L+NPSBVIYqhI4jDiI7lfs1c
HE8BRsRpAoGBAO6BnK3qD8sRvg6JsrBhppoIGsudOdpZ/KVp9ZpYCBJNJmfrkqLR
bWx1KF2UjAoYUmaKDTS2GP8JQd7X2n4T5LX8q+7iG9/wzdSWZYZuBOnjvWlNyJu4
OiUKX4aEgdvZHiuEIin5xTP98/c5LTZXwM3bq8IrOXEz8LBLLPrTCGRvAoGBANKS
i3cn1jtVirJWbvhSIjjqhpfuZN0361FB6j1Aho+7z0WVd4NQjPQqA6cAqnWoa/kj
cX0X8Ncu5eHqf6CuW+HsQda3yp3bvCXi1Yc2nKBTHnWtMm721O4ZW6rbaALzBZYW
qeJr0m9pNlfCAL0INTcy7IVAtqcCJ/7CEN6Hjm2NAoGAIGSgKArDLFxziLvw9f29
R+xT31WyVtKj+r9iaR0Ns5ag4bpgBxcUmodq/RLA1lopTt3vHzqgOHtEZATDGx6O
kJ0JqP8ys/6bpgTrMw/cQPv6bMPwvB2QYBmBkd6LWJWrgFOI5FSVEROrv+cXGetf
N1ZfhJakTZi1VuxO5p4k5KcCgYAZS9OHR/jbfeZAkFOabzt/POVYYSIq1SnmxBVg
sFy57aTzxgXqd4XHWzi/GjxgEBCQiGp8zaB4KUEih6o3YlrVZC1wnvmvRxNuNbbT
HINqWzHgjyLs46gmxlMVzm/LUuiL5EMaWTuZeLk3h63RB6hk7jAtvd1zaLXnS+b8
5Kn+jQKBgQCDeMO6rvB2rbfqSbHvPPuTru1sPIsJBKm1YZpXTFI+VMjwtk7+meYb
UQnfZ1t5rjp9q4LEcRYuSa+PfifIkM6p+wMHVQhtltUCzXWWRYkLkmQrBWKu+qiP
edF6byMgXSzgOWYuRPXwmHpBQV0GiexQUAxVyUzaVWfil69LaFfXaw==
-----END RSA PRIVATE KEY-----
            """

        self.assertTrue(provider.certificate_public_key)
Пример #16
0
    def test_01_onchange_vat(self, _check_vies):
        """Retrieve company data from VIES when VAT is valid.

        Case: name and address included.
        """
        with common.Form(self.ResPartner) as partner:
            partner.is_company = True  # to trigger VIES in constraint
            partner.name = 'P2'
            partner.vat = 'LT123456'
            # Onchange must not replace already entered data.
            self.assertEqual(partner.name, 'P2')
            self.assertEqual(partner.country_id, self.country_lt)
            self.assertEqual(partner.street, 'Street 1')
Пример #17
0
 def test_import_activity_mapping_en(self):
     with common.Form(
             self.AccountStatementImportPayPalMappingWizard) as form:
         form.filename = "fixtures/activity_en.csv"
         form.data_file = self._data_file("fixtures/activity_en.csv")
         self.assertEqual(
             len(
                 self.AccountStatementImportPayPalMappingWizard.
                 with_context(header=form.header, ).statement_columns()),
             22,
         )
         wizard = form.save()
     wizard.import_mapping()
Пример #18
0
    def test_provider_unlink_restricted(self):
        journal = self.AccountJournal.create({
            'name': 'Bank',
            'type': 'bank',
            'code': 'BANK',
        })
        with common.Form(journal) as journal_form:
            journal_form.bank_statements_source = 'online'
            journal_form.online_bank_statement_provider = 'dummy'
        journal_form.save()

        with self.assertRaises(IntegrityError), mute_logger('odoo.sql_db'):
            journal.online_bank_statement_provider_id.unlink()
Пример #19
0
    def test_provider_unlink_restricted(self):
        journal = self.AccountJournal.create({
            "name": "Bank",
            "type": "bank",
            "code": "BANK"
        })
        with common.Form(journal) as journal_form:
            journal_form.bank_statements_source = "online"
            journal_form.online_bank_statement_provider = "dummy"
        journal_form.save()

        with self.assertRaises(IntegrityError), mute_logger("odoo.sql_db"):
            journal.online_bank_statement_provider_id.unlink()
Пример #20
0
    def test_onchange(self):
        form = common.Form(self.env['test_new_api.compute.onchange'])
        form.active = True
        form.foo = "foo1"
        self.assertEqual(form.bar, "foo1")
        self.assertEqual(form.baz, "foo1")
        form.baz = "baz2"
        self.assertEqual(form.bar, "foo1")
        self.assertEqual(form.baz, "baz2")
        form.active = False
        self.assertEqual(form.bar, "foo1")
        self.assertEqual(form.baz, "baz2")
        form.foo = "foo3"
        self.assertEqual(form.bar, "foo3")
        self.assertEqual(form.baz, "baz2")
        form.active = True
        self.assertEqual(form.bar, "foo3")
        self.assertEqual(form.baz, "foo3")

        record = form.save()
        self.assertEqual(record.bar, "foo3")
        self.assertEqual(record.baz, "foo3")

        form = common.Form(record)
        self.assertEqual(form.bar, "foo3")
        self.assertEqual(form.baz, "foo3")
        form.foo = "foo4"
        self.assertEqual(form.bar, "foo4")
        self.assertEqual(form.baz, "foo4")
        form.baz = "baz5"
        self.assertEqual(form.bar, "foo4")
        self.assertEqual(form.baz, "baz5")
        form.active = False
        self.assertEqual(form.bar, "foo4")
        self.assertEqual(form.baz, "baz5")
        form.foo = "foo6"
        self.assertEqual(form.bar, "foo6")
        self.assertEqual(form.baz, "baz5")
 def test_mapping_import_wizard_csv(self):
     with common.Form(
             self.AccountBankStatementImportSheetMappingWizard) as form:
         form.filename = 'fixtures/empty_statement_en.csv'
         form.data_file = self._data_file('fixtures/empty_statement_en.csv')
         self.assertEqual(len(form.header), 90)
         self.assertEqual(
             len(
                 self.AccountBankStatementImportSheetMappingWizard.
                 with_context(header=form.header, ).statement_columns()), 7)
         form.timestamp_column = 'Date'
         form.amount_column = 'Amount'
         wizard = form.save()
     wizard.import_mapping()
Пример #22
0
    def test_create_employee_existing_email(self):
        print("Test Create Employee from wizard started . . .")
        self.first_name = 'Test0001 Name'
        self.last_name = 'Test0001 LastName'
        self.job_title = 'QA'
        self.department_id = self.env['hr.department'].search([],limit=1).id
        self.company_id = self.env['res.company'].search([], limit=1).id
        self.relationships = self.env.ref('addon_hr_customizations.employee_relationship_1').id
        self.parent_id = self.env['hr.employee'].search([], limit=1).id
        self.personal_email = self.contact_0001.email

        rec_wiz = self.env['hr.employee.create.wizard'].create({
            'first_name': self.first_name,
            'last_name': self.last_name,
            'job_title': self.job_title,
            'department_id': self.department_id,
            'company_id': self.company_id,
            'relationships': self.relationships,
            'parent_id': self.parent_id,
            'personal_email': self.personal_email,
            'work_location': 'from_home'
        })

        self.assertEqual(rec_wiz.first_name, self.first_name)
        self.assertEqual(rec_wiz.last_name, self.last_name)
        self.assertEqual(rec_wiz.job_title, self.job_title)
        self.assertEqual(rec_wiz.department_id.id, self.department_id)
        self.assertEqual(rec_wiz.company_id.id, self.company_id)
        self.assertEqual(rec_wiz.parent_id.id, self.parent_id)
        self.assertEqual(rec_wiz.personal_email, self.personal_email)

        rec_wiz_form = common.Form(rec_wiz)
        rec_wiz_form.personal_email = self.personal_email

        # Testing On Change Values
        self.assertEqual(rec_wiz_form.country_id.id, self.contact_0001.country_id.id)
        self.assertEqual(rec_wiz_form.city, self.contact_0001.city)
        rec_wiz = rec_wiz_form.save()

        employee = rec_wiz.create_employee()
        employee = self.env['hr.employee'].browse(employee['res_id'])
        self.assertEqual(rec_wiz.contact_id.id, employee.address_home_id.id)


        print("Test Create Employee from wizard done!")
Пример #23
0
    def test_display_name(self):
        self.env['ir.ui.view'].create({
            'name':
            'test_new_api.multi.tag form view',
            'model':
            'test_new_api.multi.tag',
            'arch':
            """
                <form>
                    <field name="name"/>
                    <field name="display_name"/>
                </form>
            """,
        })

        form = common.Form(self.env['test_new_api.multi.tag'])
        self.assertEqual(form.name, False)
        self.assertEqual(form.display_name, False)
Пример #24
0
    def test_cascade_unlink(self):
        journal = self.AccountJournal.create({
            "name": "Bank",
            "type": "bank",
            "code": "BANK"
        })
        with common.Form(journal) as journal_form:
            journal_form.bank_statements_source = "online"
            journal_form.online_bank_statement_provider = "dummy"
        journal_form.save()

        self.assertTrue(journal.online_bank_statement_provider_id)
        save_provider_id = journal.online_bank_statement_provider_id.id
        journal.unlink()
        self.assertFalse(
            self.OnlineBankStatementProvider.search([
                ("id", "=", save_provider_id),
            ]))
 def _do_payment(self, invoice, amount, date):
     """
     Create Payment wizard helper function.
     Returns the transient record used.
     """
     ctx = {
         "active_ids": [invoice.id],
         "active_id": invoice.id,
         "active_model": "account.move",
     }
     PaymentWizard = self.env["account.payment.register"]
     view = "account.view_account_payment_register_form"
     with common.Form(PaymentWizard.with_context(ctx), view=view) as f:
         f.amount = amount
         f.payment_date = date
     payment = f.save()
     payment.action_create_payments()
     return payment
Пример #26
0
    def test_company_check_no_access(self):
        """ Test that company_check validates correctly the companies on
        the different records, even if the use has no access to one of the
        records, example, a private address set by an onchange
        """

        user = self.env['res.users'].create({
            'name': 'My Classic User',
            'login': '******',
            'groups_id': [(6, 0, self.env.ref('base.group_user').ids)],
        })

        with common.Form(self.env['test_new_api.model_private_address_onchange'].with_user(user)) as form:
            form.name = 'My Classic Name'
            form.company_id = self.env.user.company_id
            with self.assertRaises(AccessError):
                form.address_id.name
            form.save()
Пример #27
0
 def test_mapping_import_wizard_csv(self):
     with common.Form(
             self.AccountStatementImportSheetMappingWizard) as form:
         attachment = self.env["ir.attachment"].create({
             "name":
             "fixtures/empty_statement_en.csv",
             "datas":
             self._data_file("fixtures/empty_statement_en.csv"),
         })
         form.attachment_ids.add(attachment)
         self.assertEqual(len(form.header), 90)
         self.assertEqual(
             len(
                 self.AccountStatementImportSheetMappingWizard.with_context(
                     header=form.header, ).statement_columns()),
             7,
         )
         form.timestamp_column = "Date"
         form.amount_column = "Amount"
         wizard = form.save()
     wizard.import_mapping()
    def test_payslip_timesheet(self):
        self.assertTrue(self.contract.paid_hourly_timesheet)

        # Day 1
        self.env['account.analytic.line'].create({
            'employee_id': self.employee.id,
            'project_id': self.project.id,
            'date': '2018-01-01',
            'unit_amount': 5.0,
            'name': 'test',
        })
        self.env['account.analytic.line'].create({
            'employee_id': self.employee.id,
            'project_id': self.project.id,
            'date': '2018-01-01',
            'unit_amount': 3.0,
            'name': 'test',
        })

        # Day 2
        self.env['account.analytic.line'].create({
            'employee_id': self.employee.id,
            'project_id': self.project.id,
            'date': '2018-01-02',
            'unit_amount': 10.0,
            'name': 'test',
        })

        # Make one that should be excluded.
        self.env['account.analytic.line'].create({
            'employee_id':
            self.employee.id,
            'project_id':
            self.project.id,
            'date':
            '2017-01-01',
            'unit_amount':
            5.0,
            'name':
            'test',
            'payslip_id':
            self.payslip_dummy.id,
        })

        payslip_form = common.Form(self.env['hr.payslip'])
        payslip_form.date_from = '2018-01-01'
        payslip_form.date_to = '2018-01-31'
        payslip_form.employee_id = self.employee
        self.payslip = payslip_form.save()
        self.assertTrue(self.payslip.contract_id,
                        'No auto-discovered contract!')
        wage = self.test_hourly_wage
        self.payslip.compute_sheet()
        self.assertTrue(self.payslip.worked_days_line_ids)

        timesheet_line = self.payslip.worked_days_line_ids.filtered(
            lambda l: l.code == 'TS')
        self.assertTrue(timesheet_line)
        self.assertEqual(timesheet_line.number_of_days, 2.0)
        self.assertEqual(timesheet_line.number_of_hours, 18.0)
        self.assertEqual(timesheet_line.amount, 18.0 * wage)

        # Day 3
        self.env['account.analytic.line'].create({
            'employee_id': self.employee.id,
            'project_id': self.project.id,
            'date': '2018-01-03',
            'unit_amount': 10.0,
            'name': 'test',
        })
        # Day 4
        self.env['account.analytic.line'].create({
            'employee_id': self.employee.id,
            'project_id': self.project.id,
            'date': '2018-01-04',
            'unit_amount': 10.0,
            'name': 'test',
        })
        # Day 5
        self.env['account.analytic.line'].create({
            'employee_id': self.employee.id,
            'project_id': self.project.id,
            'date': '2018-01-05',
            'unit_amount': 10.0,
            'name': 'test',
        })
        # Day 6
        self.env['account.analytic.line'].create({
            'employee_id': self.employee.id,
            'project_id': self.project.id,
            'date': '2018-01-06',
            'unit_amount': 4.0,
            'name': 'test',
        })

        self.payslip.state = 'draft'
        self.payslip._onchange_employee()
        timesheet_line = self.payslip.worked_days_line_ids.filtered(
            lambda l: l.code == 'TS')
        timesheet_overtime_line = self.payslip.worked_days_line_ids.filtered(
            lambda l: l.code == 'TS_OT')
        self.assertTrue(timesheet_line)
        self.assertEqual(timesheet_line.number_of_days, 5.0)
        self.assertEqual(timesheet_line.number_of_hours, 40.0)
        self.assertTrue(timesheet_overtime_line)
        self.assertEqual(timesheet_overtime_line.number_of_days, 1.0)
        self.assertEqual(timesheet_overtime_line.number_of_hours, 12.0)
Пример #29
0
    def test_delivery_hibou(self):
        # Assign a new shipping account
        self.partner.shipping_account_ids = self.shipping_account

        # Assign values to new Carrier
        test_insurance_value = 600
        test_sig_req_value = 300
        test_procurement_priority = '1'
        self.carrier.automatic_insurance_value = test_insurance_value
        self.carrier.automatic_sig_req_value = test_sig_req_value
        self.carrier.procurement_priority = test_procurement_priority

        sale_order = self.env['sale.order'].create({
            'partner_id':
            self.partner.id,
            'partner_shipping_id':
            self.partner.id,
            'partner_invoice_id':
            self.partner.id,
            'shipping_account_id':
            self.shipping_account.id,
            'order_line': [(0, 0, {
                'product_id': self.product.id,
            })]
        })
        self.assertFalse(sale_order.carrier_id)
        action = sale_order.action_open_delivery_wizard()
        form = common.Form(self.env[action['res_model']].with_context(
            **action.get('context', {})))
        form.carrier_id = self.carrier
        wizard = form.save()
        wizard.button_confirm()

        #sale_order.set_delivery_line()
        self.assertEqual(sale_order.carrier_id, self.carrier)
        sale_order.action_confirm()
        # Make sure 3rd party Shipping Account is set.
        self.assertEqual(sale_order.shipping_account_id, self.shipping_account)

        self.assertTrue(sale_order.picking_ids)
        # Priority coming from Carrier procurement_priority
        self.assertEqual(sale_order.picking_ids.priority,
                         test_procurement_priority)
        # 3rd party Shipping Account copied from Sale Order
        self.assertEqual(sale_order.picking_ids.shipping_account_id,
                         self.shipping_account)
        self.assertEqual(
            sale_order.carrier_id.get_third_party_account(order=sale_order),
            self.shipping_account)

        # Test attn
        test_ref = 'TEST100'
        self.assertEqual(sale_order.carrier_id.get_attn(order=sale_order),
                         False)
        sale_order.client_order_ref = test_ref
        self.assertEqual(sale_order.carrier_id.get_attn(order=sale_order),
                         test_ref)
        # The picking should get this ref as well
        self.assertEqual(
            sale_order.picking_ids.carrier_id.get_attn(
                picking=sale_order.picking_ids), test_ref)

        # Test order_name
        self.assertEqual(
            sale_order.carrier_id.get_order_name(order=sale_order),
            sale_order.name)
        # The picking should get the same 'order_name'
        self.assertEqual(
            sale_order.picking_ids.carrier_id.get_order_name(
                picking=sale_order.picking_ids), sale_order.name)
Пример #30
0
    def setUp(self):
        super(TestVATReport, self).setUp()
        self.date_from = time.strftime("%Y-%m-01")
        self.date_to = time.strftime("%Y-%m-28")
        self.company = self.env.ref("base.main_company")
        self.receivable_account = self.env["account.account"].search(
            [
                ("company_id", "=", self.company.id),
                ("user_type_id.name", "=", "Receivable"),
            ],
            limit=1,
        )
        self.income_account = self.env["account.account"].search(
            [
                ("company_id", "=", self.company.id),
                ("user_type_id.name", "=", "Income"),
            ],
            limit=1,
        )
        self.tax_account = self.env["account.account"].search(
            [
                ("company_id", "=", self.company.id),
                (
                    "user_type_id",
                    "=",
                    self.env.ref(
                        "account.data_account_type_non_current_liabilities"
                    ).id,
                ),
            ],
            limit=1,
        )
        self.bank_journal = self.env["account.journal"].search(
            [("type", "=", "bank"), ("company_id", "=", self.company.id)], limit=1
        )
        self.tax_tag_01 = self.env["account.account.tag"].create(
            {
                "name": "Tag 01",
                "applicability": "taxes",
                "country_id": self.company.country_id.id,
            }
        )
        self.tax_tag_02 = self.env["account.account.tag"].create(
            {
                "name": "Tag 02",
                "applicability": "taxes",
                "country_id": self.company.country_id.id,
            }
        )
        self.tax_tag_03 = self.env["account.account.tag"].create(
            {
                "name": "Tag 03",
                "applicability": "taxes",
                "country_id": self.company.country_id.id,
            }
        )
        self.tax_group_10 = self.env["account.tax.group"].create(
            {"name": "Tax 10%", "sequence": 1}
        )
        self.tax_group_20 = self.env["account.tax.group"].create(
            {"name": "Tax 20%", "sequence": 2}
        )
        self.tax_10 = self.env["account.tax"].create(
            {
                "name": "Tax 10.0%",
                "amount": 10.0,
                "amount_type": "percent",
                "type_tax_use": "sale",
                "company_id": self.company.id,
                "tax_group_id": self.tax_group_10.id,
                "invoice_repartition_line_ids": [
                    (0, 0, {"factor_percent": 100, "repartition_type": "base"}),
                    (
                        0,
                        0,
                        {
                            "factor_percent": 100,
                            "repartition_type": "tax",
                            "account_id": self.tax_account.id,
                            "tag_ids": [
                                (6, 0, [self.tax_tag_01.id, self.tax_tag_02.id])
                            ],
                        },
                    ),
                ],
                "refund_repartition_line_ids": [
                    (0, 0, {"factor_percent": 100, "repartition_type": "base"}),
                    (
                        0,
                        0,
                        {
                            "factor_percent": 100,
                            "repartition_type": "tax",
                            "account_id": self.tax_account.id,
                        },
                    ),
                ],
            }
        )
        self.tax_20 = self.env["account.tax"].create(
            {
                "sequence": 30,
                "name": "Tax 20.0%",
                "amount": 20.0,
                "amount_type": "percent",
                "type_tax_use": "sale",
                "company_id": self.company.id,
                "cash_basis_transition_account_id": self.tax_account.id,
                "tax_group_id": self.tax_group_20.id,
                "invoice_repartition_line_ids": [
                    (0, 0, {"factor_percent": 100, "repartition_type": "base"}),
                    (
                        0,
                        0,
                        {
                            "factor_percent": 100,
                            "repartition_type": "tax",
                            "account_id": self.tax_account.id,
                            "tag_ids": [
                                (6, 0, [self.tax_tag_02.id, self.tax_tag_03.id])
                            ],
                        },
                    ),
                ],
                "refund_repartition_line_ids": [
                    (0, 0, {"factor_percent": 100, "repartition_type": "base"}),
                    (
                        0,
                        0,
                        {
                            "factor_percent": 100,
                            "repartition_type": "tax",
                            "account_id": self.tax_account.id,
                        },
                    ),
                ],
            }
        )

        move_form = common.Form(
            self.env["account.move"].with_context(default_type="out_invoice")
        )
        move_form.partner_id = self.env.ref("base.res_partner_2")
        move_form.invoice_date = time.strftime("%Y-%m-03")
        with move_form.invoice_line_ids.new() as line_form:
            line_form.product_id = self.env.ref("product.product_product_4")
            line_form.quantity = 1.0
            line_form.price_unit = 100.0
            line_form.account_id = self.income_account
            line_form.tax_ids.add(self.tax_10)
        invoice = move_form.save()
        invoice.post()

        move_form = common.Form(
            self.env["account.move"].with_context(default_type="out_invoice")
        )
        move_form.partner_id = self.env.ref("base.res_partner_2")
        move_form.invoice_date = time.strftime("%Y-%m-04")
        with move_form.invoice_line_ids.new() as line_form:
            line_form.product_id = self.env.ref("product.product_product_4")
            line_form.quantity = 1.0
            line_form.price_unit = 250.0
            line_form.account_id = self.income_account
            line_form.tax_ids.add(self.tax_20)
        invoice = move_form.save()
        invoice.post()