diff --git a/sale_order_type_quotation_number/README.rst b/sale_order_type_quotation_number/README.rst new file mode 100644 index 00000000000..6c0c2c64455 --- /dev/null +++ b/sale_order_type_quotation_number/README.rst @@ -0,0 +1,95 @@ +================================ +Sale Order Type Quotation Number +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:aed9621c7132552e2656b5a9fa1b9b7a47d7f9aad353a430cc389e3a675d1f6c + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/16.0/sale_order_type_quotation_number + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_order_type_quotation_number + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to set a quotation sequence depending on the sale order type. It also makes compatible the modules sale_order_type and sale_quotation_number, so both a sale order sequence and a quotation sequence can be set in a sale order type. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module you need to + +* Go to Sales > Configuration > Sale Order Types and select an order type +* Select a sequence in "Quotation Sequence" field. If the field is left blank, the default quoation sequence will be used. + +Usage +===== + +When the quotation sequence applied to a quotation has changed, click on the "Recompute Quotation Seq." in order to generate the new quotation number. + +Known issues / Roadmap +====================== + +* This module does not apply quotation sequences to orders created from website. + +Bug Tracker +=========== + +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. + +Credits +======= + +Authors +~~~~~~~ + +* Sygel + +Contributors +~~~~~~~~~~~~ + +* `Sygel `_: + * Manuel Regidor + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_order_type_quotation_number/__init__.py b/sale_order_type_quotation_number/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/sale_order_type_quotation_number/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_order_type_quotation_number/__manifest__.py b/sale_order_type_quotation_number/__manifest__.py new file mode 100644 index 00000000000..40af1e60c5a --- /dev/null +++ b/sale_order_type_quotation_number/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2023 Manuel Regidor +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Sale Order Type Quotation Number", + "summary": "Use quotation sequence depending on sale type", + "version": "16.0.1.0.0", + "category": "Sales", + "website": "https://github.com/OCA/sale-workflow", + "author": "Sygel, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "sale_order_type", + "sale_quotation_number", + ], + "data": ["views/sale_order_type_view.xml", "views/sale_views.xml"], +} diff --git a/sale_order_type_quotation_number/i18n/es.po b/sale_order_type_quotation_number/i18n/es.po new file mode 100644 index 00000000000..c9323b99450 --- /dev/null +++ b/sale_order_type_quotation_number/i18n/es.po @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_type_quotation_number +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-10-25 13:46+0000\n" +"PO-Revision-Date: 2023-10-25 15:49+0200\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 2.3\n" + +#. module: sale_order_type_quotation_number +#: model:ir.model.fields,field_description:sale_order_type_quotation_number.field_sale_order__applied_quotation_seq_id +msgid "Applied Quotation Seq" +msgstr "Secuencia de presupuesto aplicada" + +#. module: sale_order_type_quotation_number +#: model:ir.model.fields,field_description:sale_order_type_quotation_number.field_sale_order_type__quotation_sequence_id +#: model_terms:ir.ui.view,arch_db:sale_order_type_quotation_number.quotation_sot_sale_order_type_search_view +msgid "Quotation Sequence" +msgstr "Secuencia de presupuesto" + +#. module: sale_order_type_quotation_number +#: model:ir.model.fields,field_description:sale_order_type_quotation_number.field_sale_order__recompute_quotation_seq +msgid "Recompute Quotation Seq" +msgstr "Recomputar secuencia presupuesto" + +#. module: sale_order_type_quotation_number +#: model_terms:ir.ui.view,arch_db:sale_order_type_quotation_number.quotation_sot_view_order_form +msgid "Recompute Quotation Seq." +msgstr "Recomputar secuencia presupuesto" + +#. module: sale_order_type_quotation_number +#: model_terms:ir.ui.view,arch_db:sale_order_type_quotation_number.quotation_sot_view_order_form +msgid "" +"Recomputing the quotation sequence will generate a gap in the previous " +"sequence. Would you like to proceed?" +msgstr "" +"Recomputar la secuencia de presupuesto generará saltos en la secuencia " +"anterior. ¿Desea continuar?" + +#. module: sale_order_type_quotation_number +#: model:ir.model,name:sale_order_type_quotation_number.model_sale_order +msgid "Sales Order" +msgstr "Pedido de venta" + +#. module: sale_order_type_quotation_number +#: model:ir.model,name:sale_order_type_quotation_number.model_sale_order_type +msgid "Type of sale order" +msgstr "Tipo de pedido de venta" diff --git a/sale_order_type_quotation_number/i18n/sale_order_type_quotation_number.pot b/sale_order_type_quotation_number/i18n/sale_order_type_quotation_number.pot new file mode 100644 index 00000000000..2fd67189b59 --- /dev/null +++ b/sale_order_type_quotation_number/i18n/sale_order_type_quotation_number.pot @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_type_quotation_number +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sale_order_type_quotation_number +#: model:ir.model.fields,field_description:sale_order_type_quotation_number.field_sale_order__applied_quotation_seq_id +msgid "Applied Quotation Seq" +msgstr "" + +#. module: sale_order_type_quotation_number +#: model:ir.model.fields,field_description:sale_order_type_quotation_number.field_sale_order_type__quotation_sequence_id +#: model_terms:ir.ui.view,arch_db:sale_order_type_quotation_number.quotation_sot_sale_order_type_search_view +msgid "Quotation Sequence" +msgstr "" + +#. module: sale_order_type_quotation_number +#: model:ir.model.fields,field_description:sale_order_type_quotation_number.field_sale_order__recompute_quotation_seq +msgid "Recompute Quotation Seq" +msgstr "" + +#. module: sale_order_type_quotation_number +#: model_terms:ir.ui.view,arch_db:sale_order_type_quotation_number.quotation_sot_view_order_form +msgid "Recompute Quotation Seq." +msgstr "" + +#. module: sale_order_type_quotation_number +#: model_terms:ir.ui.view,arch_db:sale_order_type_quotation_number.quotation_sot_view_order_form +msgid "" +"Recomputing the quotation sequence will generate a gap in the previous " +"sequence. Would you like to proceed?" +msgstr "" + +#. module: sale_order_type_quotation_number +#: model:ir.model,name:sale_order_type_quotation_number.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: sale_order_type_quotation_number +#: model:ir.model,name:sale_order_type_quotation_number.model_sale_order_type +msgid "Type of sale order" +msgstr "" diff --git a/sale_order_type_quotation_number/models/__init__.py b/sale_order_type_quotation_number/models/__init__.py new file mode 100644 index 00000000000..5b7c8a413d8 --- /dev/null +++ b/sale_order_type_quotation_number/models/__init__.py @@ -0,0 +1,2 @@ +from . import sale_order +from . import sale_order_type diff --git a/sale_order_type_quotation_number/models/sale_order.py b/sale_order_type_quotation_number/models/sale_order.py new file mode 100644 index 00000000000..0e6bb1ce741 --- /dev/null +++ b/sale_order_type_quotation_number/models/sale_order.py @@ -0,0 +1,80 @@ +# Copyright 2023 Manuel Regidor +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + applied_quotation_seq_id = fields.Many2one( + comodel_name="ir.sequence", readonly=True + ) + recompute_quotation_seq = fields.Boolean( + compute="_compute_recompute_quotation_seq", + store=True, + ) + + @api.model_create_multi + def create(self, vals_list): + orders = self.browse() + for vals in vals_list: + orders |= super( + SaleOrder, self.with_context(type_id=vals.get("type_id")) + ).create([vals]) + for order in orders.filtered(lambda a: a.quotation_seq_used): + order.applied_quotation_seq_id = order.get_quotation_seq_id() + return orders + + @api.depends("type_id", "type_id.quotation_sequence_id", "state") + def _compute_recompute_quotation_seq(self): + for sel in self: + res = False + if ( + sel.state in ["draft", "sent"] + and sel.type_id.quotation_sequence_id + and sel.type_id.quotation_sequence_id != sel.applied_quotation_seq_id + ): + res = True + sel.recompute_quotation_seq = res + + def action_recompute_quotation_seq(self): + for sel in self.filtered( + lambda a: a.state in ["draft", "sent"] and a.recompute_quotation_seq + ): + sel.write( + { + "name": sel.type_id.quotation_sequence_id.next_by_id(), + "applied_quotation_seq_id": sel.type_id.quotation_sequence_id.id, + } + ) + + def get_quotation_seq_id(self): + self.ensure_one() + seq_id = False + if not self.company_id.keep_name_so: + seq_id = self.type_id.quotation_sequence_id or self.env[ + "ir.sequence" + ].search([("code", "=", "sale.quotation")], limit=1) + return seq_id + + @api.model + def get_quotation_seq(self): + seq = "" + type_id = False + if self.env.context.get("type_id"): + type_id = self.env["sale.order.type"].browse( + self.env.context.get("type_id") + ) + if type_id and type_id.quotation_sequence_id: + seq = type_id.quotation_sequence_id.next_by_id() + else: + seq = super().get_quotation_seq() + return seq + + def get_sale_order_seq(self): + if self.type_id and self.type_id.sequence_id: + seq = self.type_id.sequence_id.next_by_id() + else: + seq = super().get_sale_order_seq() + return seq diff --git a/sale_order_type_quotation_number/models/sale_order_type.py b/sale_order_type_quotation_number/models/sale_order_type.py new file mode 100644 index 00000000000..af2376b6cac --- /dev/null +++ b/sale_order_type_quotation_number/models/sale_order_type.py @@ -0,0 +1,20 @@ +# Copyright 2023 Manuel Regidor +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class SaleOrderType(models.Model): + _inherit = "sale.order.type" + + @api.model + def _get_quotation_domain_sequence_id(self): + seq_type = self.env.ref("sale_quotation_number.seq_sale_quotation") + return [("code", "=", seq_type.code)] + + quotation_sequence_id = fields.Many2one( + comodel_name="ir.sequence", + string="Quotation Sequence", + copy=False, + domain=_get_quotation_domain_sequence_id, + ) diff --git a/sale_order_type_quotation_number/readme/CONFIGURE.rst b/sale_order_type_quotation_number/readme/CONFIGURE.rst new file mode 100644 index 00000000000..c474946d588 --- /dev/null +++ b/sale_order_type_quotation_number/readme/CONFIGURE.rst @@ -0,0 +1,4 @@ +To configure this module you need to + +* Go to Sales > Configuration > Sale Order Types and select an order type +* Select a sequence in "Quotation Sequence" field. If the field is left blank, the default quoation sequence will be used. diff --git a/sale_order_type_quotation_number/readme/CONTRIBUTORS.rst b/sale_order_type_quotation_number/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..229bfdde92e --- /dev/null +++ b/sale_order_type_quotation_number/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* `Sygel `_: + * Manuel Regidor diff --git a/sale_order_type_quotation_number/readme/DESCRIPTION.rst b/sale_order_type_quotation_number/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..38cec17f262 --- /dev/null +++ b/sale_order_type_quotation_number/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows to set a quotation sequence depending on the sale order type. It also makes compatible the modules sale_order_type and sale_quotation_number, so both a sale order sequence and a quotation sequence can be set in a sale order type. diff --git a/sale_order_type_quotation_number/readme/ROADMAP.rst b/sale_order_type_quotation_number/readme/ROADMAP.rst new file mode 100644 index 00000000000..52cc7f568de --- /dev/null +++ b/sale_order_type_quotation_number/readme/ROADMAP.rst @@ -0,0 +1 @@ +* This module does not apply quotation sequences to orders created from website. diff --git a/sale_order_type_quotation_number/readme/USAGE.rst b/sale_order_type_quotation_number/readme/USAGE.rst new file mode 100644 index 00000000000..36773d2bafa --- /dev/null +++ b/sale_order_type_quotation_number/readme/USAGE.rst @@ -0,0 +1 @@ +When the quotation sequence applied to a quotation has changed, click on the "Recompute Quotation Seq." in order to generate the new quotation number. diff --git a/sale_order_type_quotation_number/static/description/icon.png b/sale_order_type_quotation_number/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_order_type_quotation_number/static/description/icon.png differ diff --git a/sale_order_type_quotation_number/static/description/index.html b/sale_order_type_quotation_number/static/description/index.html new file mode 100644 index 00000000000..815619af0c4 --- /dev/null +++ b/sale_order_type_quotation_number/static/description/index.html @@ -0,0 +1,451 @@ + + + + + +Sale Order Type Quotation Number + + + +
+

Sale Order Type Quotation Number

+ + +

Beta License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runboat

+

This module allows to set a quotation sequence depending on the sale order type. It also makes compatible the modules sale_order_type and sale_quotation_number, so both a sale order sequence and a quotation sequence can be set in a sale order type.

+

Table of contents

+ +
+

Configuration

+

To configure this module you need to

+
    +
  • Go to Sales > Configuration > Sale Order Types and select an order type
  • +
  • Select a sequence in “Quotation Sequence” field. If the field is left blank, the default quoation sequence will be used.
  • +
+
+
+

Usage

+

When the quotation sequence applied to a quotation has changed, click on the “Recompute Quotation Seq.” in order to generate the new quotation number.

+
+
+

Known issues / Roadmap

+
    +
  • This module does not apply quotation sequences to orders created from website.
  • +
+
+
+

Bug Tracker

+

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.

+
+
+

Credits

+
+

Authors

+
    +
  • Sygel
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

This module is part of the OCA/sale-workflow project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/sale_order_type_quotation_number/tests/__init__.py b/sale_order_type_quotation_number/tests/__init__.py new file mode 100644 index 00000000000..8f66054f09d --- /dev/null +++ b/sale_order_type_quotation_number/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_order_type_quotation_number diff --git a/sale_order_type_quotation_number/tests/test_sale_order_type_quotation_number.py b/sale_order_type_quotation_number/tests/test_sale_order_type_quotation_number.py new file mode 100644 index 00000000000..75c7f8a50fd --- /dev/null +++ b/sale_order_type_quotation_number/tests/test_sale_order_type_quotation_number.py @@ -0,0 +1,70 @@ +# Copyright 2023 Manuel Regidor +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import odoo.tests.common as common +from odoo.tests import Form, tagged + + +@tagged("post_install", "-at_install") +class TestSaleOrderTypeQuotationNumber(common.TransactionCase): + def setUp(self): + super(TestSaleOrderTypeQuotationNumber, self).setUp() + self.sale_seq = self.env["ir.sequence"].create( + {"name": "Sale Seq. 1", "code": "sale.order", "prefix": "SO1", "padding": 5} + ) + self.quotation_seq_1 = self.env["ir.sequence"].create( + { + "name": "Quotation Seq. 1", + "code": "sale.quotation", + "prefix": "Q1", + "padding": 5, + } + ) + self.quotation_seq_2 = self.env["ir.sequence"].create( + { + "name": "Quotation Seq. 2", + "code": "sale.quotation", + "prefix": "Q2", + "padding": 5, + } + ) + self.order_type_1 = self.env["sale.order.type"].create( + { + "name": "Test Sale Order Type 1", + "sequence_id": self.sale_seq.id, + "quotation_sequence_id": self.quotation_seq_1.id, + } + ) + self.order_type_2 = self.env["sale.order.type"].create( + { + "name": "Test Sale Order Type 2", + "sequence_id": self.sale_seq.id, + "quotation_sequence_id": self.quotation_seq_2.id, + } + ) + self.partner = self.env.ref("base.res_partner_1") + self.env.company.write({"keep_name_so": False}) + + def create_sale_order(self, partner=False): + sale_form = Form(self.env["sale.order"]) + sale_form.partner_id = self.partner + sale_form.type_id = self.order_type_1 + return sale_form.save() + + def test_quotation_seq(self): + order = self.create_sale_order() + self.assertEqual(order.name[:2], "Q1") + self.assertFalse(order.recompute_quotation_seq) + + def test_quotation_seq_change(self): + order = self.create_sale_order() + self.assertEqual(order.name[:2], "Q1") + order.type_id = self.order_type_2 + self.assertTrue(order.recompute_quotation_seq) + order.action_recompute_quotation_seq() + self.assertEqual(order.name[:2], "Q2") + + def test_order_type_seq(self): + order = self.create_sale_order() + order.action_confirm() + self.assertEqual(order.name[:3], "SO1") diff --git a/sale_order_type_quotation_number/views/sale_order_type_view.xml b/sale_order_type_quotation_number/views/sale_order_type_view.xml new file mode 100644 index 00000000000..3ec1409d610 --- /dev/null +++ b/sale_order_type_quotation_number/views/sale_order_type_view.xml @@ -0,0 +1,46 @@ + + + + + quotation.sot.sale.order.type.form.view + sale.order.type + + + + + + + + + quotation.sot.sale.order.type.tree.view + sale.order.type + + + + + + + + + quotation.sot.sale.order.type.search.view + sale.order.type + + + + + + + + + + + diff --git a/sale_order_type_quotation_number/views/sale_views.xml b/sale_order_type_quotation_number/views/sale_views.xml new file mode 100644 index 00000000000..3b351402bb7 --- /dev/null +++ b/sale_order_type_quotation_number/views/sale_views.xml @@ -0,0 +1,22 @@ + + + + + quotation.sot.view.order.form + sale.order + + + + + + diff --git a/sale_quotation_number/__manifest__.py b/sale_quotation_number/__manifest__.py index 9db76a56c29..a54edb46096 100644 --- a/sale_quotation_number/__manifest__.py +++ b/sale_quotation_number/__manifest__.py @@ -6,7 +6,7 @@ { "name": "Sale Quotation Numeration", "summary": "Different sequence for sale quotations", - "version": "16.0.1.1.0", + "version": "16.0.1.1.1", "category": "Sales Management", "website": "https://github.com/OCA/sale-workflow", "author": "Elico Corp, " diff --git a/sale_quotation_number/migrations/16.0.1.1.1/post-migration.py b/sale_quotation_number/migrations/16.0.1.1.1/post-migration.py new file mode 100644 index 00000000000..a09c61128ef --- /dev/null +++ b/sale_quotation_number/migrations/16.0.1.1.1/post-migration.py @@ -0,0 +1,19 @@ +# Copyright 2023 Manuel Regidor (Sygel) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +import odoo + + +def migrate(cr, version): + env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) + orders = ( + env["sale.order"] + .search( + [ + ("state", "in", ["draft", "sent"]), + ("company_id.keep_name_so", "=", False), + ] + ) + .filtered(lambda a: a.name[:2] == "SQ") + ) + orders.write({"quotation_seq_used": True}) diff --git a/sale_quotation_number/models/sale_order.py b/sale_quotation_number/models/sale_order.py index b48634d8c06..d20ccb75c0e 100644 --- a/sale_quotation_number/models/sale_order.py +++ b/sale_quotation_number/models/sale_order.py @@ -4,12 +4,16 @@ # © 2020 Manuel Regidor # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) -from odoo import api, models +from odoo import api, fields, models class SaleOrder(models.Model): _inherit = "sale.order" + quotation_seq_used = fields.Boolean( + string="Quotation Sequence Used", default=False, copy=False, readonly=True + ) + @api.model_create_multi def create(self, vals_list): for vals in vals_list: @@ -20,7 +24,7 @@ def create(self, vals_list): .env["ir.sequence"] .next_by_code("sale.quotation") ) - vals["name"] = sequence or "/" + vals.update({"name": sequence or "/", "quotation_seq_used": True}) return super().create(vals_list) @api.model @@ -42,12 +46,20 @@ def copy(self, default=None): default["origin"] = self.name return super().copy(default) + def get_sale_order_seq(self): + self.ensure_one() + return ( + self.with_company(self.company_id.id) + .env["ir.sequence"] + .next_by_code("sale.order") + ) + def action_confirm(self): sequence = self.env["ir.sequence"].search( [("code", "=", "sale.quotation")], limit=1 ) for order in self: - if sequence and self.name[: len(sequence.prefix)] != sequence.prefix: + if not self.quotation_seq_used: continue if order.state not in ("draft", "sent") or order.company_id.keep_name_so: continue @@ -55,10 +67,6 @@ def action_confirm(self): quo = order.origin + ", " + order.name else: quo = order.name - sequence = ( - self.with_company(order.company_id.id) - .env["ir.sequence"] - .next_by_code("sale.order") - ) - order.write({"origin": quo, "name": sequence}) + sequence = order.get_sale_order_seq() + order.write({"origin": quo, "name": sequence, "quotation_seq_used": False}) return super().action_confirm() diff --git a/setup/sale_order_type_quotation_number/odoo/addons/sale_order_type_quotation_number b/setup/sale_order_type_quotation_number/odoo/addons/sale_order_type_quotation_number new file mode 120000 index 00000000000..30d1e5da165 --- /dev/null +++ b/setup/sale_order_type_quotation_number/odoo/addons/sale_order_type_quotation_number @@ -0,0 +1 @@ +../../../../sale_order_type_quotation_number \ No newline at end of file diff --git a/setup/sale_order_type_quotation_number/setup.py b/setup/sale_order_type_quotation_number/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/sale_order_type_quotation_number/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)