add stock_request in 11.0

This commit is contained in:
Jordi Ballester
2017-11-13 13:15:41 +01:00
committed by Kitti U
parent 432b9837ac
commit 09dfc7050b
20 changed files with 1426 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models
class StockRequestAllocation(models.Model):
_name = 'stock.request.allocation'
_description = 'Stock Request Allocation'
stock_request_id = fields.Many2one(string='Stock Request',
comodel_name='stock.request',
required=True, ondelete='cascade',
)
stock_move_id = fields.Many2one(string='Stock Move',
comodel_name='stock.move',
required=True, ondelete='cascade',
)
product_id = fields.Many2one(string='Product',
comodel_name='product.product',
related='stock_request_id.product_id',
readonly=True,
)
product_uom_id = fields.Many2one(string='UoM', comodel_name='product.uom',
related='stock_request_id.product_uom_id',
readonly=True,
)
requested_product_uom_qty = fields.Float(
'Requested Quantity (UoM)',
help='Quantity of the stock request allocated to the stock move, '
'in the UoM of the Stock Request',
)
requested_product_qty = fields.Float(
'Requested Quantity',
help='Quantity of the stock request allocated to the stock move, '
'in the default UoM of the product',
compute='_compute_requested_product_qty'
)
allocated_product_qty = fields.Float(
'Allocated Quantity',
help='Quantity of the stock request allocated to the stock move, '
'in the default UoM of the product',
)
open_product_qty = fields.Float('Open Quantity',
compute='_compute_open_product_qty')
@api.depends('stock_request_id.product_id',
'stock_request_id.product_uom_id',
'requested_product_uom_qty')
def _compute_requested_product_qty(self):
for rec in self:
rec.requested_product_qty = rec.product_uom_id._compute_quantity(
rec.requested_product_uom_qty, rec.product_id.uom_id)
@api.depends('requested_product_qty', 'allocated_product_qty',
'stock_move_id', 'stock_move_id.state')
def _compute_open_product_qty(self):
for rec in self:
if rec.stock_move_id.state == 'cancel':
rec.open_product_qty = 0.0
else:
rec.open_product_qty = \
rec.requested_product_qty - rec.allocated_product_qty
if rec.open_product_qty < 0.0:
rec.open_product_qty = 0.0