# -*- coding: utf-8 -*-
from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError, ValidationError
from datetime import datetime, timedelta


class test_cn_account_invoice(TransactionCase):
    def setUp(self):
        ''' setUp data '''
        super(test_cn_account_invoice, self).setUp()
        self.env['ir.values'].set_default('tax.config.settings',
                                          'default_goods_supplier',
                                          self.env.ref('core.supplier_category_1').id)
        self.cn_invoice = self.env['cn.account.invoice'].create({
            'type': 'in',
            'invoice_type': 'zy',
            'invoice_date': '2016-05-25',
            'invoice_code': '222222',
            'name': '888888',
            'partner_name_in': '开阖',
            'partner_code_in': '922T',
            'partner_address_in': '金海路2588B213',
            'partner_bank_number_in': '6217 8888 8888',
        })
        self.cn_invoice_line = self.env['cn.account.invoice.line'].create({
            'product_name': '玉米',
            'product_unit': '斤',
            'product_count': 1.0,
            'product_price': 2.0,
            'product_amount': 2.0,
            'product_tax_rate': 11,
            'product_tax': 0.22,
            'tax_type': '1010101030000000000',
        })
        self.cn_invoice_line.order_id = self.cn_invoice.id

    def test_action_get_attachment_view(self):
        ''' Uploading attachments of expense invoice '''
        self.cn_invoice.action_get_attachment_view()

    def test_compute_attachment_number(self):
        ''' Test: _compute_attachment_number  '''
        self.cn_invoice._compute_attachment_number()

    def test_create_buy_partner(self):
        ''' Test: create buy partner '''
        self.cn_invoice.create_buy_partner()

    def test_create_buy_partner_same_main_mobile_and_tax_num(self):
        ''' Test: create buy partner,.main_mobile, tax_num same '''
        #
        self.cn_invoice.partner_address_in = '金海路922T'
        self.cn_invoice.create_buy_partner()

        self.cn_invoice.create_buy_partner()

@@ -930,16 +930,18 @@
 r_in': '
+%E5%BB%BA%E8%A1%8C
 6217 888
@@ -2099,28 +2099,1122 @@
 nvoice.create_buy_partner()%0A
+%0A    def test_create_category(self):%0A        ''' Test: create category '''%0A        self.cn_invoice.create_category()%0A%0A    def test_create_product(self):%0A        ''' Test: create product '''%0A        # %E5%95%86%E5%93%81 uom_id %E5%BF%85%E9%A1%BB%E5%AD%98%E5%9C%A8%0A        self.cn_invoice_line.product_unit = '%E4%BB%B6'%0A        # %E5%95%86%E5%93%81 category_id %E5%BF%85%E9%A1%BB%E5%AD%98%E5%9C%A8%0A        self.cn_invoice_line.tax_type = '%E4%B8%8D%E5%BE%81%E7%A8%8E%E8%87%AA%E6%9D%A5%E6%B0%B4'%0A        self.env.ref('core.goods_category_1').tax_category_id = self.env.ref('tax.nsbm6110000000000000000').id%0A%0A        self.cn_invoice.create_product()%0A%0A    def test_create_sell_partner(self):%0A        ''' Test: create_sell_partner '''%0A        # %E5%88%9B%E5%BB%BA%E5%AE%A2%E6%88%B7%EF%BC%8C%E4%BD%86%E6%98%AF%E4%B8%8D%E5%AD%98%E5%9C%A8 %E5%AE%A2%E6%88%B7%E7%B1%BB%E5%88%AB %E6%8A%A5%E9%94%99%0A        with self.assertRaises(UserError):%0A            self.cn_invoice.create_sell_partner()%0A%0A        # %E4%B8%BB%E8%A6%81%E6%89%8B%E6%9C%BA%E5%8F%B7%E5%92%8C%E7%A8%8E%E5%8F%B7%E7%9B%B8%E5%90%8C%0A        self.env%5B'ir.values'%5D.set_default('tax.config.settings', 'default_customer',%0A                                          self.env.ref('tax.domestic_customer').id)%0A        self.cn_invoice.partner_name_out = 'kaihe'%0A        self.cn_invoice.partner_address_out = '%E9%87%91%E6%B5%B7%E8%B7%AF922T'%0A        self.cn_invoice.partner_code_out = '922T'%0A        self.cn_invoice.create_sell_partner()%0A

添加 cn_account_invoice 测试数据