Skip to content

Commit

Permalink
[13.0][ADD] purchase_isolated_rfq
Browse files Browse the repository at this point in the history
  • Loading branch information
kongrattapong committed Jan 28, 2020
1 parent 4b76960 commit 9c9db37
Show file tree
Hide file tree
Showing 14 changed files with 750 additions and 0 deletions.
90 changes: 90 additions & 0 deletions purchase_isolated_rfq/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
=====================
Purchase Isolated RFQ
=====================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fpurchase--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/purchase-workflow/tree/13.0-add-purchase_isolated_quotation/purchase_isolated_rfq
:alt: OCA/purchase-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/purchase-workflow-13-0-add-purchase_isolated_quotation/purchase-workflow-13-0-add-purchase_isolated_quotation-purchase_isolated_rfq
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/142/13.0-add-purchase_isolated_quotation
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

Base on sale_isolated_quotation

In some countries/companies, It's already common to separate these two documents.
For filing purposes, the document sequence of Requests For Quotation (RFQ) and Purchases order
has to be separated. In practice, there could be multiple RFQ open
to a vendor, yet only one RFQ get converted to the Purchases order.

This module separate RFQ and Purchases order by adding order_sequence flag in
purchase.order model.

Each type of document will have separated sequence numbering.
RFQ will have only 2 state, Draft and Done. Purchases Order work as normal.

**Table of contents**

.. contents::
:local:

Usage
=====

* Create RFQ as normal
* As user click "Convert to Order", the isolated purchases order will be created

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_isolated_rfq%0Aversion:%2013.0-add-purchase_isolated_quotation%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Ecosoft

Contributors
~~~~~~~~~~~~

* Rattapong Chokmasermkul <rattapongc@ecosoft.co.th>

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/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/13.0-add-purchase_isolated_quotation/purchase_isolated_rfq>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions purchase_isolated_rfq/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .hooks import post_init_hook
from . import models
14 changes: 14 additions & 0 deletions purchase_isolated_rfq/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2020 Ecosoft Co., Ltd (https://ecosoft.co.th)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
{
"name": "Purchase Isolated RFQ",
"version": "13.0.1.0.0",
"author": "Ecosoft, Odoo Community Association (OCA)",
"category": "Purchases",
"website": "https://github.com/OCA/purchase-workflow",
"depends": ["purchase"],
"license": "AGPL-3",
"data": ["data/ir_sequence_data.xml", "views/purchase_views.xml"],
"installable": True,
"post_init_hook": "post_init_hook",
}
12 changes: 12 additions & 0 deletions purchase_isolated_rfq/data/ir_sequence_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<odoo noupdate="1">

<!-- Sequences for RFQ -->
<record id="seq_purchase_rfq" model="ir.sequence">
<field name="name">Requests for Quotation</field>
<field name="code">purchase.rfq</field>
<field name="prefix">RFQ</field>
<field name="padding">3</field>
<field name="company_id" eval="False"/>
</record>

</odoo>
13 changes: 13 additions & 0 deletions purchase_isolated_rfq/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 Ecosoft Co., Ltd (https://ecosoft.co.th)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)


def post_init_hook(cr, registry):
""" Set value for order_sequence on old records """
cr.execute(
"""
update purchase_order
set order_sequence = true
where state not in ('draft', 'cancel')
"""
)
1 change: 1 addition & 0 deletions purchase_isolated_rfq/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import purchase_order
81 changes: 81 additions & 0 deletions purchase_isolated_rfq/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright 2020 Ecosoft Co., Ltd (https://ecosoft.co.th)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from odoo import _, api, fields, models
from odoo.exceptions import UserError


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

order_sequence = fields.Boolean(string="Order Sequence", readonly=True, index=True)
quote_id = fields.Many2one(
comodel_name="purchase.order",
string="Quotation",
readonly=True,
ondelete="restrict",
copy=False,
help="For Purchases Order, this field references to its RFQ",
)
order_id = fields.Many2one(
comodel_name="purchase.order",
string="Order",
readonly=True,
ondelete="restrict",
copy=False,
help="For RFQ, this field references to its Purchases Order",
)
quotation_state = fields.Selection(
selection=[
("draft", "Draft"),
("sent", "Mail Sent"),
("cancel", "Cancelled"),
("done", "Done"),
],
string="RFQ Status",
readonly=True,
related="state",
help="Only relative RFQ states",
)

@api.model
def create(self, vals):
order_sequence = vals.get("order_sequence") or self.env.context.get(
"order_sequence"
)
if not order_sequence and vals.get("name", "/") == "/":
vals["name"] = self.env["ir.sequence"].next_by_code("purchase.rfq") or "/"
return super().create(vals)

def _prepare_order_from_quotation(self):
return {
"name": self.env["ir.sequence"].next_by_code("purchase.order") or "/",
"order_sequence": True,
"quote_id": self.id,
"partner_ref": self.partner_ref,
}

def action_convert_to_order(self):
self.ensure_one()
if self.order_sequence:
raise UserError(_("Only quotation can convert to order"))
order = self.copy(self._prepare_order_from_quotation())
# Reference from this RFQ to order
self.order_id = order.id
if self.state == "draft":
self.button_done()
return self.open_duplicated_purchase_order()

@api.model
def open_duplicated_purchase_order(self):
return {
"name": _("Purchases Order"),
"view_mode": "form",
"view_id": False,
"res_model": "purchase.order",
"context": {"default_order_sequence": True, "order_sequence": True},
"type": "ir.actions.act_window",
"nodestroy": True,
"target": "current",
"domain": "[('order_sequence', '=', True)]",
"res_id": self.order_id and self.order_id.id or False,
}
1 change: 1 addition & 0 deletions purchase_isolated_rfq/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Rattapong Chokmasermkul <rattapongc@ecosoft.co.th>
12 changes: 12 additions & 0 deletions purchase_isolated_rfq/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Base on sale_isolated_quotation

In some countries/companies, It's already common to separate these two documents.
For filing purposes, the document sequence of Requests For Quotation (RFQ) and Purchases order
has to be separated. In practice, there could be multiple RFQ open
to a vendor, yet only one RFQ get converted to the Purchases order.

This module separate RFQ and Purchases order by adding order_sequence flag in
purchase.order model.

Each type of document will have separated sequence numbering.
RFQ will have only 2 state, Draft and Done. Purchases Order work as normal.
2 changes: 2 additions & 0 deletions purchase_isolated_rfq/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Create RFQ as normal
* As user click "Convert to Order", the isolated purchases order will be created
Loading

0 comments on commit 9c9db37

Please sign in to comment.