This commit is contained in:
Songb
2024-04-28 11:43:49 +08:00
commit 953c76ce8a
4108 changed files with 2312605 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
from . import test_documents
from . import test_invoices
from . import test_reports
+256
View File
@@ -0,0 +1,256 @@
# -*- coding: utf-8 -*-
import base64
from odoo.tests import Form
from odoo.exceptions import UserError
from odoo.tests.common import tagged, TransactionCase
GIF = b"R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs="
TEXT = base64.b64encode(bytes("workflow bridge account", 'utf-8'))
@tagged('post_install', '-at_install', 'test_document_bridge')
class TestCaseDocumentsBridgeAccount(TransactionCase):
def setUp(self):
super(TestCaseDocumentsBridgeAccount, self).setUp()
self.folder_a = self.env['documents.folder'].create({
'name': 'folder A',
})
self.folder_a_a = self.env['documents.folder'].create({
'name': 'folder A - A',
'parent_folder_id': self.folder_a.id,
})
self.document_txt = self.env['documents.document'].create({
'datas': TEXT,
'name': 'file.txt',
'mimetype': 'text/plain',
'folder_id': self.folder_a_a.id,
})
self.document_gif = self.env['documents.document'].create({
'datas': GIF,
'name': 'file.gif',
'mimetype': 'image/gif',
'folder_id': self.folder_a.id,
})
self.workflow_rule_vendor_bill = self.env['documents.workflow.rule'].create({
'domain_folder_id': self.folder_a.id,
'name': 'workflow rule create vendor bill on f_a',
'create_model': 'account.move.in_invoice',
})
def test_bridge_folder_workflow(self):
"""
tests the create new business model (vendor bill & credit note).
"""
self.assertEqual(self.document_txt.res_model, 'documents.document', "failed at default res model")
multi_return = self.workflow_rule_vendor_bill.apply_actions([self.document_txt.id, self.document_gif.id])
self.assertEqual(multi_return.get('type'), 'ir.actions.act_window',
'failed at invoice workflow return value type')
self.assertEqual(multi_return.get('res_model'), 'account.move',
'failed at invoice workflow return value res model')
self.assertEqual(self.document_txt.res_model, 'account.move', "failed at workflow_bridge_dms_account"
" new res_model")
vendor_bill_txt = self.env['account.move'].search([('id', '=', self.document_txt.res_id)])
self.assertTrue(vendor_bill_txt.exists(), 'failed at workflow_bridge_dms_account vendor_bill')
self.assertEqual(self.document_txt.res_id, vendor_bill_txt.id, "failed at workflow_bridge_dms_account res_id")
self.assertEqual(vendor_bill_txt.move_type, 'in_invoice', "failed at workflow_bridge_dms_account vendor_bill type")
vendor_bill_gif = self.env['account.move'].search([('id', '=', self.document_gif.res_id)])
self.assertEqual(self.document_gif.res_id, vendor_bill_gif.id, "failed at workflow_bridge_dms_account res_id")
single_return = self.workflow_rule_vendor_bill.apply_actions([self.document_txt.id])
self.assertEqual(single_return.get('res_model'), 'account.move',
'failed at invoice res_model action from workflow create model')
invoice = self.env[single_return['res_model']].browse(single_return.get('res_id'))
attachments = self.env['ir.attachment'].search([('res_model', '=', 'account.move'), ('res_id', '=', invoice.id)])
self.assertEqual(len(attachments), 1, 'there should only be one ir attachment matching')
def test_bridge_account_account_settings_on_write(self):
"""
Makes sure the settings apply their values when an ir_attachment is set as message_main_attachment_id
on invoices.
"""
folder_test = self.env['documents.folder'].create({'name': 'folder_test'})
self.env.user.company_id.documents_account_settings = True
for invoice_type in ['in_invoice', 'out_invoice', 'in_refund', 'out_refund']:
invoice_test = self.env['account.move'].with_context(default_move_type=invoice_type).create({
'name': 'invoice_test',
'move_type': invoice_type,
})
setting = self.env['documents.account.folder.setting'].create({
'folder_id': folder_test.id,
'journal_id': invoice_test.journal_id.id,
})
attachment_txt_test = self.env['ir.attachment'].create({
'datas': TEXT,
'name': 'fileText_test.txt',
'mimetype': 'text/plain',
'res_model': 'account.move',
'res_id': invoice_test.id
})
attachment_txt_alternative_test = self.env['ir.attachment'].create({
'datas': TEXT,
'name': 'fileText_test_alternative.txt',
'mimetype': 'text/plain',
'res_model': 'account.move',
'res_id': invoice_test.id
})
attachment_txt_main_attachment_test = self.env['ir.attachment'].create({
'datas': TEXT,
'name': 'fileText_main_attachment.txt',
'mimetype': 'text/plain',
'res_model': 'account.move',
'res_id': invoice_test.id
})
invoice_test.write({'message_main_attachment_id': attachment_txt_test.id})
txt_doc = self.env['documents.document'].search([('attachment_id', '=', attachment_txt_test.id)])
self.assertEqual(txt_doc.folder_id, folder_test, 'the text test document have a folder')
invoice_test.write({'message_main_attachment_id': attachment_txt_alternative_test.id})
self.assertEqual(txt_doc.attachment_id.id, attachment_txt_alternative_test.id,
"the attachment of the document should have swapped")
attachment_txt_main_attachment_test.register_as_main_attachment()
self.assertEqual(txt_doc.attachment_id.id, attachment_txt_main_attachment_test.id,
"the attachment of the document should have swapped")
# deleting the setting to prevent duplicate settings.
setting.unlink()
def test_journal_entry(self):
"""
Makes sure the settings apply their values when an ir_attachment is set as message_main_attachment_id
on invoices.
"""
folder_test = self.env['documents.folder'].create({'name': 'Bills'})
self.env.user.company_id.documents_account_settings = True
invoice_test = self.env['account.move'].with_context(default_move_type='entry').create({
'name': 'Journal Entry',
'move_type': 'entry',
})
setting = self.env['documents.account.folder.setting'].create({
'folder_id': folder_test.id,
'journal_id': invoice_test.journal_id.id,
})
attachments = self.env['ir.attachment'].create([{
'datas': TEXT,
'name': 'fileText_test.txt',
'mimetype': 'text/plain',
'res_model': 'account.move',
'res_id': invoice_test.id
}, {
'datas': TEXT,
'name': 'fileText_test2.txt',
'mimetype': 'text/plain',
'res_model': 'account.move',
'res_id': invoice_test.id
}])
documents = self.env['documents.document'].search([('attachment_id', 'in', attachments.ids)])
self.assertEqual(len(documents), 2)
setting.unlink()
def test_bridge_account_workflow_settings_on_write(self):
"""
Tests that tags added by a workflow action are not completely overridden by the settings.
"""
self.env.user.company_id.documents_account_settings = True
tag_category_a = self.env['documents.facet'].create({
'folder_id': self.folder_a.id,
'name': "categ_a",
})
tag_a = self.env['documents.tag'].create({
'facet_id': tag_category_a.id,
'name': "tag_a",
})
tag_b = self.env['documents.tag'].create({
'facet_id': tag_category_a.id,
'name': "tag_b",
})
tag_action_a = self.env['documents.workflow.action'].create({
'action': 'add',
'facet_id': tag_category_a.id,
'tag_id': tag_a.id,
})
self.workflow_rule_vendor_bill.tag_action_ids += tag_action_a
invoice_test = self.env['account.move'].with_context(default_move_type='in_invoice').create({
'name': 'invoice_test',
'move_type': 'in_invoice',
})
self.env['documents.account.folder.setting'].create({
'folder_id': self.folder_a.id,
'journal_id': invoice_test.journal_id.id,
'tag_ids': tag_b,
})
document_test = self.env['documents.document'].create({
'name': 'test reconciliation workflow',
'folder_id': self.folder_a.id,
'datas': TEXT,
})
self.workflow_rule_vendor_bill.apply_actions([document_test.id])
self.assertEqual(document_test.tag_ids, tag_a | tag_b,
"The document should have the workflow action's tag(s)")
def test_bridge_account_sync_partner(self):
"""
Tests that the partner is always synced on the document, regardless of settings
"""
partner_1, partner_2 = self.env['res.partner'].create([{'name': 'partner_1'}, {'name': 'partner_2'}])
self.document_txt.partner_id = partner_1
self.workflow_rule_vendor_bill.apply_actions([self.document_txt.id, self.document_gif.id])
move = self.env['account.move'].browse(self.document_txt.res_id)
self.assertEqual(move.partner_id, partner_1)
move.partner_id = partner_2
self.assertEqual(self.document_txt.partner_id, partner_2)
def test_workflow_create_misc_entry(self):
misc_entry_rule = self.env.ref('documents_account.misc_entry_rule')
misc_entry_action = misc_entry_rule.apply_actions([self.document_txt.id, self.document_gif.id])
move = self.env['account.move'].browse(self.document_txt.res_id)
self.assertEqual(misc_entry_action.get('res_model'), 'account.move')
self.assertEqual(move.move_type, 'entry')
self.assertTrue(move.journal_id in misc_entry_rule.suitable_journal_ids)
def test_workflow_create_bank_statement_raise(self):
with self.assertRaises(UserError): # Could not make sense of the given file.
self.env.ref('documents_account.bank_statement_rule').apply_actions([self.document_txt.id, self.document_gif.id])
def test_workflow_create_vendor_bill(self):
vendor_bill_entry_rule = self.env.ref('documents_account.vendor_bill_rule_financial')
vendor_bill_entry_action = vendor_bill_entry_rule.apply_actions([self.document_txt.id])
move = self.env['account.move'].browse(self.document_txt.res_id)
self.assertEqual(vendor_bill_entry_action.get('res_model'), 'account.move')
self.assertEqual(move.move_type, 'in_invoice')
self.assertTrue(move.journal_id in vendor_bill_entry_rule.suitable_journal_ids)
def test_workflow_create_vendor_receipt(self):
# Activate the group for the vendor receipt
self.env['res.config.settings'].create({'group_show_purchase_receipts': True}).execute()
self.assertTrue(self.env.user.has_group('account.group_purchase_receipts'), 'The "purchase Receipt" feature should be enabled.')
vendor_receipt_rule = self.env.ref('documents_account.documents_vendor_receipt_rule')
vendor_receipt_action = vendor_receipt_rule.apply_actions([self.document_txt.id])
move = self.env['account.move'].browse(self.document_txt.res_id)
self.assertEqual(vendor_receipt_action.get('res_model'), 'account.move')
self.assertEqual(move.move_type, 'in_receipt')
self.assertTrue(move.journal_id in vendor_receipt_rule.suitable_journal_ids)
def test_workflow_rule_form_journal(self):
with Form(self.env.ref('documents_account.vendor_bill_rule_financial')) as rule:
# our accounting action has a journal_id
self.assertTrue(rule.journal_id)
# switching it to non-accouting action resets its journal_id on write/create
rule.create_model = 'link.to.record'
rule.save()
self.assertFalse(rule.journal_id)
# switching back gives us the rigth journal_id on write/create
rule.create_model = 'account.move.out_invoice'
rule.save()
self.assertTrue(rule.journal_id.type == 'sale')
self.assertTrue(rule.journal_id in rule.suitable_journal_ids)
+65
View File
@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
import base64
from odoo import Command
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.tests import tagged
@tagged('post_install', '-at_install')
class TestInvoices(AccountTestInvoicingCommon):
def test_suspense_statement_line_id(self):
reconcile_activity_type = self.env['mail.activity.type'].create({
"name": "Reconciliation request",
"category": "upload_file",
"folder_id": self.env.ref("documents.documents_finance_folder").id,
"res_model": "account.move",
"tag_ids": [(6, 0, [self.env.ref('documents.documents_finance_status_tc').id])],
})
st = self.env['account.bank.statement'].create({
'line_ids': [Command.create({
'amount': -1000.0,
'date': '2017-01-01',
'journal_id': self.company_data['default_journal_bank'].id,
'payment_ref': 'test_suspense_statement_line_id',
})],
})
st.balance_end_real = st.balance_end
st_line = st.line_ids
move = st_line.move_id
# Log an activity on the move using the "Reconciliation Request".
activity = self.env['mail.activity'].create({
'activity_type_id': reconcile_activity_type.id,
'note': "test_suspense_statement_line_id",
'res_id': move.id,
'res_model_id': self.env.ref('account.model_account_move').id,
})
activity._onchange_activity_type_id()
# A new document has been created.
documents = self.env['documents.document'].search([('request_activity_id', '=', activity.id)])
self.assertTrue(documents.exists())
# Upload an attachment.
attachment = self.env['ir.attachment'].create({
'name': "test_suspense_statement_line_id",
'datas': base64.b64encode(bytes("test_suspense_statement_line_id", 'utf-8')),
'res_model': move._name,
'res_id': move.id,
})
activity._action_done(attachment_ids=attachment.ids)
# Upload as a vendor bill.
workflow_rule_vendor_bill = self.env['documents.workflow.rule'].create({
'domain_folder_id': documents.folder_id.id,
'name': "Create a new Vendor Bill from document",
'create_model': 'account.move.in_invoice',
})
vendor_bill_action = workflow_rule_vendor_bill.apply_actions(documents.ids)
self.assertTrue(vendor_bill_action.get('res_id'))
vendor_bill = self.env['account.move'].browse(vendor_bill_action['res_id'])
self.assertRecordValues(vendor_bill, [{'suspense_statement_line_id': st_line.id}])
+30
View File
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from odoo import fields
from odoo.tests import tagged
from odoo.addons.account_reports.tests.common import TestAccountReportsCommon
@tagged('post_install', '-at_install')
class TestReports(TestAccountReportsCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.report = cls.env.ref('account_reports.balance_sheet')
def test_report_export_wizard(self):
'''
The wizard in documents_account overrides the one in account_reports.
This test makes sure that the folder_id and tag_ids are properly set on get_attachment_vals()
'''
options = self._generate_options(self.report, fields.Date.from_string('2017-02-01'), fields.Date.from_string('2017-02-01'))
action = self.report.open_report_export_wizard(options)
wizard = self.env[action['res_model']].browse(action['res_id'])
wizard = wizard.with_context(account_report_generation_options=options)
export_format_ids = self.env['account_reports.export.wizard.format'].search([('fun_param', '=', 'export_to_xlsx')])
wizard['export_format_ids'] = export_format_ids
wizard.export_report()