[IMP] stock_request_purchase: Add Stock request orders. Change logo

This commit is contained in:
Enric Tobella
2018-04-10 17:54:27 +02:00
committed by Jesús Alan Ramos Rodríguez
parent e8cd399c02
commit c5b320146d
8 changed files with 118 additions and 25 deletions

View File

@@ -46,6 +46,7 @@ Contributors
------------
* Jordi Ballester <jordi.ballester@eficent.com>.
* Enric Tobella <etobella@creublanca.es>
Maintainer
----------

View File

@@ -4,7 +4,7 @@
{
"name": "Stock Request Purchase",
"summary": "Internal request for stock",
"version": "11.0.1.1.0",
"version": "11.0.2.0.0",
"license": "LGPL-3",
"website": "https://github.com/stock-logistics-warehouse",
"author": "Eficent, "
@@ -17,6 +17,7 @@
"data": [
"security/ir.model.access.csv",
"views/stock_request_views.xml",
"views/stock_request_order_views.xml",
"views/purchase_order_views.xml",
],
"installable": True,

View File

@@ -3,3 +3,4 @@ from . import purchase_order
from . import purchase_order_line
from . import procurement_rule
from . import stock_request
from . import stock_request_order

View File

@@ -9,7 +9,7 @@ class StockRequest(models.Model):
purchase_ids = fields.One2many('purchase.order',
compute='_compute_purchase_ids',
string='Pickings', readonly=True)
string='Purchase Orders', readonly=True)
purchase_count = fields.Integer(string='Purchase count',
compute='_compute_purchase_ids',
readonly=True)

View File

@@ -0,0 +1,40 @@
# Copyright 2018 Creu Blanca
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models
class StockRequestOrder(models.Model):
_inherit = 'stock.request.order'
purchase_ids = fields.One2many('purchase.order',
compute='_compute_purchase_ids',
string='Purchase Orders', readonly=True)
purchase_count = fields.Integer(string='Purchase count',
compute='_compute_purchase_ids',
readonly=True)
purchase_line_ids = fields.Many2many('purchase.order.line',
compute='_compute_purchase_ids',
string='Purchase Order Lines',
readonly=True, copy=False)
@api.depends('stock_request_ids')
def _compute_purchase_ids(self):
for req in self.sudo():
req.purchase_ids = req.stock_request_ids.mapped('purchase_ids')
req.purchase_line_ids = req.stock_request_ids.mapped(
'purchase_line_ids')
req.purchase_count = len(req.purchase_ids)
@api.multi
def action_view_purchase(self):
action = self.env.ref(
'purchase.purchase_order_action_generic').read()[0]
purchases = self.mapped('purchase_ids')
if len(purchases) > 1:
action['domain'] = [('id', 'in', purchases.ids)]
elif purchases:
action['views'] = [
(self.env.ref('purchase.purchase_order_form').id, 'form')]
action['res_id'] = purchases.id
return action

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

@@ -74,44 +74,54 @@ class TestStockRequestPurchase(common.TransactionCase):
def test_create_request_01(self):
"""Single Stock request with buy rule"""
vals = {
'company_id': self.main_company.id,
'warehouse_id': self.warehouse.id,
'location_id': self.warehouse.lot_stock_id.id,
'stock_request_ids': [(0, 0, {
'product_id': self.product.id,
'product_uom_id': self.product.uom_id.id,
'product_uom_qty': 5.0,
'company_id': self.main_company.id,
'warehouse_id': self.warehouse.id,
'location_id': self.warehouse.lot_stock_id.id,
})]
}
stock_request = self.stock_request.sudo(
order = self.env['stock.request.order'].sudo(
self.stock_request_user).create(vals)
stock_request.action_confirm()
self.assertEqual(stock_request.state, 'open')
order.action_confirm()
self.assertEqual(order.state, 'open')
self.assertEqual(order.stock_request_ids.state, 'open')
stock_request.refresh()
order.refresh()
self.assertEqual(len(stock_request.sudo().purchase_ids), 1)
self.assertEqual(len(stock_request.picking_ids), 0)
self.assertEqual(len(stock_request.move_ids), 0)
self.assertEqual(stock_request.qty_in_progress, 0.0)
self.assertEqual(len(order.sudo().purchase_ids), 1)
self.assertEqual(len(order.picking_ids), 0)
self.assertEqual(len(order.move_ids), 0)
self.assertEqual(len(order.stock_request_ids.sudo().purchase_ids), 1)
self.assertEqual(len(order.stock_request_ids.picking_ids), 0)
self.assertEqual(len(order.stock_request_ids.move_ids), 0)
self.assertEqual(order.stock_request_ids.qty_in_progress, 0.0)
purchase = stock_request.sudo().purchase_ids[0]
purchase = order.sudo().purchase_ids[0]
purchase.button_confirm()
picking = purchase.picking_ids[0]
picking.action_confirm()
self.assertEqual(stock_request.qty_in_progress, 5.0)
self.assertEqual(stock_request.qty_done, 0.0)
self.assertEqual(order.stock_request_ids.qty_in_progress, 5.0)
self.assertEqual(order.stock_request_ids.qty_done, 0.0)
picking.action_assign()
packout1 = picking.move_line_ids[0]
packout1.qty_done = 5
picking.action_done()
self.assertEqual(stock_request.qty_in_progress, 0.0)
self.assertEqual(stock_request.qty_done,
stock_request.product_uom_qty)
self.assertEqual(stock_request.state, 'done')
self.assertEqual(order.stock_request_ids.qty_in_progress, 0.0)
self.assertEqual(order.stock_request_ids.qty_done,
order.stock_request_ids.product_uom_qty)
self.assertEqual(order.stock_request_ids.state, 'done')
self.assertEqual(order.state, 'done')
def test_create_request_02(self):
"""Multiple Stock requests with buy rule"""
@@ -176,16 +186,24 @@ class TestStockRequestPurchase(common.TransactionCase):
def test_view_actions(self):
vals = {
'company_id': self.main_company.id,
'warehouse_id': self.warehouse.id,
'location_id': self.warehouse.lot_stock_id.id,
'stock_request_ids': [(0, 0, {
'product_id': self.product.id,
'product_uom_id': self.product.uom_id.id,
'product_uom_qty': 5.0,
'company_id': self.main_company.id,
'warehouse_id': self.warehouse.id,
'location_id': self.warehouse.lot_stock_id.id,
})]
}
stock_request = self.stock_request.sudo().create(vals)
stock_request.action_confirm()
order = self.env['stock.request.order'].sudo().create(vals)
order.action_confirm()
stock_request = order.stock_request_ids
action = stock_request.action_view_purchase()
@@ -197,3 +215,9 @@ class TestStockRequestPurchase(common.TransactionCase):
action = stock_request.purchase_ids[0].action_view_stock_request()
self.assertEqual(action['type'], 'ir.actions.act_window')
self.assertEqual(action['res_id'], stock_request.id)
action = order.action_view_purchase()
self.assertEqual(action['domain'], '[]')
self.assertEqual('views' in action.keys(), True)
self.assertEqual(action['res_id'], order.purchase_ids[0].id)

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 Eficent
License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="stock_request_order_form" model="ir.ui.view">
<field name="name">stock.request.order.form</field>
<field name="model">stock.request.order</field>
<field name="inherit_id" ref="stock_request.stock_request_order_form"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<field name="purchase_ids" invisible="1"/>
<button type="object"
name="action_view_purchase"
class="oe_stat_button"
icon="fa-truck"
attrs="{'invisible': [('purchase_count', '=', 0)]}"
groups="purchase.group_purchase_user">
<field name="purchase_count" widget="statinfo"
string="Purchase"/>
</button>
</div>
</field>
</record>
</odoo>