def setUp(self): super(TestPayslipBase, self).setUp() # Some salary rules references self.hra_rule_id = self.ref( 'hr_payroll.hr_salary_rule_houserentallowance1') self.conv_rule_id = self.ref( 'hr_payroll.hr_salary_rule_convanceallowance1') self.prof_tax_rule_id = self.ref( 'hr_payroll.hr_salary_rule_professionaltax1') self.pf_rule_id = self.ref('hr_payroll.hr_salary_rule_providentfund1') self.mv_rule_id = self.ref('hr_payroll.hr_salary_rule_meal_voucher') self.comm_rule_id = self.ref( 'hr_payroll.hr_salary_rule_sales_commission') # I create a new employee "Richard" self.richard_emp = self.env['hr.employee'].create({ 'name': 'Richard', 'gender': 'male', 'birthday': '1984-05-01', 'country_id': self.ref('base.be'), 'department_id': self.ref('hr.dep_rd') }) # I create a salary structure for "Software Developer" self.developer_pay_structure = self.env['hr.payroll.structure'].create( { 'name': 'Salary Structure for Software Developer', 'code': 'SD', 'company_id': self.ref('base.main_company'), 'rule_ids': [(4, self.hra_rule_id), (4, self.conv_rule_id), (4, self.prof_tax_rule_id), (4, self.pf_rule_id), (4, self.mv_rule_id), (4, self.comm_rule_id)], }) # I create a contract for "Richard" self.env['hr.contract'].create({ 'date_end': Date.to_string((datetime.now() + timedelta(days=365))), 'date_start': Date.today(), 'name': 'Contract for Richard', 'wage': 5000.0, 'type_id': self.ref('hr_contract_types.hr_contract_type_emp'), 'employee_id': self.richard_emp.id, 'struct_id': self.developer_pay_structure.id, })
def test_01_test_total(self): today_date = Date.today() last_year_date = Date.to_string(datetime.today() - relativedelta(years=1)) move1 = self._add_move(today_date, self.journal_sale, 0, 100, 100, 0) move2 = self._add_move(last_year_date, self.journal_sale, 0, 100, 100, 0) report = self.ReportJournalLedger.create({ 'date_from': self.fy_date_start, 'date_to': self.fy_date_end, 'company_id': self.company.id, 'journal_ids': [(6, 0, self.journal_sale.ids)] }) report.compute_data_for_report() self.check_report_journal_debit_credit(report, 100, 100) move3 = self._add_move(today_date, self.journal_sale, 0, 100, 100, 0) report.compute_data_for_report() self.check_report_journal_debit_credit(report, 200, 200) report.move_target = 'posted' report.compute_data_for_report() self.check_report_journal_debit_credit(report, 0, 0) move1.post() report.compute_data_for_report() self.check_report_journal_debit_credit(report, 100, 100) move2.post() report.compute_data_for_report() self.check_report_journal_debit_credit(report, 100, 100) move3.post() report.compute_data_for_report() self.check_report_journal_debit_credit(report, 200, 200) report.date_from = self.previous_fy_date_start report.compute_data_for_report() self.check_report_journal_debit_credit(report, 300, 300)
def test_program_rules_one_date(self): # Test case: Based on the validity dates and the number of allowed uses # VFE NOTE the .rule_id is necessary to ensure the dates constraints doesn't raise # because the orm applies the related inverse one by one, raising the constraint... self.immediate_promotion_program.rule_id.write({ 'rule_date_from': False, 'rule_date_to': Date.to_string((datetime.now() - timedelta(days=2))), }) order = self.empty_order order.write({ 'order_line': [(0, False, { 'product_id': self.product_A.id, 'name': '1 Product A', 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }), (0, False, { 'product_id': self.product_B.id, 'name': '2 Product B', 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, })] }) order.recompute_coupon_lines() self.assertNotIn(self.immediate_promotion_program, order._get_applicable_programs()) self.assertEqual( len(order.order_line.ids), 2, "The promo offert shouldn't have been applied we're not between the validity dates" ) self.immediate_promotion_program.rule_id.write({ 'rule_date_from': Date.to_string((datetime.now() + timedelta(days=1))), 'rule_date_to': False, }) order.recompute_coupon_lines() self.assertNotIn(self.immediate_promotion_program, order._get_applicable_programs()) self.assertEqual( len(order.order_line.ids), 2, "The promo offert shouldn't have been applied we're not between the validity dates" ) self.immediate_promotion_program.rule_id.write({ 'rule_date_from': False, 'rule_date_to': Date.to_string((datetime.now() + timedelta(days=2))), }) order.recompute_coupon_lines() self.assertIn(self.immediate_promotion_program, order._get_applicable_programs()) self.assertEqual( len(order.order_line.ids), 3, "The promo offer should have been applied as we're between the validity dates" ) self.immediate_promotion_program.rule_id.write({ 'rule_date_from': Date.to_string((datetime.now() - timedelta(days=1))), 'rule_date_to': False, }) order.recompute_coupon_lines() self.assertIn(self.immediate_promotion_program, order._get_applicable_programs()) self.assertEqual( len(order.order_line.ids), 3, "The promo offer should have been applied as we're between the validity dates" )
def test_program_rules_validity_dates_and_uses(self): # Test case: Based on the validity dates and the number of allowed uses self.immediate_promotion_program.write({ 'rule_date_from': Date.to_string((datetime.now() - timedelta(days=7))), 'rule_date_to': Date.to_string((datetime.now() - timedelta(days=2))), 'maximum_use_number': 1, }) order = self.empty_order order.write({ 'order_line': [(0, False, { 'product_id': self.product_A.id, 'name': '1 Product A', 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }), (0, False, { 'product_id': self.product_B.id, 'name': '2 Product B', 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, })] }) order.recompute_coupon_lines() self.assertEqual( len(order.order_line.ids), 2, "The promo offert shouldn't have been applied we're not between the validity dates" ) self.immediate_promotion_program.write({ 'rule_date_from': Date.to_string((datetime.now() - timedelta(days=7))), 'rule_date_to': Date.to_string((datetime.now() + timedelta(days=2))), }) order = self.env['sale.order'].create({'partner_id': self.steve.id}) order.write({ 'order_line': [(0, False, { 'product_id': self.product_A.id, 'name': '1 Product A', 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, }), (0, False, { 'product_id': self.product_B.id, 'name': '2 Product B', 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, })] }) order.recompute_coupon_lines() self.assertEqual( len(order.order_line.ids), 3, "The promo offert should have been applied as we're between the validity dates" ) order = self.env['sale.order'].create({ 'partner_id': self.env['res.partner'].create({ 'name': 'My Partner' }).id }) order.write({ 'order_line': [(0, False, { 'product_id': self.product_A.id, 'name': '1 Product A', 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, }), (0, False, { 'product_id': self.product_B.id, 'name': '2 Product B', 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, })] }) order.recompute_coupon_lines() self.assertEqual( len(order.order_line.ids), 2, "The promo offert shouldn't have been applied as the number of uses is exceeded" )
def setUp(self): super(TestJournalReport, self).setUp() self.AccountObj = self.env['account.account'] self.InvoiceObj = self.env['account.invoice'] self.JournalObj = self.env['account.journal'] self.JournalReportObj = self.env['journal.ledger.report.wizard'] self.MoveObj = self.env['account.move'] self.ReportJournalLedger = self.env['report_journal_ledger'] self.TaxObj = self.env['account.tax'] self.company = self.env.ref('base.main_company') today = datetime.today() last_year = today - relativedelta(years=1) self.previous_fy_date_start = Date.to_string( last_year.replace(month=1, day=1)) self.previous_fy_date_end = Date.to_string( last_year.replace(month=12, day=31)) self.fy_date_start = Date.to_string(today.replace(month=1, day=1)) self.fy_date_end = Date.to_string(today.replace(month=12, day=31)) self.receivable_account = self.AccountObj.search( [('user_type_id.name', '=', 'Receivable')], limit=1) self.income_account = self.AccountObj.search( [('user_type_id.name', '=', 'Income')], limit=1) self.payable_account = self.AccountObj.search( [('user_type_id.name', '=', 'Payable')], limit=1) self.journal_sale = self.JournalObj.create({ 'name': "Test journal sale", 'code': "TST-JRNL-S", 'type': 'sale', 'company_id': self.company.id, }) self.journal_purchase = self.JournalObj.create({ 'name': "Test journal purchase", 'code': "TST-JRNL-P", 'type': 'sale', 'company_id': self.company.id, }) self.tax_15_s = self.TaxObj.create({ 'sequence': 30, 'name': 'Tax 15.0% (Percentage of Price)', 'amount': 15.0, 'amount_type': 'percent', 'include_base_amount': False, 'type_tax_use': 'sale', }) self.tax_20_s = self.TaxObj.create({ 'sequence': 30, 'name': 'Tax 20.0% (Percentage of Price)', 'amount': 20.0, 'amount_type': 'percent', 'include_base_amount': False, 'type_tax_use': 'sale', }) self.tax_15_p = self.TaxObj.create({ 'sequence': 30, 'name': 'Tax 15.0% (Percentage of Price)', 'amount': 15.0, 'amount_type': 'percent', 'include_base_amount': False, 'type_tax_use': 'purchase', }) self.tax_20_p = self.TaxObj.create({ 'sequence': 30, 'name': 'Tax 20.0% (Percentage of Price)', 'amount': 20.0, 'amount_type': 'percent', 'include_base_amount': False, 'type_tax_use': 'purchase', }) self.partner_2 = self.env.ref('base.res_partner_2')
def dump_date(self, value, write): value = Date.to_string(value) self.dump_unicode(value, write)
def _check_pos_hash_integrity(self): """Checks that all posted or invoiced pos orders have still the same data as when they were posted and raises an error with the result. """ def build_order_info(order): entry_reference = _('(Receipt ref.: %s)') order_reference_string = order.pos_reference and entry_reference % order.pos_reference or '' return [ ctx_tz(order, 'date_order'), order.l10n_fr_hash, order.name, order_reference_string, ctx_tz(order, 'write_date') ] hash_verified = True msg_alert = '' report_dict = {} if self._is_accounting_unalterable(): orders = self.env['pos.order'].search( [('state', 'in', ['paid', 'done', 'invoiced']), ('company_id', '=', self.id), ('l10n_fr_secure_sequence_number', '!=', 0)], order="l10n_fr_secure_sequence_number ASC") if not orders: msg_alert = (_( 'There isn\'t any order flagged for data inalterability yet for the company %s. This mechanism only runs for point of sale orders generated after the installation of the module France - Certification CGI 286 I-3 bis. - POS', self.env.company.name)) hash_verified = False previous_hash = u'' start_order_info = [] for order in orders: if order.l10n_fr_hash != order._compute_hash( previous_hash=previous_hash): msg_alert = (_( 'Corrupted data on point of sale order with id %s.', order.id)) hash_verified = False break previous_hash = order.l10n_fr_hash if hash_verified: orders_sorted_date = orders.sorted(lambda o: o.date_order) start_order_info = build_order_info(orders_sorted_date[0]) end_order_info = build_order_info(orders_sorted_date[-1]) report_dict.update({ 'first_order_name': start_order_info[2], 'first_order_hash': start_order_info[1], 'first_order_date': start_order_info[0], 'last_order_name': end_order_info[2], 'last_order_hash': end_order_info[1], 'last_order_date': end_order_info[0], }) return { 'result': hash_verified and report_dict or 'None', 'msg_alert': msg_alert or 'None', 'printing_date': format_date(self.env, Date.to_string(Date.today())), }