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_kit_anglo_saxo_price_diff(self): """ Suppose an automated-AVCO configuration and a Price Difference Account defined on the product category. When buying a kit of that category at a higher price than its cost, the difference should be published on the Price Difference Account """ price_diff_account = self.env['account.account'].create({ 'name': 'Super Price Difference Account', 'code': 'SPDA', 'user_type_id': self.env.ref('account.data_account_type_current_assets').id, 'reconcile': True, }) self.avco_category.property_account_creditor_price_difference_categ = price_diff_account kit, compo01, compo02 = self.env['product.product'].create([{ 'name': name, 'standard_price': price, 'type': 'product', 'categ_id': self.avco_category.id, } for name, price in [('Kit', 0), ('Compo 01', 10), ('Compo 02', 20)]]) self.env['mrp.bom'].create({ 'product_tmpl_id': kit.product_tmpl_id.id, 'type': 'phantom', 'bom_line_ids': [(0, 0, { 'product_id': p.id, 'product_qty': 1, }) for p in [compo01, compo02]] }) kit.button_bom_cost() po_form = Form(self.env['purchase.order']) po_form.partner_id = self.vendor01 with po_form.order_line.new() as pol_form: pol_form.product_id = kit pol_form.price_unit = 100 po = po_form.save() po.button_confirm() action = po.picking_ids.button_validate() wizard = Form(self.env[action['res_model']].with_context( action['context'])).save() wizard.process() action = po.action_create_invoice() invoice = self.env['account.move'].browse(action['res_id']) invoice.invoice_date = Date.today() invoice.action_post() price_diff_aml = invoice.line_ids.filtered( lambda l: l.account_id == price_diff_account) self.assertEqual( price_diff_aml.balance, 70, "Should be the purchase price minus the kit cost (i.e. 100 - 30)")
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())), }