mirror of
https://github.com/OCA/rma.git
synced 2025-02-16 17:11:47 +02:00
Add computed fields for the RMA locations
This commit is contained in:
@@ -20,3 +20,4 @@
|
||||
##############################################################################
|
||||
|
||||
from . import stock_warehouse
|
||||
from . import product
|
||||
|
||||
@@ -39,6 +39,7 @@ The product views displays the quantity available and virtual in this
|
||||
'website': 'http://www.camptocamp.com',
|
||||
'data': ['stock_data.xml',
|
||||
'stock_warehouse_view.xml',
|
||||
'product_view.xml',
|
||||
],
|
||||
'test': [],
|
||||
'installable': True,
|
||||
|
||||
104
crm_rma_stock_location/product.py
Normal file
104
crm_rma_stock_location/product.py
Normal file
@@ -0,0 +1,104 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Guewen Baconnier
|
||||
# Copyright 2014 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import orm, fields
|
||||
import openerp.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class ProductProduct(orm.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
def _product_available(self, cr, uid, ids, field_names=None, arg=False,
|
||||
context=None):
|
||||
""" Finds the incoming and outgoing quantity of product for the RMA
|
||||
locations.
|
||||
"""
|
||||
if field_names is None:
|
||||
field_names = []
|
||||
if context is None:
|
||||
context = {}
|
||||
shop_obj = self.pool['sale.shop']
|
||||
warehouse_obj = self.pool['stock.warehouse']
|
||||
res = {}
|
||||
for id in ids:
|
||||
res[id] = {}.fromkeys(field_names, 0.0)
|
||||
|
||||
for field in field_names:
|
||||
ctx = context.copy()
|
||||
|
||||
warehouse_id = ctx.get('warehouse_id')
|
||||
if ctx.get('shop'):
|
||||
shop_id = ctx['shop']
|
||||
warehouse = shop_obj.read(cr, uid, shop_id,
|
||||
['warehouse_id'],
|
||||
context=ctx)
|
||||
warehouse_id = warehouse['warehouse_id'][0]
|
||||
|
||||
if warehouse_id:
|
||||
rma_id = warehouse_obj.read(cr, uid,
|
||||
warehouse_id,
|
||||
['lot_rma_id'],
|
||||
context=ctx)['lot_rma_id'][0]
|
||||
if rma_id:
|
||||
ctx['location'] = rma_id
|
||||
else:
|
||||
location_ids = set()
|
||||
wids = warehouse_obj.search(cr, uid, [], context=context)
|
||||
if not wids:
|
||||
return res
|
||||
for wh in warehouse_obj.browse(cr, uid, wids, context=context):
|
||||
if wh.lot_rma_id:
|
||||
location_ids.add(wh.lot_rma_id.id)
|
||||
if not location_ids:
|
||||
return res
|
||||
ctx['location'] = list(location_ids)
|
||||
|
||||
ctx['compute_child'] = True
|
||||
compute = {
|
||||
'rma_qty_available': {
|
||||
'states': ('done', ),
|
||||
'what': ('in', 'out')
|
||||
},
|
||||
'rma_virtual_available': {
|
||||
'states': ('confirmed', 'waiting', 'assigned', 'done'),
|
||||
'what': ('in', 'out')
|
||||
}
|
||||
}
|
||||
ctx.update(compute[field])
|
||||
stock = self.get_product_available(cr, uid, ids, context=ctx)
|
||||
for id in ids:
|
||||
res[id][field] = stock.get(id, 0.0)
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'rma_qty_available': fields.function(
|
||||
_product_available,
|
||||
type='float',
|
||||
multi='rma_qty',
|
||||
digits_compute=dp.get_precision('Product Unit of Measure'),
|
||||
string='RMA Quantity On Hand'),
|
||||
'rma_virtual_available': fields.function(
|
||||
_product_available,
|
||||
type='float',
|
||||
multi='rma_qty',
|
||||
digits_compute=dp.get_precision('Product Unit of Measure'),
|
||||
string='RMA Quantity Available'),
|
||||
}
|
||||
28
crm_rma_stock_location/product_view.xml
Normal file
28
crm_rma_stock_location/product_view.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data noupdate="0">
|
||||
<record id="product_product_tree_view" model="ir.ui.view">
|
||||
<field name="name">product.product.tree</field>
|
||||
<field name="model">product.product</field>
|
||||
<field name="inherit_id" ref="product.product_product_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="virtual_available" position="after">
|
||||
<field name="rma_qty_available"/>
|
||||
<field name="rma_virtual_available"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_normal_procurement_locations_form" model="ir.ui.view">
|
||||
<field name="name">product.normal.procurement.locations.inherit</field>
|
||||
<field name="model">product.product</field>
|
||||
<field name="inherit_id" ref="stock.view_normal_procurement_locations_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="virtual_available" position="after">
|
||||
<field name="rma_qty_available" class="oe_inline"/>
|
||||
<field name="rma_virtual_available" class="oe_inline"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user