[10.0][ADD] stock_orderpoint_manual_procurement_uom

This commit is contained in:
lreficent
2018-01-02 13:53:01 +01:00
committed by Miquel Raïch
parent b02ab84a65
commit 8bce7462cc
10 changed files with 283 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=======================================
Stock Orderpoint Manual Procurement UoM
=======================================
Glue module for ``stock_orderpoint_uom`` and
``stock_orderpoint_manual_procurement``
Usage
=====
The recommended quantity to procure is adjusted to the procurement unit of
measure indicated in the reordering rule.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/153/10.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/stock-logistics-warehouse/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.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Lois Rilo Antelo <lois.rilo@eficent.com>
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.
To contribute to this module, please visit https://odoo-community.org.

View File

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models
from . import wizards

View File

@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright 2018 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).
{
"name": "Stock Orderpoint Manual Procurement UoM",
"summary": "Glue module for stock_orderpoint_uom and "
"stock_orderpoint_manual_procurement",
"version": "10.0.1.0.0",
"author": "Eficent, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse Management",
"depends": [
"stock_orderpoint_uom",
"stock_orderpoint_manual_procurement",
],
"data": [],
"license": "AGPL-3",
'installable': True,
'application': False,
'auto-install': True,
}

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import stock_warehouse_orderpoint

View File

@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2018 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 odoo import api, models
class StockWarehouseOrderpoint(models.Model):
_inherit = 'stock.warehouse.orderpoint'
@api.multi
def _get_procure_recommended_qty(self, virtual_qty, op_qtys):
procure_recommended_qty = \
super(StockWarehouseOrderpoint, self)._get_procure_recommended_qty(
virtual_qty, op_qtys)
if self.procure_uom_id:
product_qty = self.product_id.uom_id._compute_quantity(
procure_recommended_qty, self.procure_uom_id)
else:
product_qty = procure_recommended_qty
return product_qty

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import test_stock_orderpoint_manual_procurement

View File

@@ -0,0 +1,133 @@
# -*- coding: utf-8 -*-
# Copyright 2018 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 odoo.tests import common
class TestStockWarehouseOrderpoint(common.TransactionCase):
def setUp(self):
super(TestStockWarehouseOrderpoint, self).setUp()
# Refs
self.group_stock_manager = self.env.ref('stock.group_stock_manager')
self.group_change_procure_qty = self.env.ref(
'stock_orderpoint_manual_procurement.'
'group_change_orderpoint_procure_qty')
self.company1 = self.env.ref('base.main_company')
# Get required Model
self.reordering_rule_model = self.env['stock.warehouse.orderpoint']
self.product_model = self.env['product.product']
self.user_model = self.env['res.users']
self.product_ctg_model = self.env['product.category']
self.stock_change_model = self.env['stock.change.product.qty']
self.make_procurement_orderpoint_model =\
self.env['make.procurement.orderpoint']
# Create users
self.user = self._create_user('user_1',
[self.group_stock_manager,
self.group_change_procure_qty],
self.company1)
# Get required Model data
self.product_uom = self.env.ref('product.product_uom_unit')
self.location = self.env.ref('stock.stock_location_stock')
self.product = self.env.ref('product.product_product_7')
self.dozen = self.env.ref('product.product_uom_dozen')
# Create Product category and Product
self.product_ctg = self._create_product_category()
self.product = self._create_product()
# Add default quantity
quantity = 20.00
self._update_product_qty(self.product, self.location, quantity)
# Create Reordering Rule
self.reorder = self.create_orderpoint()
def _create_user(self, login, groups, company):
""" Create a user."""
group_ids = [group.id for group in groups]
user = \
self.user_model.with_context({'no_reset_password': True}).create({
'name': 'Test User',
'login': login,
'password': 'demo',
'email': 'test@yourcompany.com',
'company_id': company.id,
'company_ids': [(4, company.id)],
'groups_id': [(6, 0, group_ids)]
})
return user
def _create_product_category(self):
"""Create a Product Category."""
product_ctg = self.product_ctg_model.create({
'name': 'test_product_ctg',
'type': 'normal',
})
return product_ctg
def _create_product(self):
"""Create a Product."""
product = self.product_model.create({
'name': 'Test Product',
'categ_id': self.product_ctg.id,
'type': 'product',
'uom_id': self.product_uom.id,
})
return product
def _update_product_qty(self, product, location, quantity):
"""Update Product quantity."""
change_product_qty = self.stock_change_model.create({
'location_id': location.id,
'product_id': product.id,
'new_quantity': quantity,
})
change_product_qty.change_product_qty()
return change_product_qty
def create_orderpoint(self):
"""Create a Reordering Rule"""
reorder = self.reordering_rule_model.sudo(self.user).create({
'name': 'Order-point',
'product_id': self.product.id,
'product_min_qty': 100.0,
'product_max_qty': 500.0,
'qty_multiple': 1.0,
'procure_uom_id': self.dozen.id,
})
return reorder
def create_orderpoint_procurement(self):
"""Make Procurement from Reordering Rule"""
context = {
'active_model': 'stock.warehouse.orderpoint',
'active_ids': self.reorder.ids,
'active_id': self.reorder.id
}
wizard = self.make_procurement_orderpoint_model.sudo(self.user).\
with_context(context).create({})
wizard.make_procurement()
return wizard
def test_security(self):
"""Test Manual Procurement created from Order-Point"""
# Create Manual Procurement from order-point procured quantity
self.create_orderpoint_procurement()
# Assert that Procurement is created with the desired quantity
self.assertTrue(self.reorder.procurement_ids)
self.assertEqual(self.reorder.product_id.id,
self.reorder.procurement_ids.product_id.id)
self.assertEqual(self.reorder.name,
self.reorder.procurement_ids.origin)
self.assertNotEqual(self.reorder.procure_recommended_qty,
self.reorder.procurement_ids.product_qty)
self.assertEqual(self.reorder.procurement_ids.product_qty, 40)

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import make_procurement_orderpoint

View File

@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Copyright 2018 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 odoo import api, models
class MakeProcurementOrderpoint(models.TransientModel):
_inherit = 'make.procurement.orderpoint'
@api.model
def _prepare_item(self, orderpoint):
vals = super(MakeProcurementOrderpoint, self)._prepare_item(orderpoint)
if orderpoint.procure_uom_id:
product_uom = orderpoint.procure_uom_id
vals['uom_id'] = product_uom.id
return vals
class MakeProcurementOrderpointItem(models.TransientModel):
_inherit = 'make.procurement.orderpoint.item'
@api.multi
@api.onchange('uom_id')
def onchange_uom_id(self):
for rec in self:
uom = rec.orderpoint_id.procure_uom_id or \
rec.orderpoint_id.product_uom
rec.qty = uom._compute_quantity(
rec.orderpoint_id.procure_recommended_qty,
rec.uom_id)