+
Account Sequence Option
+
+
+
+
This module extends module base_sequence_option and allow you to provide
+optional sequences for account.move documents, i.e., invoice, bill,
+journal entry.
+
To use this module, enable developer mode, and check “Use sequence
+options” under Settings -> Technical -> Manage Sequence Options.
+
If you want to define your sequences in XML, feel free to use
+demo/account_demo_options.xml as a base for your own sequence
+definitions.
+
The demo sequences use a continuous numbering scheme, without the
+current year in the generated name. To use a scheme that does include
+the year, set use_date_range to true, and use %(range_year)s
+the represent the year. For example, to generate an invoice scheme that
+will generate “2022F00001” in 2022, try:
+
+<record id="seq_customer_invoice_1" model="ir.sequence">
+ <field name="name">Customer Invoice</field>
+ <field name="padding" eval="5" />
+ <field name="prefix">%(range_year)sF</field>
+ <field name="use_date_range">true</field>
+</record>
+
+
Odoo will generate the date ranges automagically when the first invoice
+(or vendor bill, etc) of a year is posted.
+
+
Important
+
This is an alpha version, the data model and design can change at any time without warning.
+Only for development or testing purpose, do not use in production.
+More details on development status
+
+
Table of contents
+
+
+
+
Bugs are tracked on GitHub Issues.
+In case of trouble, please check there if your issue has already been reported.
+If you spotted it first, help us to smash it by providing a detailed and welcomed
+feedback.
+
Do not contact contributors directly about support or help with technical issues.
+
+
+
+
+
+
+
+
This module is maintained by the OCA.
+
+
+
+
OCA, or the Odoo Community Association, is a nonprofit organization whose
+mission is to support the collaborative development of Odoo features and
+promote its widespread use.
+
Current maintainer:
+
+
This module is part of the OCA/account-financial-tools project on GitHub.
+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
+
+
+
+
+
diff --git a/account_sequence_option/tests/__init__.py b/account_sequence_option/tests/__init__.py
new file mode 100644
index 00000000000..7fa68a11132
--- /dev/null
+++ b/account_sequence_option/tests/__init__.py
@@ -0,0 +1,4 @@
+# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
+# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
+
+from . import test_account_sequence_option
diff --git a/account_sequence_option/tests/test_account_sequence_option.py b/account_sequence_option/tests/test_account_sequence_option.py
new file mode 100644
index 00000000000..ceb8bbd7684
--- /dev/null
+++ b/account_sequence_option/tests/test_account_sequence_option.py
@@ -0,0 +1,97 @@
+# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
+# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
+
+from datetime import timedelta
+
+from odoo import fields
+from odoo.tests.common import Form, TransactionCase, tagged
+
+
+@tagged("post_install", "-at_install")
+class TestAccountSequenceOption(TransactionCase):
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+ cls.AccountMove = cls.env["account.move"]
+ cls.AccountMoveLine = cls.env["account.move.line"]
+ cls.partner_id = cls.env.ref("base.res_partner_1")
+ cls.product_id_1 = cls.env.ref("product.product_product_6")
+ cls.account_seq_opt1 = cls.env.ref("account_sequence_option.account_sequence")
+ cls.pay_in = cls.env.ref("account.account_payment_method_manual_in")
+ cls.pay_out = cls.env.ref("account.account_payment_method_manual_out")
+
+ @classmethod
+ def _create_invoice(self, move_type):
+ move_form = Form(
+ self.env["account.move"].with_context(default_move_type=move_type)
+ )
+ move_form.partner_id = self.partner_id
+ move_form.invoice_date = fields.Date.today()
+ with move_form.invoice_line_ids.new() as line_form:
+ line_form.product_id = self.product_id_1
+ invoice = move_form.save()
+ return invoice
+
+ @classmethod
+ def _create_payment(self, payment_type, partner_type):
+ ctx = {
+ "default_payment_type": payment_type,
+ "default_partner_type": partner_type,
+ "default_move_journal_types": ("bank", "cash"),
+ }
+ move_form = Form(self.env["account.payment"].with_context(**ctx))
+ move_form.partner_id = self.partner_id
+ payment = move_form.save()
+ return payment
+
+ def test_account_sequence_options(self):
+ """Test different kind of sequences
+ 1. Customer Invoice 2. Vendor Bill
+ 3. Customer Refund 4. Vendor Refund
+ 5. Customer Payment 6. Vendor Payment
+ """
+ self.account_seq_opt1.use_sequence_option = True
+ # 1. Customer Invoice
+ self.invoice = self._create_invoice("out_invoice")
+ self.invoice.action_post()
+ self.invoice._compute_name()
+ name = hasattr(self.env["account.journal"], "sequence_id") and "INV" or "CINV"
+ self.assertIn(name, self.invoice.name)
+ # 2. Vendor Bill
+ self.invoice = self._create_invoice("in_invoice")
+ self.invoice.action_post()
+ name = hasattr(self.env["account.journal"], "sequence_id") and "BILL" or "VBIL"
+ self.assertIn(name, self.invoice.name)
+ # 3. Customer Refund
+ self.invoice = self._create_invoice("out_refund")
+ self.invoice.action_post()
+ name = hasattr(self.env["account.journal"], "sequence_id") and "RINV" or "CREF"
+ self.assertIn(name, self.invoice.name)
+ # 4. Vendor Refund
+ self.invoice = self._create_invoice("in_refund")
+ self.invoice.action_post()
+ name = hasattr(self.env["account.journal"], "sequence_id") and "RBILL" or "VREF"
+ self.assertIn(name, self.invoice.name)
+ # 5. Customer Payment
+ self.payment = self._create_payment("inbound", "customer")
+ self.payment.action_post()
+ name = hasattr(self.env["account.journal"], "sequence_id") and "BNK1" or "CPAY"
+ self.assertIn(name, self.payment.name)
+ # 6. Vendor Payment
+ self.payment = self._create_payment("outbound", "supplier")
+ self.payment.action_post()
+ name = hasattr(self.env["account.journal"], "sequence_id") and "BNK1" or "VPAY"
+ self.assertIn(name, self.payment.name)
+ # 7. Create out invoice, post invoice, reset invoice to Draft
+ # Change Date, post invoice.
+ self.invoice = self._create_invoice("out_invoice")
+ self.invoice.action_post()
+ old_name = self.invoice.name
+ self.invoice.button_draft()
+ self.invoice.write(
+ {"invoice_date": self.invoice.invoice_date - timedelta(days=1)}
+ )
+ self.invoice.action_post()
+ self.assertEqual(old_name, self.invoice.name)
+
+ self.invoice._constrains_date_sequence()
diff --git a/account_sequence_option/views/account_move_views.xml b/account_sequence_option/views/account_move_views.xml
new file mode 100644
index 00000000000..c37ab1df9ff
--- /dev/null
+++ b/account_sequence_option/views/account_move_views.xml
@@ -0,0 +1,15 @@
+
+
+