def test_02_invoice_plan_with_advance(self): # To create all remaining invoice from SO ctx = { "active_id": self.so_service.id, "active_ids": [self.so_service.id], "all_remain_invoices": True, } # Create Invoice Plan 3 installment with Advance num_installment = 3 f = Form(self.env["sale.create.invoice.plan"]) f.num_installment = num_installment f.advance = True # Advance plan = f.save() plan.with_context(ctx).sale_create_invoice_plan() self.assertEqual( len(self.so_service.invoice_plan_ids), num_installment + 1, "Wrong number of installment created", ) # If advance percent is not filled, show error with self.assertRaises(ValidationError): self.so_service.action_confirm() advance_line = self.so_service.invoice_plan_ids.filtered( lambda l: l.invoice_type == "advance" ) self.assertEqual(len(advance_line), 1, "No one advance line") # Add 10% to advance advance_line.percent = 10 # Can confirm the SO after advance is filled self.so_service.action_confirm() # Create all invoice plan wizard = self.env["sale.make.planned.invoice"].create({}) wizard.with_context(ctx).create_invoices_by_plan() # Valid number of invoices, including advance invoices = self.so_service.invoice_ids self.assertEqual( len(invoices), num_installment + 1, "Wrong number of invoice created" ) # Valid total quantity of invoices (exclude Advance line) quantity = sum( invoices.mapped("invoice_line_ids") .filtered(lambda l: l.product_id == self.product_order) .mapped("quantity") ) self.assertEqual(quantity, 1, "Wrong number of total invoice quantity")
def test_create_expenses(self): form_expenses = Form(self.env["deltatech.expenses.deduction"]) form_expenses.date_advance = fields.Date.today() form_expenses.advance = 1000 form_expenses.employee_id = self.employee form_expenses.account_diem_id = self.account_diem expenses = form_expenses.save() expenses.validate_advance() form_expenses = Form(expenses) with form_expenses.expenses_line_ids.new() as line: line.name = "Test" line.amount = 300 expenses = form_expenses.save() expenses.validate_expenses() expenses.invalidate_expenses()