forked from OCA/purchase-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e56d6c2
commit aa9ff22
Showing
18 changed files
with
350 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2021 ProThai Technology Co.,Ltd. (http://prothaitechnology.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Purchase For Quotation Numeration", | ||
"summary": "Different sequence for purchase for quotations", | ||
"version": "14.0.1.0.0", | ||
"author": "ProThai, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"category": "Purchase Management", | ||
"depends": ["purchase"], | ||
"website": "https://github.com/OCA/purchase-workflow", | ||
"data": [ | ||
"data/ir_sequence_data.xml", | ||
"reports/purchase_report_templates.xml", | ||
"views/res_config_settings_views.xml", | ||
"views/purchase_views.xml", | ||
], | ||
"maintainer": ["prapassornS"], | ||
"installable": True, | ||
"auto_install": False, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import res_company | ||
from . import purchase_order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright 2021 ProThai Technology Co.,Ltd. (http://prothaitechnology.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
import base64 | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class PurchaseOrder(models.Model): | ||
_inherit = "purchase.order" | ||
|
||
rfq_number = fields.Char( | ||
string="RFQ Reference", | ||
index=True, | ||
copy=False, | ||
default="New", | ||
) | ||
|
||
@api.model | ||
def create(self, vals): | ||
|
||
if "company_id" in vals: | ||
keep_name_po = ( | ||
self.env["res.company"].browse(vals.get("company_id")).keep_name_po | ||
) | ||
else: | ||
keep_name_po = self.env.company.keep_name_po | ||
|
||
if not keep_name_po and vals.get("name", "New") == "New": | ||
vals["name"] = self.env["ir.sequence"].next_by_code("purchase.rfq") or "New" | ||
|
||
return super().create(vals) | ||
|
||
def button_confirm(self): | ||
for order in self: | ||
if order.state in ["draft", "sent"] and not order.company_id.keep_name_po: | ||
if order.company_id.auto_attachment_rfq: | ||
# save rfq pdf as attachment | ||
order.action_get_rfq_attachment() | ||
|
||
order.write( | ||
{ | ||
"rfq_number": order.name, | ||
"name": self.env["ir.sequence"].next_by_code("purchase.order"), | ||
} | ||
) | ||
|
||
return super().button_confirm() | ||
|
||
def action_get_rfq_attachment(self): | ||
rfq_pdf = self.env.ref("purchase.report_purchase_quotation")._render_qweb_pdf( | ||
self.id | ||
)[0] | ||
return self.env["ir.attachment"].create( | ||
{ | ||
"name": "{}.pdf".format(self.name), | ||
"type": "binary", | ||
"datas": base64.encodebytes(rfq_pdf), | ||
"res_model": self._name, | ||
"res_id": self.id, | ||
} | ||
) | ||
|
||
def button_draft(self): | ||
for rec in self.filtered(lambda l: l.rfq_number != "New"): | ||
rec.name = rec.rfq_number | ||
return super().button_draft() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2021 ProThai Technology Co.,Ltd. (http://prothaitechnology.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
keep_name_po = fields.Boolean( | ||
string="Use Same Enumeration", | ||
help="If this is unchecked, purchase rfq use a different sequence from " | ||
"Purchase orders", | ||
default=True, | ||
) | ||
auto_attachment_rfq = fields.Boolean( | ||
string="Auto Attachment RFQ", | ||
help="Auto attachment requests for quotation after confirm", | ||
default=False, | ||
) | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
keep_name_po = fields.Boolean(related="company_id.keep_name_po", readonly=False) | ||
auto_attachment_rfq = fields.Boolean( | ||
related="company_id.auto_attachment_rfq", readonly=False | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
To configure this module, you need to: | ||
|
||
* Go to **Purchases -> Configuration and uncheck 'Use same enumeration for purchase rfq and purchase orders'.** | ||
* Go to **Purchases -> Configuration and check 'Auto attachment requests for quotation after confirm'.** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Prapassorn Sornkaew <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Note: This module is similar to sale_quotation_number, but for purchase/rfq | ||
|
||
* Purchase for Quotation: | ||
|
||
* Purchase process in draft stage just informing prices and element of communication. | ||
|
||
* Purchase Order: | ||
|
||
* Purchase process confirmed, the customer already have a compromise with us in terms of pay an invoice and receive our product or service. | ||
|
||
**Technical Explanation** | ||
|
||
When you create a purchase quotation, it is numbered using the 'purchase.rfq' | ||
sequence. When you confirm a purchase quotation, its rfq number is saved in the | ||
'rfq_number' field and the purchase order gets a new number, retrieving it from | ||
'purchase.order' sequence. | ||
|
||
* With Odoo Base: | ||
|
||
Purchase for Quotation 1 Number = PO001 | ||
|
||
Purchase for Quotation 2 Number = PO002 | ||
|
||
* With Odoo + This Module: | ||
|
||
Purchase for Quotation 1 Number = RFQ001 | ||
|
||
Purchase for Quotation 2 Number = RFQ002 | ||
|
||
Purchase for Quotation 1 Confirmed = Number for Purchase Order PO001 from Purchase for Quotation RFQ001 | ||
|
||
Purchase for Quotation 2 Confirmed = Number for Purchase Order PO002 from Purchase for Quotation RFQ002 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<template | ||
id="report_purchasequotation_document" | ||
inherit_id="purchase.report_purchasequotation_document" | ||
> | ||
<xpath expr="//span[@t-field='o.name']" position="replace"> | ||
<t t-if="o.rfq_number != 'New'"> | ||
<span t-field="o.rfq_number" /> | ||
</t> | ||
<t t-else=""> | ||
<span t-field="o.name" /> | ||
</t> | ||
</xpath> | ||
</template> | ||
|
||
</odoo> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import test_purchase_order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Copyright 2021 ProThai Technology Co.,Ltd. (http://prothaitechnology.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.exceptions import UserError | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestPurchaseOrder(TransactionCase): | ||
def setUp(self, *args, **kwargs): | ||
super(TestPurchaseOrder, self).setUp() | ||
self.purchase_order_model = self.env["purchase.order"] | ||
company = self.env.company | ||
company.keep_name_po = False | ||
company.auto_attachment_rfq = True | ||
|
||
def test_enumeration(self): | ||
order1 = self.purchase_order_model.create( | ||
{"partner_id": self.env.ref("base.res_partner_1").id} | ||
) | ||
|
||
purchase_for_quotation1_name = order1.name | ||
order2 = self.purchase_order_model.create( | ||
{"partner_id": self.env.ref("base.res_partner_1").id} | ||
) | ||
purchase_for_quotation2_name = order2.name | ||
|
||
self.assertRegex(purchase_for_quotation1_name, "RFQ") | ||
self.assertRegex(purchase_for_quotation2_name, "RFQ") | ||
self.assertLess( | ||
int(purchase_for_quotation1_name[4:]), int(purchase_for_quotation2_name[4:]) | ||
) | ||
|
||
order2.button_confirm() | ||
order1.button_confirm() | ||
|
||
self.assertRegex(order1.name, "P") | ||
self.assertEqual(order1.rfq_number, purchase_for_quotation1_name) | ||
|
||
self.assertRegex(order2.name, "P") | ||
self.assertEqual(order2.rfq_number, purchase_for_quotation2_name) | ||
self.assertLess(int(order2.name[3:]), int(order1.name[3:])) | ||
|
||
def test_with_rfq_number(self): | ||
rfq_number = "rfq_number" | ||
order1 = self.purchase_order_model.create( | ||
{ | ||
"rfq_number": rfq_number, | ||
"partner_id": self.env.ref("base.res_partner_1").id, | ||
} | ||
) | ||
purchase_for_quotation1_name = order1.name | ||
order1.button_confirm() | ||
|
||
self.assertRegex(order1.name, "P") | ||
self.assertEqual(order1.rfq_number, purchase_for_quotation1_name) | ||
|
||
def test_error_confirmation_sequence(self): | ||
order = self.purchase_order_model.create( | ||
{ | ||
"partner_id": self.env.ref("base.res_partner_1").id, | ||
"state": "done", | ||
} | ||
) | ||
sequence_id = self.env["ir.sequence"].search( | ||
[ | ||
("code", "=", "purchase.order"), | ||
("company_id", "in", [order.company_id.id, False]), | ||
] | ||
) | ||
next_name = sequence_id.get_next_char(sequence_id.number_next_actual) | ||
try: | ||
order.button_confirm() | ||
except UserError: | ||
pass | ||
order.update({"state": "draft"}) | ||
# Now the RFQ can be confirmed | ||
order.button_confirm() | ||
self.assertEqual(next_name, order.name) | ||
|
||
def test_auto_attachment_rfq(self): | ||
order = self.purchase_order_model.create( | ||
{ | ||
"partner_id": self.env.ref("base.res_partner_1").id, | ||
"state": "draft", | ||
} | ||
) | ||
order.button_confirm() | ||
attachment = self.env["ir.attachment"].search( | ||
[("res_model", "=", "purchase.order"), ("res_id", "=", order.id)] | ||
) | ||
self.assertEqual(attachment.res_id, order.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<odoo> | ||
<record id="purchase_order_form" model="ir.ui.view"> | ||
<field name="name">purchase.order.form</field> | ||
<field name="model">purchase.order</field> | ||
<field name="inherit_id" ref="purchase.purchase_order_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="company_id" position="after"> | ||
<field | ||
name="rfq_number" | ||
attrs="{'invisible': ['|', ('rfq_number', '=', 'New'), ('state','not in',('purchase','done'))]}" | ||
/> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2021 ProThai Technology Co.,Ltd. (http://prothaitechnology.com) | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record id="res_config_settings_view_form_purchase_rfq_number" model="ir.ui.view"> | ||
<field name="name">Purchase RFQ number configuration</field> | ||
<field name="model">res.config.settings</field> | ||
<field | ||
name="inherit_id" | ||
ref="purchase.res_config_settings_view_form_purchase" | ||
/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='group_send_reminder']/../.." position="after"> | ||
<div class="col-12 col-lg-6 o_setting_box"> | ||
<div class="o_setting_left_pane"> | ||
<field name="keep_name_po" /> | ||
</div> | ||
<div class="o_setting_right_pane"> | ||
<label for="keep_name_po" /> | ||
<div class="text-muted"> | ||
If this is unchecked, purchase rfq use a different sequence from purchase orders | ||
</div> | ||
</div> | ||
</div> | ||
<div | ||
class="col-12 col-lg-6 o_setting_box" | ||
attrs="{'invisible': [('keep_name_po', '=', True)]}" | ||
> | ||
<div class="o_setting_left_pane"> | ||
<field name="auto_attachment_rfq" /> | ||
</div> | ||
<div class="o_setting_right_pane"> | ||
<label for="auto_attachment_rfq" /> | ||
<div class="text-muted"> | ||
Auto attachment requests for quotation after confirm | ||
</div> | ||
</div> | ||
</div> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../purchase_rfq_number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |