from odoo.tests import TransactionCase, tagged @tagged('post_install', '-at_install') class TestButtonVisibility(TransactionCase): def setUp(self): super().setUp() self.vendor = self.env['res.partner'].create({'name': 'Test Vendor'}) self.product = self.env['product.product'].create({'name': 'Test Product', 'standard_price': 100}) def test_reset_to_draft_visibility(self): # Find existing posted bills for the vendor bills = self.env['account.move'].search([ ('move_type', '=', 'in_invoice'), ('partner_id', '=', self.vendor.id), ('state', '=', 'posted') ]) print(f"\nFOUND {len(bills)} POSTED BILLS FOR VENDOR {self.vendor.name}") for bill in bills: print(f"\nChecking Bill {bill.name} (ID: {bill.id}):") print(f" state: {bill.state}") print(f" restrict_mode_hash_table: {bill.restrict_mode_hash_table}") print(f" need_cancel_request: {bill.need_cancel_request}") print(f" show_reset_to_draft_button: {bill.show_reset_to_draft_button}") print(f" journal_id.restrict_mode_hash_table: {bill.journal_id.restrict_mode_hash_table}") # Additional check for localization overrides if any # (Printed above via logic) if not bills: print("No posted bills found to check. Creating one...") # Create Bill bill = self.env['account.move'].create({ 'move_type': 'in_invoice', 'partner_id': self.vendor.id, 'invoice_date': '2024-01-01', 'line_ids': [(0, 0, { 'product_id': self.product.id, 'quantity': 1, 'price_unit': 100, })] }) # Post Bill bill.action_post() print(f"\nCREATED FRESH BILL {bill.name}:") print(f" state: {bill.state}") print(f" show_reset_to_draft_button: {bill.show_reset_to_draft_button}") self.assertTrue(bill.show_reset_to_draft_button, "Fresh bill should have button visible")