Skip to content

Commit

Permalink
[11.0][MIG] purchase_date_planned_manual
Browse files Browse the repository at this point in the history
  • Loading branch information
LoisRForgeFlow authored and JordiBForgeFlow committed Nov 9, 2018
1 parent 933977c commit a266f4a
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 98 deletions.
73 changes: 50 additions & 23 deletions purchase_date_planned_manual/README.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

============================
Purchase Date Planned Manual
============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png
:target: https://odoo-community.org/page/development-status
:alt: Mature
.. |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/11.0/purchase_date_planned_manual
:alt: OCA/purchase-workflow
.. |badge4| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/142/11.0
:alt: Try me on Runbot

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

This module makes the system to always respect the planned (or scheduled)
date set by the user when creating a Purchase order or the day set in the
procurement order if the line is created from there.
date set by the user when creating a Purchase Order.

Additionally, this module modifies the PO views and sets in red the lines
that are predicted to arrive late compared to the scheduled date and vendor
lead time.

**Table of contents**

.. contents::
:local:

Usage
=====

Expand All @@ -32,42 +52,49 @@ Or:
#. Now the scheduled date in the procurement is respected even if the line is
added to a previously existing PO.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/142/10.0

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 smash it by providing detailed and welcomed feedback.
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.

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

Credits
=======

Images
------
Authors
~~~~~~~

* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
* Eficent

Contributors
------------
~~~~~~~~~~~~

* Lois Rilo <[email protected]>

Maintainer
----------
Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

To contribute to this module, please visit https://odoo-community.org.
.. |maintainer-lreficent| image:: https://github.com/lreficent.png?size=40px
:target: https://github.com/lreficent
:alt: lreficent

Current `maintainer <https://odoo-community.org/page/maintainer-role>`_:

|maintainer-lreficent|

This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/11.0/purchase_date_planned_manual>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 0 additions & 5 deletions purchase_date_planned_manual/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import models
7 changes: 4 additions & 3 deletions purchase_date_planned_manual/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
Expand All @@ -7,11 +6,13 @@
"name": "Purchase Date Planned Manual",
"summary": "This module makes the system to always respect the planned "
"(or scheduled) date in PO lines.",
"version": "10.0.1.0.0",
"version": "11.0.1.0.0",
"development_status": "Mature",
"author": "Eficent, "
"Odoo Community Association (OCA)",
"maintainers": ["lreficent"],
"website": "https://github.com/OCA/purchase-workflow",
"category": "Purchases",
"category": "Purchase Management",
"depends": ["purchase"],
"data": [
'views/purchase_order_view.xml',
Expand Down
6 changes: 0 additions & 6 deletions purchase_date_planned_manual/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import purchase_order
from . import procurement_order
19 changes: 0 additions & 19 deletions purchase_date_planned_manual/models/procurement_order.py

This file was deleted.

8 changes: 5 additions & 3 deletions purchase_date_planned_manual/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from dateutil.relativedelta import relativedelta
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.fields import Datetime as Dt


class PurchaseOrderLine(models.Model):
Expand Down Expand Up @@ -48,5 +48,7 @@ def _get_date_planned(self, seller, po=False):

@api.multi
def action_delayed_line(self):
raise UserError(_('This line is scheduled for: %s. \n However it is '
'now planned to arrive late.') % self.date_planned)
raise UserError(_(
'This line is scheduled for: %s. \n However it is now planned to '
'arrive late.') % Dt.to_string(Dt.context_timestamp(
self, Dt.from_string(self.date_planned))))
1 change: 1 addition & 0 deletions purchase_date_planned_manual/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Lois Rilo <[email protected]>
6 changes: 6 additions & 0 deletions purchase_date_planned_manual/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This module makes the system to always respect the planned (or scheduled)
date set by the user when creating a Purchase Order.

Additionally, this module modifies the PO views and sets in red the lines
that are predicted to arrive late compared to the scheduled date and vendor
lead time.
14 changes: 14 additions & 0 deletions purchase_date_planned_manual/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
To use this module you could follow any of the two options below:

#. Go to 'Purchase' and create a purchase order.
#. Manually set the scheduled date in the PO lines.
#. This date will never be modified by the system and the lines that are
expected to be late are highlighted in red.

Or:

#. Create a procurement order for a product that can be bought and have the
route 'buy' activated.
#. Run the procurement.
#. Now the scheduled date in the procurement is respected even if the line is
added to a previously existing PO.
4 changes: 0 additions & 4 deletions purchase_date_planned_manual/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_date_planned_manual
35 changes: 4 additions & 31 deletions purchase_date_planned_manual/tests/test_date_planned_manual.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand All @@ -13,7 +12,7 @@ def setUp(self, *args, **kwargs):
super(TestDatePlannedManual, self).setUp(*args, **kwargs)
self.po_model = self.env['purchase.order']
self.pol_model = self.env['purchase.order.line']
self.proc_model = self.env['procurement.order']
self.pp_model = self.env['product.product']
# Create some partner, products and supplier info:
route_buy_id = self.env.ref('purchase.route_warehouse0_buy').id
self.partner = self.env['res.partner'].create({
Expand All @@ -24,28 +23,22 @@ def setUp(self, *args, **kwargs):
'name': self.partner.id,
'delay': 2,
}).id
self.product_1 = self.env['product.product'].create({
self.product_1 = self.pp_model.create({
'name': 'Test product 1',
'type': 'product',
'route_ids': [(4, route_buy_id)],
'seller_ids': [(4, supplier_info_id)],
})
self.product_2 = self.env['product.product'].create({
self.product_2 = self.pp_model.create({
'name': 'Test product 2',
'type': 'product',
})
# Create purchase order and dates
self.purchase_order = self.env['purchase.order'].create({
self.purchase_order = self.po_model.create({
'partner_id': self.partner.id,
})
next_week_time = datetime.now() + timedelta(days=7)
self.next_week_time = fields.Datetime.to_string(next_week_time)
# Create a warehouse
self.test_warehouse = self.env['stock.warehouse'].create({
'name': 'Test Warehouse',
'code': 'T-WH',
})
self.test_location = self.test_warehouse.lot_stock_id

def test_manually_set_pol_date(self):
"""Tests the manual modification of scheduled date in purchase order
Expand Down Expand Up @@ -82,23 +75,3 @@ def test_manually_set_pol_date(self):
"state 'draft'.")
with self.assertRaises(UserError):
po_line_1.action_delayed_line()

def test_po_created_from_procurements(self):
"""Tests the purchase order lines created from procurement orders."""
proc = self.proc_model.create({
'name': 'test',
'product_id': self.product_1.id,
'product_qty': 5.0,
'product_uom': self.product_1.uom_id.id,
'warehouse_id': self.test_warehouse.id,
'location_id': self.test_location.id,
'date_planned': self.next_week_time,
})
self.assertEqual(proc.state, 'running',
"Procurement has not run correctly.")
self.assertTrue(proc.purchase_id,
"No purchase order created from procurement.")
pol_date = proc.purchase_id.order_line.date_planned
self.assertEqual(pol_date, self.next_week_time,
"Dates in procurement a purchase order line does not "
"match.")
6 changes: 2 additions & 4 deletions purchase_date_planned_manual/views/purchase_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

<odoo>
<record id="view_purchase_order_form" model="ir.ui.view">
<field name="name">purchase.order.form - purchase_date_planned_manual
extension</field>
<field name="name">purchase.order.form - purchase_date_planned_manual</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
Expand All @@ -18,8 +17,7 @@
icon="fa-exclamation-triangle"/>
</xpath>
<xpath expr="//field[@name='order_line']/tree" position="attributes">
<attribute name="decoration-danger">predicted_arrival_late
is True</attribute>
<attribute name="decoration-danger">predicted_arrival_late is True</attribute>
</xpath>
</field>
</record>
Expand Down

0 comments on commit a266f4a

Please sign in to comment.