Skip to content

Commit

Permalink
[MIG] purchase_picking_state: Migration to 11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
celm1990 authored and victoralmau committed Mar 10, 2022
1 parent a72cdd3 commit 3b4f2a4
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 90 deletions.
38 changes: 28 additions & 10 deletions purchase_picking_state/README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

===============================
Expand All @@ -11,9 +11,13 @@ This module allows to add picking status on the purchase order
Usage
=====

To use this module, you need to:

#. Go to ...

.. 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/9.0
:target: https://runbot.odoo-community.org/runbot/142/11.0

Bug Tracker
===========
Expand All @@ -25,25 +29,39 @@ help us smashing it by providing a detailed and welcomed `feedback
<https://github.com/OCA/
purchase-workflow/issues/new?body=module:%20
purchase_picking_state%0Aversion:%20
9.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
11.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Credits
=======


Images
------

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

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

* Chafique Delli [email protected]

* Carlos Lopez Mite <[email protected]>

Do not contact contributors directly about help with questions or problems concerning
this addon, but use the `forum <https://www.odoo.com/forum/help-1>`_,
the `community mailing list <mailto:[email protected]>`_,
or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help,
and the bug tracker linked in `Bug Tracker`_ above for technical issues.

Maintainer
----------

.. 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.
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.
To contribute to this module, please visit https://odoo-community.org.
7 changes: 3 additions & 4 deletions purchase_picking_state/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# © 2016 Chafique DELLI @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Copyright 2016 Chafique DELLI @ Akretion
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import purchase
from . import models
24 changes: 11 additions & 13 deletions purchase_picking_state/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
# -*- coding: utf-8 -*-
# © 2016 Chafique DELLI @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Copyright 2016 Chafique DELLI @ Akretion
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
'name': 'Purchase Picking State',
'summary': 'Add the status of all the incoming picking'
' in the purchase order',
'version': '10.0.1.0.0',
'category': 'Purchase Management',
'website': 'http://akretion.com',
'author': 'Akretion',
'version': '11.0.1.0.0',
'author': 'Akretion, '
'Odoo Community Association (OCA)',
'license': 'AGPL-3',
'application': False,
'installable': True,
'category': 'Purchase Management',
'website': 'https://github.com/OCA/purchase-workflow',
'depends': [
'purchase',
],
'data': [
'purchase_view.xml',
]
'views/purchase_view.xml',
],
'installable': True,
}
4 changes: 4 additions & 0 deletions purchase_picking_state/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2016 Chafique DELLI @ Akretion
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import purchase
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# © 2016 Chafique DELLI @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Copyright 2016 Chafique DELLI @ Akretion
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import models, fields, api
from odoo.tools.translate import _


class PurchaseOrder(models.Model):
Expand All @@ -12,10 +12,10 @@ class PurchaseOrder(models.Model):
def get_picking_state(self):
return [
('draft', ''),
('cancel', 'Cancelled'),
('not_received', 'Not Received'),
('partially_received', 'Partially Received'),
('done', 'Transferred'),
('cancel', _('Cancelled')),
('not_received', _('Not Received')),
('partially_received', _('Partially Received')),
('done', _('Transferred')),
]

@api.multi
Expand All @@ -39,6 +39,6 @@ def _compute_picking_state(self):

picking_state = fields.Selection(
string="Picking status", readonly=True,
compute='_compute_picking_state',
compute='_compute_picking_state', store=True,
selection='get_picking_state',
help="Overall status based on all pickings")
30 changes: 0 additions & 30 deletions purchase_picking_state/purchase_view.xml

This file was deleted.

89 changes: 64 additions & 25 deletions purchase_picking_state/tests/test_purchase_picking_state.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,68 @@
# -*- coding: utf-8 -*-
# © 2016 Chafique DELLI @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Copyright 2016 Chafique DELLI @ Akretion
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo.tests.common import TransactionCase
from datetime import datetime

from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT as DTF

from odoo.addons.account.tests.account_test_classes import AccountingTestCase


class TestPurchasePickingState(AccountingTestCase):

def setUp(self):
super(TestPurchasePickingState, self).setUp()
# Useful models
self.PurchaseOrder = self.env['purchase.order']
self.StockPicking = self.env['stock.picking']
self.partner_id = self.env.ref('base.res_partner_1')
self.product_id_1 = self.env.ref('product.product_product_8')
self.product_id_2 = self.env.ref('product.product_product_11')

(self.product_id_1 | self.product_id_2).write({
'purchase_method': 'purchase',
})
self.po_vals = {
'partner_id': self.partner_id.id,
'order_line': [
(0, 0, {
'name': self.product_id_1.name,
'product_id': self.product_id_1.id,
'product_qty': 5.0,
'product_uom': self.product_id_1.uom_po_id.id,
'price_unit': 500.0,
'date_planned': datetime.today().strftime(DTF),
}),
(0, 0, {
'name': self.product_id_2.name,
'product_id': self.product_id_2.id,
'product_qty': 5.0,
'product_uom': self.product_id_2.uom_po_id.id,
'price_unit': 250.0,
'date_planned': datetime.today().strftime(DTF),
})],
}

class TestPurchasePickingState(TransactionCase):
def test_picking_state_in_purchase_order(self):
draft_order_ids = self.env['purchase.order'].search([
('state', 'in', ['draft', 'sent', 'bid', 'cancel']),
])
for purchase in draft_order_ids:
self.assertEquals(purchase.picking_state, 'draft')
confirmed_order_ids = self.env['purchase.order'].search([
('state', 'in', ['confirmed', 'approved', 'done']),
])
for purchase in confirmed_order_ids:
pickings_state = set(
[picking.state for picking in purchase.picking_ids])
if pickings_state == set(['cancel']):
self.assertEquals(purchase.picking_state, 'cancel')
elif (pickings_state == set(['cancel', 'done']) or
pickings_state == set(['done'])):
self.assertEquals(purchase.picking_state, 'done')
elif 'done' in pickings_state:
self.assertEquals(purchase.picking_state, 'partially_received')
else:
self.assertEquals(purchase.picking_state, 'not_received')
self.po = self.PurchaseOrder.create(self.po_vals)
# picking_state equals to draft
self.assertEqual(self.po.picking_state, 'draft')
# confirm po and picking_state equals to not_received
self.po.button_confirm()
self.assertEqual(self.po.picking_state, 'not_received')
# cancel picking and picking_state equals to cancel
self.po.picking_ids.action_cancel()
self.assertEqual(self.po.picking_state, 'cancel')
self.po.button_cancel()
self.po.button_draft()
self.po.button_confirm()
pick = self.po.picking_ids.filtered(
lambda x: x.state not in ('done', 'cancel'))
pick.force_assign()
pick.move_line_ids.write({'qty_done': 2})
pick.action_done()
self.assertEqual(self.po.picking_state, 'partially_received')
backorders = self.StockPicking.search([('backorder_id', '=', pick.id)])
backorders.move_line_ids.write({'qty_done': 3})
backorders.action_done()
self.assertEqual(self.po.picking_state, 'done')
24 changes: 24 additions & 0 deletions purchase_picking_state/views/purchase_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record id="purchase_order_form" model="ir.ui.view">
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<field name="currency_id" position="after">
<field name="picking_state" attrs="{'invisible':[('picking_state','=', 'draft')]}" />
</field>
</field>
</record>

<record id="purchase_order_tree" model="ir.ui.view">
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_tree" />
<field name="arch" type="xml">
<field name="state" position="after">
<field name="picking_state" invisible="not context.get('show_purchase', False)" />
</field>
</field>
</record>

</odoo>

0 comments on commit 3b4f2a4

Please sign in to comment.