コード例 #1
0
    def setUp(self):
        super(TestPartnerTimeToPay, self).setUp()
        self.payment_model = self.env["account.payment"]
        self.register_payments_model = self.env["account.payment.register"]
        self.partner_id = self.env.ref("base.res_partner_1")
        self.product_id = self.env.ref("product.product_product_4")
        self.account_model = self.env["account.account"]
        self.account_move_model = self.env["account.move"]
        self.account_journal = self.env["account.journal"]
        self.payment_method_manual_in = self.env.ref(
            "account.account_payment_method_manual_in")
        self.account_receivable_id = self.env.ref(
            "account.data_account_type_receivable")
        self.account_revenue_id = self.env.ref(
            "account.data_account_type_revenue")
        self.account_revenue = self.account_model.search(
            [("user_type_id", "=", self.account_revenue_id.id)], limit=1)
        self.today = Date.from_string(Date.context_today(self.env.user))

        self.invoice_id = self.account_move_model.create({
            "partner_id":
            self.partner_id.id,
            "type":
            "out_invoice",
            "invoice_date":
            self.today,
            "invoice_line_ids": [(
                0,
                0,
                {
                    "product_id": self.product_id.id,
                    "name": self.product_id.name,
                    "price_unit": 100,
                    "quantity": 10,
                    "account_id": self.account_revenue.id,
                },
            )],
        })

        self.invoice_id._onchange_invoice_line_ids()
        self.invoice_id._onchange_recompute_dynamic_lines()
        self.invoice_id.action_post()
        self.bank_journal_euro = self.account_journal.create({
            "name": "Bank",
            "type": "bank",
            "code": "BNK67"
        })

        ctx = {
            "active_model": "account.invoice",
            "active_ids": [self.invoice_id.id]
        }
        self.register_payments = self.register_payments_model.with_context(
            ctx).create({
                "payment_date": self.today + relativedelta(days=10),
                "journal_id": self.bank_journal_euro.id,
                "payment_method_id": self.payment_method_manual_in.id,
            })
        self.register_payments.create_payments()
        self.payment = self.payment_model.search([], order="id desc", limit=1)
コード例 #2
0
    def setUp(self):
        super(TestPartnerTimeToPay, self).setUp()
        self.payment_model = self.env['account.payment']
        self.register_payments_model = self.env['account.register.payments']
        self.partner_id = self.env.ref('base.res_partner_1')
        self.product_id = self.env.ref('product.product_product_4')
        self.account_model = self.env['account.account']
        self.account_invoice_model = self.env['account.invoice']
        self.account_journal = self.env['account.journal']
        self.payment_method_manual_in =\
            self.env.ref("account.account_payment_method_manual_in")
        self.account_receivable_id =\
            self.env.ref('account.data_account_type_receivable')
        self.account_revenue_id =\
            self.env.ref('account.data_account_type_revenue')

        self.account_receivable = self.account_model.search(
            [('user_type_id', '=', self.account_receivable_id.id)], limit=1)
        self.account_revenue = self.account_model.search(
            [('user_type_id', '=', self.account_revenue_id.id)], limit=1)
        self.today = Date.from_string(Date.context_today(self.env.user))

        self.invoice_id = self.account_invoice_model.create({
            'partner_id': self.partner_id.id,
            'type': 'out_invoice',
            'account_id': self.account_receivable.id,
            'date_invoice': self.today,
            'invoice_line_ids': [(0, 0, {
                'product_id': self.product_id.id,
                'name': self.product_id.name,
                'price_unit': 100,
                'quantity': 10,
                'account_id': self.account_revenue.id,
            })]
        })

        self.invoice_id._onchange_invoice_line_ids()
        self.invoice_id._onchange_cash_rounding()
        self.invoice_id.action_invoice_open()
        self.bank_journal_euro =\
            self.account_journal.create({
                'name': 'Bank',
                'type': 'bank',
                'code': 'BNK67'
            })

        ctx = {
            'active_model': 'account.invoice',
            'active_ids': [self.invoice_id.id]
        }
        self.register_payments =\
            self.register_payments_model.with_context(ctx).create({
                'payment_date':
                    self.today + relativedelta(days=10),
                'journal_id': self.bank_journal_euro.id,
                'payment_method_id': self.payment_method_manual_in.id,
            })
        self.register_payments.create_payments()
        self.payment = self.payment_model.search([], order="id desc", limit=1)
コード例 #3
0
 def _inverse_age(self):
     today = fDate.from_string(fDate.context_today(self))
     for book in self.filtered('date_release'):
         try:
             d = today - timedelta(days=book.age_days)
             book.date_release = fDate.to_string(d)
         except (IOError, OSError) as exc:
             message = _('Unable to inverse age') % exc
             raise UserError(message)
コード例 #4
0
ファイル: library_book.py プロジェクト: rona-setyana/Library
 def _search_age(self, operator, value):
     today = fDate.from_string(fDate.context_today(self))
     value_days = timedelta(days=value)
     value_date = fDate.to_string(today - value_days)
     # convert the operator:
     # book with age > value have a date < value_date
     operator_map = {'>': '<', '>=': '<=', '<': '>', '<=': '>='}
     new_op = operator_map.get(operator, operator)
     return [('date_release', new_op, value_date)]
コード例 #5
0
    def import_with_po_wizard(self, payment_mode_id, payment_type="inbound", aml=False):
        order_vals = {
            "payment_type": payment_type,
            "payment_mode_id": payment_mode_id.id,
        }
        order = self.env["account.payment.order"].create(order_vals)
        with self.assertRaises(UserError):
            order.draft2open()
        order.payment_mode_id_change()
        self.assertEqual(order.journal_id.id, payment_mode_id.fixed_journal_id.id)
        self.assertEqual(len(order.payment_line_ids), 0)

        with self.assertRaises(UserError):
            order.draft2open()

        line_create = (
            self.env["account.payment.line.create"]
            .with_context(active_model="account.payment.order", active_id=order.id)
            .create(
                {"date_type": "move", "move_date": Date.context_today(self.env.user)}
            )
        )
        line_create.payment_mode = "same"
        line_create.move_line_filters_change()
        line_create.populate()
        line_create.create_payment_lines()
        line_created_due = (
            self.env["account.payment.line.create"]
            .with_context(active_model="account.payment.order", active_id=order.id)
            .create(
                {
                    "date_type": "due",
                    "target_move": "all",
                    "due_date": Date.context_today(self.env.user),
                }
            )
        )
        line_created_due.populate()
        line_created_due.create_payment_lines()
        self.assertGreater(len(order.payment_line_ids), 0)
        self._payment_order_all_workflow(order)
        self.assertEqual(order.state, "done")
        return order
コード例 #6
0
 def _search_age(self, operator, value):
     try:
         today = fDate.from_string(fDate.context_today(self))
         value_days = timedelta(days=value)
         value_date = fDate.to_string(today - value_days)
         operator_map = {'>': '<', '>=': '<=', '<': '>', '<=': '>=', }
         new_op = operator_map.get(operator, operator)
         return [('date_release', new_op, value_date)]
     except (IOError, OSError) as exc:
         message = _('Unable to search by age') % exc
         raise UserError(message)
コード例 #7
0
 def _search_age(self, operator, value):
     today = fDate.context_today(self)
     value_date = fDate.subtract(today, days=value)
     # convert the operator:
     # book with age > value have a date < value_date
     operator_map = {
         '>': '<',
         '>=': '<=',
         '<': '>',
         '<=': '>=',
     }
     new_op = operator_map.get(operator, operator)
     return [('date_release', new_op, value_date)]
コード例 #8
0
ファイル: test_sale_timesheet.py プロジェクト: WilldooIT/odoo
    def test_timesheet_invoice(self):
        """ Test to create invoices for the sale order with timesheets

            1) create sale order
            2) try to create an invoice for the timesheets 10 days before
            3) create invoice for the timesheets 6 days before
            4) create invoice for the timesheets 4 days before
            5) create invoice for the timesheets from today
        """
        today = Date.context_today(self.env.user)
        sale_order = self.env['sale.order'].create({
            'partner_id': self.partner_a.id,
            'partner_invoice_id': self.partner_a.id,
            'partner_shipping_id': self.partner_a.id,
            'pricelist_id': self.company_data['default_pricelist'].id,
        })
        # Section Line
        so_line_ordered_project_only = self.env['sale.order.line'].create({
            'name': "Section Name",
            'order_id': sale_order.id,
            'display_type': 'line_section',
        })
        so_line_deliver_global_project = self.env['sale.order.line'].create({
            'name': self.product_delivery_timesheet2.name,
            'product_id': self.product_delivery_timesheet2.id,
            'product_uom_qty': 50,
            'product_uom': self.product_delivery_timesheet2.uom_id.id,
            'price_unit': self.product_delivery_timesheet2.list_price,
            'order_id': sale_order.id,
        })
        so_line_deliver_task_project = self.env['sale.order.line'].create({
            'name': self.product_delivery_timesheet3.name,
            'product_id': self.product_delivery_timesheet3.id,
            'product_uom_qty': 20,
            'product_uom': self.product_delivery_timesheet3.uom_id.id,
            'price_unit': self.product_delivery_timesheet3.list_price,
            'order_id': sale_order.id,
        })
        so_line_deliver_global_project.product_id_change()
        so_line_deliver_task_project.product_id_change()

        # confirm SO
        sale_order.action_confirm()
        task_serv1 = self.env['project.task'].search([('sale_line_id', '=', so_line_deliver_global_project.id)])
        task_serv2 = self.env['project.task'].search([('sale_line_id', '=', so_line_deliver_task_project.id)])
        project_serv2 = self.env['project.project'].search([('sale_line_id', '=', so_line_deliver_task_project.id)])

        timesheet1 = self.env['account.analytic.line'].create({
            'name': 'Test Line',
            'project_id': task_serv1.project_id.id,
            'task_id': task_serv1.id,
            'unit_amount': 10,
            'employee_id': self.employee_manager.id,
            'date': today - timedelta(days=6)
        })

        timesheet2 = self.env['account.analytic.line'].create({
            'name': 'Test Line 2',
            'project_id': task_serv1.project_id.id,
            'task_id': task_serv1.id,
            'unit_amount': 20,
            'employee_id': self.employee_manager.id,
            'date': today - timedelta(days=1)
        })

        timesheet3 = self.env['account.analytic.line'].create({
            'name': 'Test Line 3',
            'project_id': task_serv1.project_id.id,
            'task_id': task_serv1.id,
            'unit_amount': 10,
            'employee_id': self.employee_manager.id,
            'date': today - timedelta(days=5)
        })

        timesheet4 = self.env['account.analytic.line'].create({
            'name': 'Test Line 4',
            'project_id': task_serv2.project_id.id,
            'task_id': task_serv2.id,
            'unit_amount': 30,
            'employee_id': self.employee_manager.id
        })
        self.assertEqual(so_line_deliver_global_project.invoice_status, 'to invoice')
        self.assertEqual(so_line_deliver_task_project.invoice_status, 'to invoice')
        self.assertEqual(sale_order.invoice_status, 'to invoice')

        # Context for sale.advance.payment.inv wizard
        self.context = {
            'active_model': 'sale.order',
            'active_ids': [sale_order.id],
            'active_id': sale_order.id,
            'default_journal_id': self.company_data['default_journal_sale'].id
        }

        # invoice SO
        wizard = self.env['sale.advance.payment.inv'].with_context(self.context).create({
            'advance_payment_method': 'delivered',
            'date_start_invoice_timesheet': today - timedelta(days=16),
            'date_end_invoice_timesheet': today - timedelta(days=10)
        })

        self.assertTrue(wizard.invoicing_timesheet_enabled, 'The "date_start_invoice_timesheet" and "date_end_invoice_timesheet" field should be visible in the wizard because a product in sale order has service_policy to "Timesheet on Task"')

        with self.assertRaises(UserError):
            wizard.create_invoices()

        self.assertFalse(sale_order.invoice_ids, 'Normally, no invoice will be created because the timesheet logged is after the period defined in date_start_invoice_timesheet and date_end_invoice_timesheet field')

        wizard.write({
            'date_start_invoice_timesheet': today - timedelta(days=10),
            'date_end_invoice_timesheet': today - timedelta(days=6)
        })
        wizard.create_invoices()

        self.assertTrue(sale_order.invoice_ids, 'One invoice should be created because the timesheet logged is between the period defined in wizard')

        invoice = sale_order.invoice_ids[0]
        self.assertEqual(so_line_deliver_global_project.qty_invoiced, timesheet1.unit_amount)

        # validate invoice
        invoice.action_post()

        wizard.write({
            'date_start_invoice_timesheet': today - timedelta(days=16),
            'date_end_invoice_timesheet': today - timedelta(days=4)
        })
        wizard.create_invoices()

        self.assertEqual(len(sale_order.invoice_ids), 2)
        invoice2 = sale_order.invoice_ids[-1]

        self.assertEqual(so_line_deliver_global_project.qty_invoiced, timesheet1.unit_amount + timesheet3.unit_amount, "The last invoice done should have the quantity of the timesheet 3, because the date this timesheet is the only one before the 'date_end_invoice_timesheet' field in the wizard.")

        wizard.write({
            'date_start_invoice_timesheet': today - timedelta(days=4),
            'date_end_invoice_timesheet': today
        })

        wizard.create_invoices()

        self.assertEqual(len(sale_order.invoice_ids), 3)
        invoice3 = sale_order.invoice_ids[-1]

        # Check if all timesheets have been invoiced
        self.assertEqual(so_line_deliver_global_project.qty_invoiced, timesheet1.unit_amount + timesheet2.unit_amount + timesheet3.unit_amount)
        self.assertTrue(so_line_deliver_task_project.invoice_lines)
        self.assertEqual(so_line_deliver_task_project.qty_invoiced, timesheet4.unit_amount)
コード例 #9
0
ファイル: test_reinvoice.py プロジェクト: yustas147/odoo
    def test_reversed_invoice_reinvoice_with_period(self):
        """
        Tests that when reversing an invoice of timesheet and selecting a time
        period, the qty to invoice is correctly found
        Business flow:
          Create a sale order and deliver some hours (invoiced = 0)
          Create an invoice
          Confirm (invoiced = 1)
          Add Credit Note
          Confirm (invoiced = 0)
          Go back to the SO
          Create an invoice
          Select a time period [1 week ago, 1 week in the future]
          Confirm
          -> Fails if there is nothing to invoice
        """
        product = self.env['product.product'].create({
            'name':
            "Service delivered, create task in global project",
            'standard_price':
            30,
            'list_price':
            90,
            'type':
            'service',
            'service_policy':
            'delivered_timesheet',
            'invoice_policy':
            'delivery',
            'default_code':
            'SERV-DELI2',
            'service_type':
            'timesheet',
            'service_tracking':
            'task_global_project',
            'project_id':
            self.project_global.id,
            'taxes_id':
            False,
            'property_account_income_id':
            self.account_sale.id,
        })
        today = Date.context_today(self.env.user)

        # Creates a sales order for quantity 3
        so_form = Form(self.env['sale.order'])
        so_form.partner_id = self.env['res.partner'].create({'name': 'Toto'})
        with so_form.order_line.new() as line:
            line.product_id = product
            line.product_uom_qty = 3.0
        sale_order = so_form.save()
        sale_order.action_confirm()

        # "Deliver" 1 of 3
        task = sale_order.tasks_ids
        self.env['account.analytic.line'].create({
            'name':
            'Test Line',
            'project_id':
            task.project_id.id,
            'task_id':
            task.id,
            'unit_amount':
            1,
            'employee_id':
            self.employee_user.id,
            'company_id':
            self.company_data['company'].id,
        })

        context = {
            "active_model": 'sale.order',
            "active_ids": [sale_order.id],
            "active_id": sale_order.id,
            'open_invoices': True,
        }
        # Invoice the 1
        wizard = self.env['sale.advance.payment.inv'].with_context(
            context).create({'advance_payment_method': 'delivered'})
        invoice_dict = wizard.create_invoices()
        # Confirm the invoice
        invoice = self.env['account.move'].browse(invoice_dict['res_id'])
        invoice.action_post()

        # Refund the invoice
        wiz_context = {
            'active_model': 'account.move',
            'active_ids': [invoice.id],
            'default_journal_id': self.company_data['default_journal_sale'].id
        }
        refund_invoice_wiz = self.env['account.move.reversal'].with_context(
            wiz_context).create({
                'reason': 'please reverse :c',
                'refund_method': 'refund',
                'date': today,
            })
        refund_invoice = self.env['account.move'].browse(
            refund_invoice_wiz.reverse_moves()['res_id'])
        refund_invoice.action_post()
        # reversing with action_reverse and then action_post does not reset the invoice_status to 'to invoice' in tests

        # Recreate wizard to get the new invoices created
        wizard = self.env['sale.advance.payment.inv'].with_context(
            context).create({
                'advance_payment_method':
                'delivered',
                'date_start_invoice_timesheet':
                today - timedelta(days=7),
                'date_end_invoice_timesheet':
                today + timedelta(days=7)
            })

        # The actual test :
        wizard.create_invoices(
        )  # No exception should be raised, there is indeed something to be invoiced since it was reversed
コード例 #10
0
    def test_tax_balance(self):
        tax_account_id = self.env['account.account'].create({
            'name': 'Tax Paid',
            'code': 'TAXTEST',
            'user_type_id': self.env.ref(
                'account.data_account_type_current_liabilities'
            ).id,
        }).id
        tax = self.env['account.tax'].create({
            'name': 'Tax 10.0%',
            'amount': 10.0,
            'amount_type': 'percent',
            'account_id': tax_account_id,
        })
        invoice_account_id = self.env['account.account'].search(
            [('user_type_id', '=', self.env.ref(
                'account.data_account_type_receivable'
            ).id)], limit=1).id
        invoice_line_account_id = self.env['account.account'].create({
            'user_type_id': self.env.ref(
                'account.data_account_type_expenses'
            ).id,
            'code': 'EXPTEST',
            'name': 'Test expense account',
        }).id
        invoice = self.env['account.invoice'].create({
            'partner_id': self.env.ref('base.res_partner_2').id,
            'account_id': invoice_account_id,
            'type': 'out_invoice',
        })

        self.env['account.invoice.line'].create({
            'product_id': self.env.ref('product.product_product_4').id,
            'quantity': 1.0,
            'price_unit': 100.0,
            'invoice_id': invoice.id,
            'name': 'product that cost 100',
            'account_id': invoice_line_account_id,
            'invoice_line_tax_ids': [(6, 0, [tax.id])],
        })
        invoice._onchange_invoice_line_ids()
        invoice._convert_to_write(invoice._cache)
        self.assertEqual(invoice.state, 'draft')

        # change the state of invoice to open by clicking Validate button
        invoice.action_invoice_open()

        self.assertEqual(tax.base_balance, 100.)
        self.assertEqual(tax.balance, 10.)
        self.assertEqual(tax.base_balance_regular, 100.)
        self.assertEqual(tax.balance_regular, 10.)
        self.assertEqual(tax.base_balance_refund, 0.)
        self.assertEqual(tax.balance_refund, 0.)

        # testing wizard
        current_range = self.range.search([
            ('date_start', '=', '%s-%s-01' % (
                self.current_year, self.current_month))
        ])
        wizard = self.env['wizard.open.tax.balances'].new({})
        self.assertFalse(wizard.from_date)
        self.assertFalse(wizard.to_date)
        wizard = self.env['wizard.open.tax.balances'].new({
            'date_range_id': current_range[0].id,
        })
        wizard.onchange_date_range_id()
        wizard._convert_to_write(wizard._cache)
        action = wizard.open_taxes()
        self.assertEqual(
            action['context']['from_date'], current_range[0].date_start)
        self.assertEqual(
            action['context']['to_date'], current_range[0].date_end)

        # exercise search has_moves = True
        taxes = self.env['account.tax'].search([('has_moves', '=', True)])
        self.assertLessEqual(tax, taxes)

        # testing buttons
        tax_action = tax.view_tax_lines()
        base_action = tax.view_base_lines()
        tax_action_move_lines = self.env['account.move.line'].\
            search(tax_action['domain'])
        self.assertTrue(invoice.move_id.line_ids & tax_action_move_lines)
        self.assertEqual(
            tax_action['xml_id'], 'account.action_account_moves_all_tree')
        base_action_move_lines = self.env['account.move.line'].\
            search(base_action['domain'])
        self.assertTrue(invoice.move_id.line_ids & base_action_move_lines)
        self.assertEqual(
            base_action['xml_id'], 'account.action_account_moves_all_tree')

        # test specific method
        state_list = tax.get_target_state_list(target_move='all')
        self.assertEqual(state_list, ['posted', 'draft'])
        state_list = tax.get_target_state_list(target_move='whatever')
        self.assertEqual(state_list, [])

        refund = self.env['account.invoice'].create({
            'partner_id': self.env.ref('base.res_partner_2').id,
            'account_id': invoice_account_id,
            'type': 'out_refund',
        })

        self.env['account.invoice.line'].create({
            'product_id': self.env.ref('product.product_product_2').id,
            'quantity': 1.0,
            'price_unit': 25.0,
            'invoice_id': refund.id,
            'name': 'returned product that cost 25',
            'account_id': invoice_line_account_id,
            'invoice_line_tax_ids': [(6, 0, [tax.id])],
        })
        refund._onchange_invoice_line_ids()
        refund._convert_to_write(invoice._cache)
        self.assertEqual(refund.state, 'draft')

        # change the state of refund to open by clicking Validate button
        refund.action_invoice_open()

        # force the _compute_balance() to be triggered
        tax._compute_balance()

        self.assertEqual(tax.base_balance, 75.)
        self.assertEqual(tax.balance, 7.5)
        self.assertEqual(tax.base_balance_regular, 100.)
        self.assertEqual(tax.balance_regular, 10.)
        self.assertEqual(tax.base_balance_refund, -25.)
        self.assertEqual(tax.balance_refund, -2.5)

        # Taxes on liquidity type moves are included
        liquidity_account_id = self.env['account.account'].search(
            [('internal_type', '=', 'liquidity')], limit=1).id
        self.env['account.move'].create({
            'date': Date.context_today(self.env.user),
            'journal_id': self.env['account.journal'].search(
                [('type', '=', 'bank')], limit=1).id,
            'name': 'Test move',
            'line_ids': [(0, 0, {
                'account_id': liquidity_account_id,
                'debit': 110,
                'credit': 0,
                'name': 'Bank Fees',
            }), (0, 0, {
                'account_id': invoice_line_account_id,
                'debit': 0,
                'credit': 100,
                'name': 'Bank Fees',
                'tax_ids': [(4, tax.id)]
            }), (0, 0, {
                'account_id': tax.account_id.id,
                'debit': 0,
                'credit': 10,
                'name': 'Bank Fees',
                'tax_line_id': tax.id,
            })],
        }).post()
        tax.refresh()
        self.assertEqual(tax.base_balance, 175.)
        self.assertEqual(tax.balance, 17.5)
コード例 #11
0
    def test_tax_balance(self):
        tax_account_id = (self.env["account.account"].create({
            "name":
            "Tax Paid",
            "code":
            "TAXTEST",
            "user_type_id":
            self.env.ref("account.data_account_type_current_liabilities").id,
        }).id)
        tax = self.env["account.tax"].create({
            "name": "Tax 10.0%",
            "amount": 10.0,
            "amount_type": "percent"
        })
        invoice_line_account_id = (self.env["account.account"].create({
            "user_type_id":
            self.env.ref("account.data_account_type_expenses").id,
            "code":
            "EXPTEST",
            "name":
            "Test expense account",
        }).id)
        product = self.env.ref("product.product_product_4")
        invoice = self.env["account.move"].create({
            "partner_id":
            self.env.ref("base.res_partner_2").id,
            "type":
            "out_invoice",
            "invoice_line_ids": [(
                0,
                None,
                {
                    "product_id": product.id,
                    "quantity": 1.0,
                    "price_unit": 100.0,
                    "name": "product that cost 100",
                    "account_id": invoice_line_account_id,
                    "tax_ids": [(6, 0, [tax.id])],
                },
            )],
        })

        invoice._onchange_invoice_line_ids()
        invoice._convert_to_write(invoice._cache)
        self.assertEqual(invoice.state, "draft")

        # change the state of invoice to open by clicking Validate button
        invoice.action_post()

        self.assertEqual(tax.base_balance, 100.0)
        self.assertEqual(tax.balance, 10.0)
        self.assertEqual(tax.base_balance_regular, 100.0)
        self.assertEqual(tax.balance_regular, 10.0)
        self.assertEqual(tax.base_balance_refund, 0.0)
        self.assertEqual(tax.balance_refund, 0.0)

        # testing wizard
        current_range = self.range.search([(
            "date_start",
            "=",
            "{}-{}-01".format(self.current_year, self.current_month),
        )])
        wizard = self.env["wizard.open.tax.balances"].new({})
        self.assertFalse(wizard.from_date)
        self.assertFalse(wizard.to_date)
        wizard = self.env["wizard.open.tax.balances"].new(
            {"date_range_id": current_range[0].id})
        self.assertEqual(wizard.from_date, current_range[0].date_start)
        self.assertEqual(wizard.to_date, current_range[0].date_end)
        action = wizard.open_taxes()
        self.assertEqual(action["context"]["from_date"],
                         current_range[0].date_start)
        self.assertEqual(action["context"]["to_date"],
                         current_range[0].date_end)

        # exercise search has_moves = True
        taxes = self.env["account.tax"].search([("has_moves", "=", True)])
        self.assertEqual(len(taxes), 1)
        self.assertEqual(taxes[0].name, "Tax 10.0%")

        # testing buttons
        tax_action = tax.view_tax_lines()
        base_action = tax.view_base_lines()
        tax_action_move_lines = self.env["account.move.line"].search(
            tax_action["domain"])
        self.assertTrue(invoice.line_ids & tax_action_move_lines)
        self.assertEqual(tax_action["xml_id"],
                         "account.action_account_moves_all_tree")
        base_action_move_lines = self.env["account.move.line"].search(
            base_action["domain"])
        self.assertTrue(invoice.line_ids & base_action_move_lines)
        self.assertEqual(base_action["xml_id"],
                         "account.action_account_moves_all_tree")

        # test specific method
        state_list = tax.get_target_state_list(target_move="all")
        self.assertEqual(state_list, ["posted", "draft"])
        state_list = tax.get_target_state_list(target_move="whatever")
        self.assertEqual(state_list, [])

        product = self.env.ref("product.product_product_2")
        refund = self.env["account.move"].create({
            "partner_id":
            self.env.ref("base.res_partner_2").id,
            "type":
            "out_refund",
            "invoice_line_ids": [(
                0,
                None,
                {
                    "product_id": product.id,
                    "quantity": 1.0,
                    "price_unit": 25.0,
                    "name": "returned product that cost 25",
                    "account_id": invoice_line_account_id,
                    "tax_ids": [(6, 0, [tax.id])],
                },
            )],
        })

        refund._onchange_invoice_line_ids()
        refund._convert_to_write(invoice._cache)
        self.assertEqual(refund.state, "draft")

        # change the state of refund to open by clicking Validate button
        refund.action_post()

        # force the _compute_balance() to be triggered
        tax._compute_balance()

        self.assertEqual(tax.base_balance, 75.0)
        self.assertEqual(tax.balance, 7.5)
        self.assertEqual(tax.base_balance_regular, 100.0)
        self.assertEqual(tax.balance_regular, 10.0)
        self.assertEqual(tax.base_balance_refund, -25.0)
        self.assertEqual(tax.balance_refund, -2.5)

        # Taxes on liquidity type moves are included
        tax_repartition_line = tax.invoice_repartition_line_ids.filtered(
            lambda line: line.repartition_type == "tax")
        liquidity_account_id = (self.env["account.account"].search(
            [("internal_type", "=", "liquidity")], limit=1).id)
        move = self.env["account.move"].create({
            "type":
            "entry",
            "date":
            Date.context_today(self.env.user),
            "journal_id":
            self.env["account.journal"].search([("type", "=", "bank")],
                                               limit=1).id,
            "name":
            "Test move",
            "line_ids": [
                (
                    0,
                    0,
                    {
                        "account_id": liquidity_account_id,
                        "debit": 110,
                        "credit": 0,
                        "name": "Bank Fees",
                    },
                ),
                (
                    0,
                    0,
                    {
                        "account_id": invoice_line_account_id,
                        "debit": 0,
                        "credit": 100,
                        "name": "Bank Fees",
                        "tax_ids": [(4, tax.id)],
                    },
                ),
                (
                    0,
                    0,
                    {
                        "account_id": tax_account_id,
                        "debit": 0,
                        "credit": 10,
                        "name": "Bank Fees",
                        "tax_repartition_line_id": tax_repartition_line.id,
                    },
                ),
            ],
        })
        move.action_post()
        tax.refresh()
        self.assertEqual(tax.base_balance, 175.0)
        self.assertEqual(tax.balance, 17.5)
コード例 #12
0
 def _inverse_age(self):
     today = fDate.context_today(self)
     for book in self.filtered('date_release'):
         d = fDate.subtract(today, days=book.age_days)
         book.date_release = d
コード例 #13
0
 def _compute_age(self):
     today = fDate.context_today(self)
     for book in self.filtered('date_release'):
         delta = today - book.date_release
         book.age_days = delta.days
コード例 #14
0
 def _compute_age(self):
     today = fDate.from_string(fDate.context_today(self))
     for book in self.filtered('date_release'):
         delta = (today - fDate.from_string(book.date_release))
         book.age_days = delta.days
コード例 #15
0
ファイル: test_sale_timesheet.py プロジェクト: WilldooIT/odoo
    def test_transfert_project(self):
        """ Transfert task with timesheet to another project. """
        Timesheet = self.env['account.analytic.line']
        Task = self.env['project.task']
        today = Date.context_today(self.env.user)

        task = Task.with_context(default_project_id=self.project_template.id).create({
            'name': 'first task',
            'partner_id': self.partner_b.id,
            'planned_hours': 10,
            'sale_line_id': self.so.order_line[0].id
        })

        Timesheet.create({
            'project_id': self.project_template.id,
            'task_id': task.id,
            'name': 'my first timesheet',
            'unit_amount': 4,
        })

        timesheet_count1 = Timesheet.search_count([('project_id', '=', self.project_global.id)])
        timesheet_count2 = Timesheet.search_count([('project_id', '=', self.project_template.id)])
        self.assertEqual(timesheet_count1, 0, "No timesheet in project_global")
        self.assertEqual(timesheet_count2, 1, "One timesheet in project_template")
        self.assertEqual(len(task.timesheet_ids), 1, "The timesheet should be linked to task")

        # change project of task, as the timesheet is not yet invoiced, the timesheet will change his project
        task.write({
            'project_id': self.project_global.id
        })

        timesheet_count1 = Timesheet.search_count([('project_id', '=', self.project_global.id)])
        timesheet_count2 = Timesheet.search_count([('project_id', '=', self.project_template.id)])
        self.assertEqual(timesheet_count1, 1, "One timesheet in project_global")
        self.assertEqual(timesheet_count2, 0, "No timesheet in project_template")
        self.assertEqual(len(task.timesheet_ids), 1, "The timesheet still should be linked to task")

        # Create an invoice
        context = {
            'active_model': 'sale.order',
            'active_ids': [self.so.id],
            'active_id': self.so.id,
            'default_journal_id': self.company_data['default_journal_sale'].id
        }
        wizard = self.env['sale.advance.payment.inv'].with_context(context).create({
            'advance_payment_method': 'delivered',
            'date_start_invoice_timesheet': today - timedelta(days=4),
            'date_end_invoice_timesheet': today,
        })
        wizard.create_invoices()

        Timesheet.create({
            'project_id': self.project_global.id,
            'task_id': task.id,
            'name': 'my second timesheet',
            'unit_amount': 6,
        })

        self.assertEqual(Timesheet.search_count([('project_id', '=', self.project_global.id)]), 2, "2 timesheets in project_global")

        # change project of task, the timesheet not yet invoiced will change its project. The timesheet already invoiced will not change his project.
        task.write({
            'project_id': self.project_template.id
        })

        timesheet_count1 = Timesheet.search_count([('project_id', '=', self.project_global.id)])
        timesheet_count2 = Timesheet.search_count([('project_id', '=', self.project_template.id)])
        self.assertEqual(timesheet_count1, 1, "Still one timesheet in project_global")
        self.assertEqual(timesheet_count2, 1, "One timesheet in project_template")
        self.assertEqual(len(task.timesheet_ids), 2, "The 2 timesheets still should be linked to task")
コード例 #16
0
    def test_transfert_project(self):
        """ Transfert task with timesheet to another project. """
        Timesheet = self.env['account.analytic.line']
        Task = self.env['project.task']
        today = Date.context_today(self.env.user)

        task = Task.with_context(
            default_project_id=self.project_global.id).create({
                'name':
                'first task',
                'partner_id':
                self.partner_customer_usd.id,
                'planned_hours':
                10,
            })

        Timesheet.create({
            'project_id': self.project_global.id,
            'task_id': task.id,
            'name': 'my first timesheet',
            'unit_amount': 4,
        })

        timesheet_count1 = Timesheet.search_count([('project_id', '=',
                                                    self.project_global.id)])
        timesheet_count2 = Timesheet.search_count([('project_id', '=',
                                                    self.project_template.id)])
        self.assertEqual(timesheet_count1, 1,
                         "One timesheet in project_global")
        self.assertEqual(timesheet_count2, 0,
                         "No timesheet in project_template")
        self.assertEqual(len(task.timesheet_ids), 1,
                         "The timesheet should be linked to task")

        # change project of task, as the timesheet is not yet invoiced, the timesheet will change his project
        task.write({'project_id': self.project_template.id})

        timesheet_count1 = Timesheet.search_count([('project_id', '=',
                                                    self.project_global.id)])
        timesheet_count2 = Timesheet.search_count([('project_id', '=',
                                                    self.project_template.id)])
        self.assertEqual(timesheet_count1, 0, "No timesheet in project_global")
        self.assertEqual(timesheet_count2, 1,
                         "One timesheet in project_template")
        self.assertEqual(len(task.timesheet_ids), 1,
                         "The timesheet still should be linked to task")

        wizard = self.env['project.task.create.sale.order'].with_context(
            active_id=task.id, active_model='project.task').create(
                {'product_id': self.product_delivery_timesheet3.id})

        # We create the SO and the invoice
        action = wizard.action_create_sale_order()
        sale_order = self.env['sale.order'].browse(action['res_id'])
        self.context = {
            'active_model': 'sale.order',
            'active_ids': [sale_order.id],
            'active_id': sale_order.id,
            'default_journal_id': self.journal_sale.id
        }
        wizard = self.env['sale.advance.payment.inv'].with_context(
            self.context).create({
                'advance_payment_method': 'delivered',
                'date_invoice_timesheet': today
            })
        wizard.create_invoices()

        Timesheet.create({
            'project_id': self.project_template.id,
            'task_id': task.id,
            'name': 'my second timesheet',
            'unit_amount': 6,
        })

        self.assertEqual(
            Timesheet.search_count([
                ('project_id', '=', self.project_template.id)
            ]), 2, "2 timesheets in project_template")

        # change project of task, the timesheet not yet invoiced will change its project. The timesheet already invoiced will not change his project.
        task.write({'project_id': self.project_global.id})

        timesheet_count1 = Timesheet.search_count([('project_id', '=',
                                                    self.project_global.id)])
        timesheet_count2 = Timesheet.search_count([('project_id', '=',
                                                    self.project_template.id)])
        self.assertEqual(timesheet_count1, 1,
                         "One timesheet in project_global")
        self.assertEqual(timesheet_count2, 1,
                         "Still one timesheet in project_template")
        self.assertEqual(len(task.timesheet_ids), 2,
                         "The 2 timesheet still should be linked to task")
コード例 #17
0
 def _inverse_age(self):
     today = fDate.from_string(fDate.context_today(self))
     for book in self.filtered('date_release'):
         d = today - timedelta(days=book.age_days)
         book.date_release = fDate.to_string(d)
コード例 #18
0
    def test_read_grid_method_date(self):
        project_id = self.grid_obj_2.project_id
        grid_range = self.range_day
        row_field = []
        col_field = "start_date"
        cell_field = "resource_hours"
        domain = [('project_id', '=', project_id.id)]

        lang = self.env['res.lang'].search([('code', '=', self.env.user.lang)])
        lang.write({'week_start': '1'})

        # A call to read_grid with grid_anchor should return data from 2019-06-01 to 2019-06-30
        result_read_grid = self.grid_obj_2.with_context(
            grid_anchor="2019-06-14").read_grid(row_field, col_field,
                                                cell_field, domain, grid_range)

        # For checking today, previous and next grid_anchor
        self.assertEqual(
            result_read_grid.get('prev').get('grid_anchor'), "2019-05-14")
        self.assertEqual(
            result_read_grid.get('next').get('grid_anchor'), "2019-07-14")
        today = Date.from_string(Date.context_today(self.env.user))
        self.assertEqual(
            result_read_grid.get('initial').get('grid_anchor'),
            Date.to_string(today))

        # Should have 30 cols for 30 days of June and 1 row for grid_obj_2
        self.assertEqual(len(result_read_grid.get('cols')), 30)
        self.assertEqual(len(result_read_grid.get('rows')), 1)

        date_of_work = self.grid_obj_2.start_date.day - 1
        self.assertEqual(
            result_read_grid.get('grid')[0][date_of_work].get('value'),
            self.grid_obj_2.resource_hours)

        # For checking readonly of freeze cell
        result_read_grid_readonly = self.grid_obj_2_validated.with_context(
            grid_anchor="2019-06-14").read_grid(row_field,
                                                col_field,
                                                cell_field,
                                                domain,
                                                grid_range,
                                                readonly_field='validated')
        date_of_work = self.grid_obj_2_validated.start_date.day - 1
        self.assertEqual(
            result_read_grid_readonly.get('grid')[0][date_of_work].get(
                'readonly'), True)

        # For checking week range ('span': 'month', 'step': 'week')
        result_read_grid = self.grid_obj_2.with_context(
            grid_anchor="2019-06-14").read_grid(row_field, col_field,
                                                cell_field, domain,
                                                self.range_week_2)
        # Should have 5 weeks in cols
        self.assertEqual(len(result_read_grid.get('cols')), 5)
        col0 = result_read_grid.get('cols')[0]
        week1_start_date0 = col0.get('values').get('start_date')
        self.assertEqual(week1_start_date0[0], "2019-05-27/2019-06-03")
        col4 = result_read_grid.get('cols')[4]
        week1_start_date4 = col4.get('values').get('start_date')
        self.assertEqual(week1_start_date4[0], "2019-06-24/2019-07-01")
        # Since the start_date for obj_2 is 2019-06-04, so it is the second week according to its domain
        self.assertEqual(
            result_read_grid.get('grid')[0][1].get('value'), self.grid_obj_2.
            resource_hours)  # resource_hours for grid_obj_2 is 4.0