mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_request_purchase: Add Stock request orders. Change logo
This commit is contained in:
committed by
Jesús Alan Ramos Rodríguez
parent
e8cd399c02
commit
c5b320146d
@@ -46,6 +46,7 @@ Contributors
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
* Jordi Ballester <jordi.ballester@eficent.com>.
|
* Jordi Ballester <jordi.ballester@eficent.com>.
|
||||||
|
* Enric Tobella <etobella@creublanca.es>
|
||||||
|
|
||||||
Maintainer
|
Maintainer
|
||||||
----------
|
----------
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Stock Request Purchase",
|
"name": "Stock Request Purchase",
|
||||||
"summary": "Internal request for stock",
|
"summary": "Internal request for stock",
|
||||||
"version": "11.0.1.1.0",
|
"version": "11.0.2.0.0",
|
||||||
"license": "LGPL-3",
|
"license": "LGPL-3",
|
||||||
"website": "https://github.com/stock-logistics-warehouse",
|
"website": "https://github.com/stock-logistics-warehouse",
|
||||||
"author": "Eficent, "
|
"author": "Eficent, "
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
"data": [
|
"data": [
|
||||||
"security/ir.model.access.csv",
|
"security/ir.model.access.csv",
|
||||||
"views/stock_request_views.xml",
|
"views/stock_request_views.xml",
|
||||||
|
"views/stock_request_order_views.xml",
|
||||||
"views/purchase_order_views.xml",
|
"views/purchase_order_views.xml",
|
||||||
],
|
],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ from . import purchase_order
|
|||||||
from . import purchase_order_line
|
from . import purchase_order_line
|
||||||
from . import procurement_rule
|
from . import procurement_rule
|
||||||
from . import stock_request
|
from . import stock_request
|
||||||
|
from . import stock_request_order
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class StockRequest(models.Model):
|
|||||||
|
|
||||||
purchase_ids = fields.One2many('purchase.order',
|
purchase_ids = fields.One2many('purchase.order',
|
||||||
compute='_compute_purchase_ids',
|
compute='_compute_purchase_ids',
|
||||||
string='Pickings', readonly=True)
|
string='Purchase Orders', readonly=True)
|
||||||
purchase_count = fields.Integer(string='Purchase count',
|
purchase_count = fields.Integer(string='Purchase count',
|
||||||
compute='_compute_purchase_ids',
|
compute='_compute_purchase_ids',
|
||||||
readonly=True)
|
readonly=True)
|
||||||
|
|||||||
40
stock_request_purchase/models/stock_request_order.py
Normal file
40
stock_request_purchase/models/stock_request_order.py
Normal 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 |
@@ -74,44 +74,54 @@ class TestStockRequestPurchase(common.TransactionCase):
|
|||||||
def test_create_request_01(self):
|
def test_create_request_01(self):
|
||||||
"""Single Stock request with buy rule"""
|
"""Single Stock request with buy rule"""
|
||||||
vals = {
|
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_id': self.product.id,
|
||||||
'product_uom_id': self.product.uom_id.id,
|
'product_uom_id': self.product.uom_id.id,
|
||||||
'product_uom_qty': 5.0,
|
'product_uom_qty': 5.0,
|
||||||
'company_id': self.main_company.id,
|
'company_id': self.main_company.id,
|
||||||
'warehouse_id': self.warehouse.id,
|
'warehouse_id': self.warehouse.id,
|
||||||
'location_id': self.warehouse.lot_stock_id.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)
|
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(order.sudo().purchase_ids), 1)
|
||||||
self.assertEqual(len(stock_request.picking_ids), 0)
|
self.assertEqual(len(order.picking_ids), 0)
|
||||||
self.assertEqual(len(stock_request.move_ids), 0)
|
self.assertEqual(len(order.move_ids), 0)
|
||||||
self.assertEqual(stock_request.qty_in_progress, 0.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()
|
purchase.button_confirm()
|
||||||
picking = purchase.picking_ids[0]
|
picking = purchase.picking_ids[0]
|
||||||
picking.action_confirm()
|
picking.action_confirm()
|
||||||
|
|
||||||
self.assertEqual(stock_request.qty_in_progress, 5.0)
|
self.assertEqual(order.stock_request_ids.qty_in_progress, 5.0)
|
||||||
self.assertEqual(stock_request.qty_done, 0.0)
|
self.assertEqual(order.stock_request_ids.qty_done, 0.0)
|
||||||
|
|
||||||
picking.action_assign()
|
picking.action_assign()
|
||||||
packout1 = picking.move_line_ids[0]
|
packout1 = picking.move_line_ids[0]
|
||||||
packout1.qty_done = 5
|
packout1.qty_done = 5
|
||||||
picking.action_done()
|
picking.action_done()
|
||||||
|
|
||||||
self.assertEqual(stock_request.qty_in_progress, 0.0)
|
self.assertEqual(order.stock_request_ids.qty_in_progress, 0.0)
|
||||||
self.assertEqual(stock_request.qty_done,
|
self.assertEqual(order.stock_request_ids.qty_done,
|
||||||
stock_request.product_uom_qty)
|
order.stock_request_ids.product_uom_qty)
|
||||||
self.assertEqual(stock_request.state, 'done')
|
self.assertEqual(order.stock_request_ids.state, 'done')
|
||||||
|
self.assertEqual(order.state, 'done')
|
||||||
|
|
||||||
def test_create_request_02(self):
|
def test_create_request_02(self):
|
||||||
"""Multiple Stock requests with buy rule"""
|
"""Multiple Stock requests with buy rule"""
|
||||||
@@ -176,16 +186,24 @@ class TestStockRequestPurchase(common.TransactionCase):
|
|||||||
|
|
||||||
def test_view_actions(self):
|
def test_view_actions(self):
|
||||||
vals = {
|
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_id': self.product.id,
|
||||||
'product_uom_id': self.product.uom_id.id,
|
'product_uom_id': self.product.uom_id.id,
|
||||||
'product_uom_qty': 5.0,
|
'product_uom_qty': 5.0,
|
||||||
'company_id': self.main_company.id,
|
'company_id': self.main_company.id,
|
||||||
'warehouse_id': self.warehouse.id,
|
'warehouse_id': self.warehouse.id,
|
||||||
'location_id': self.warehouse.lot_stock_id.id,
|
'location_id': self.warehouse.lot_stock_id.id,
|
||||||
|
})]
|
||||||
}
|
}
|
||||||
|
|
||||||
stock_request = self.stock_request.sudo().create(vals)
|
order = self.env['stock.request.order'].sudo().create(vals)
|
||||||
stock_request.action_confirm()
|
|
||||||
|
order.action_confirm()
|
||||||
|
|
||||||
|
stock_request = order.stock_request_ids
|
||||||
|
|
||||||
action = stock_request.action_view_purchase()
|
action = stock_request.action_view_purchase()
|
||||||
|
|
||||||
@@ -197,3 +215,9 @@ class TestStockRequestPurchase(common.TransactionCase):
|
|||||||
action = stock_request.purchase_ids[0].action_view_stock_request()
|
action = stock_request.purchase_ids[0].action_view_stock_request()
|
||||||
self.assertEqual(action['type'], 'ir.actions.act_window')
|
self.assertEqual(action['type'], 'ir.actions.act_window')
|
||||||
self.assertEqual(action['res_id'], stock_request.id)
|
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)
|
||||||
|
|||||||
26
stock_request_purchase/views/stock_request_order_views.xml
Normal file
26
stock_request_purchase/views/stock_request_order_views.xml
Normal 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>
|
||||||
Reference in New Issue
Block a user