Skip to content

Commit

Permalink
[10.0][ADD] purchase_request_comment module
Browse files Browse the repository at this point in the history
  • Loading branch information
AdriaGForgeFlow authored and AaronHForgeFlow committed Apr 17, 2019
1 parent 3b2a98e commit f7a81e9
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 0 deletions.
34 changes: 34 additions & 0 deletions purchase_request_comment/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License AGPL-3

=========================
Purchase Request Comments
=========================
This module propagates internal comments from Purchase Request to Purchase Orders, appending them if the Purchase
Request Lines come from different Purchase Request.

Usage
=====

* Create a PO from one or multiple purchse request lines

Credits
=======

Contributors
------------

* Adria Gil Sorribes <[email protected]>


Maintainer
----------

.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://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.

3 changes: 3 additions & 0 deletions purchase_request_comment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import models
from . import wizard
from . import tests
19 changes: 19 additions & 0 deletions purchase_request_comment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Purchase Request Comment",
"version": "10.0.1.0.0",
"author": "Eficent",
'license': 'AGPL-3',
"website": "www.eficent.com",
"category": "Purchase Management",
"depends": ["purchase_request_to_rfq", "purchase_comment_template"],
"summary": """
Link from sales to Purchase Requests
""",
"data": [
"views/purchase_request_views.xml",
"views/purchase_views.xml"
],
'installable': True,
}
2 changes: 2 additions & 0 deletions purchase_request_comment/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import purchase
from . import purchase_request
15 changes: 15 additions & 0 deletions purchase_request_comment/models/purchase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).

from odoo import fields, models


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

internal_comments = fields.Text(
string='Internal Comments',
help="These comments come from the Purchase Request and are "
"internal and merely informative."
)
15 changes: 15 additions & 0 deletions purchase_request_comment/models/purchase_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).

from odoo import fields, models


class PurchaseRequest(models.Model):
_inherit = 'purchase.request'

internal_comments = fields.Text(
string='Internal Comments',
help="These comments will be propagated to the Purchase Order. "
"Text introduced here is internal and merely informative."
)
1 change: 1 addition & 0 deletions purchase_request_comment/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_purchase_request_to_rfq
47 changes: 47 additions & 0 deletions purchase_request_comment/tests/test_purchase_request_to_rfq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).

from odoo.tests import common
from odoo.tools import SUPERUSER_ID


class TestPurchaseRequestToRfq(common.TransactionCase):

def setUp(self):
super(TestPurchaseRequestToRfq, self).setUp()
self.purchase_request = self.env['purchase.request']
self.purchase_request_line = self.env['purchase.request.line']
self.wiz =\
self.env['purchase.request.line.make.purchase.order']
self.purchase_order = self.env['purchase.order']

def test_purchase_request_to_purchase_rfq(self):
vals = {
'picking_type_id': self.env.ref('stock.picking_type_in').id,
'requested_by': SUPERUSER_ID,
'internal_comments': 'This is an internal comment in purchase '
'request 1',
}
purchase_request = self.purchase_request.create(vals)
vals = {
'request_id': purchase_request.id,
'product_id': self.env.ref('product.product_product_13').id,
'product_uom_id': self.env.ref('product.product_uom_unit').id,
'product_qty': 5.0,
}
purchase_request_line = self.purchase_request_line.create(vals)
purchase_request.button_to_approve()
purchase_request.button_approved()

vals = {
'supplier_id': self.env.ref('base.res_partner_12').id,
}
wiz_id = self.wiz.with_context(
active_model="purchase.request.line",
active_ids=[purchase_request_line.id],
active_id=purchase_request_line.id,).create(vals)
wiz_id.make_purchase_order()
self.assertTrue(
purchase_request_line.purchase_lines.order_id.internal_comments,
'Comment should have been propagated')
19 changes: 19 additions & 0 deletions purchase_request_comment/views/purchase_request_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!-- Copyright 2019 Eficent Business and IT Consulting Services S.L.
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
<odoo>

<record model="ir.ui.view" id="view_purchase_request_form">
<field name="name">purchase.request.form</field>
<field name="model">purchase.request</field>
<field name="inherit_id" ref="purchase_request.view_purchase_request_form"/>
<field name="arch" type="xml">
<field name="line_ids" position="after">
<group name="internal_comments" string="Internal Comments">
<field name="internal_comments" nolabel="1" placeholder="Place here any internal comment needed. These comments will be propagated to the Purchase Order."/>
</group>
</field>
</field>
</record>

</odoo>
22 changes: 22 additions & 0 deletions purchase_request_comment/views/purchase_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<!-- Copyright 2019 Eficent Business and IT Consulting Services S.L.
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
<odoo>

<record model="ir.ui.view" id="purchase_order_form_add_comment">
<field name="name">comment_template.purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase_comment_template.purchase_order_form_add_comment"/>
<field name="arch" type="xml">
<xpath expr="//notebook//page[@name='comments']" position="after">
<page string="Internal Comments" name="internal_comments">
<p style="margin-top: 10px;">The comments are internal and merely informative.</p>
<group name="internal_comments" string="Comments from Purchase Request">
<field name="internal_comments" nolabel="1" placeholder="Insert here internal informative comments for users."/>
</group>
</page>
</xpath>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions purchase_request_comment/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import purchase_request_line_make_purchase_order
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).

from odoo import api, models


class PurchaseRequestLineMakePurchaseOrder(models.TransientModel):
_inherit = "purchase.request.line.make.purchase.order"

@api.multi
def make_purchase_order(self):
res = super(PurchaseRequestLineMakePurchaseOrder,
self).make_purchase_order()
for po_id in set(res.get('domain')[0][2]):
purchase = self.env['purchase.order'].browse(po_id)
po_comment = purchase.internal_comments
purchase_requests = self.item_ids.mapped('request_id')
for pr in purchase_requests:
if pr.internal_comments:
if not po_comment:
po_comment = "Purchase Request [%s]: %s" % (
pr.name, pr.internal_comments)
else:
po_comment = "%s\nPurchase Request [%s]: %s" % (
po_comment, pr.name, pr.internal_comments)
purchase.internal_comments = po_comment
return res

0 comments on commit f7a81e9

Please sign in to comment.