improve action_view_reservations from product

This commit is contained in:
Yannick Vaucher
2014-09-01 19:56:13 +02:00
committed by Alexandre Fayolle
parent b4fe3059d9
commit e648a372d9
3 changed files with 77 additions and 21 deletions

View File

@@ -19,23 +19,66 @@
#
##############################################################################
from openerp import models, api
from openerp import models, fields, api
class ProductTemplate(models.Model):
_inherit = 'product.template'
reservation_count = fields.Integer(
compute='_reservation_count',
string='# Sales')
@api.multi
def _reservation_count(self):
StockReservation = self.env['stock.reservation']
product_ids = self._get_products()
domain = [('product_id', 'in', product_ids),
('state', 'in', ['draft', 'assigned'])]
reservations = StockReservation.search(domain)
self.reservation_count = sum(reserv.product_uom_qty
for reserv in reservations)
@api.multi
def action_view_reservations(self):
assert len(self._ids) == 1, "Expected 1 ID, got %r" % self._ids
ref = 'stock_reserve.action_stock_reservation_tree'
product_ids = self._get_products()
action_dict = self._get_act_window_dict(ref)
action_dict['domain'] = ("[('product_id','in',[" +
','.join(map(str, product_ids)) + "])]")
action_dict['context'] = {
'search_default_draft': 1,
'search_default_reserved': 1
}
return action_dict
class ProductProduct(models.Model):
_inherit = 'product.product'
reservation_count = fields.Integer(
compute='_reservation_count',
string='# Sales')
@api.multi
def open_stock_reservation(self):
def _reservation_count(self):
StockReservation = self.env['stock.reservation']
product_id = self._ids[0]
domain = [('product_id', '=', product_id),
('state', 'in', ['draft', 'assigned'])]
reservations = StockReservation.search(domain)
self.reservation_count = sum(reserv.product_uom_qty
for reserv in reservations)
@api.multi
def action_view_reservations(self):
assert len(self._ids) == 1, "Expected 1 ID, got %r" % self._ids
data_obj = self.env['ir.model.data']
act_obj = self.env['ir.actions.act_window']
ref = 'stock_reserve.action_stock_reservation'
action = data_obj.xmlid_to_object(ref)
action_dict = action.read()
ref = 'stock_reserve.action_stock_reservation_tree'
product_id = self._ids[0]
action_dict = self.product_tmpl_id._get_act_window_dict(ref)
action_dict['domain'] = ("[('product_id','='," + str(product_id) + ")]")
action_dict['context'] = {
'search_default_draft': 1,
'search_default_reserved': 1,
'default_product_id': self._ids[0],
'search_default_product_id': self._ids[0]}
return action
'search_default_reserved': 1
}
return action_dict

View File

@@ -2,18 +2,32 @@
<openerp>
<data noupdate="0">
<record model="ir.ui.view" id="product_form_view">
<field name="name">product.product.form.reserve</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="procurement.product_form_view_procurement_button"/>
<record model="ir.ui.view" id="product_template_form_view_reservation_button">
<field name="name">product.template.reservation.button</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='buttons']" position="inside">
<button string="Stock Reservations"
name="open_stock_reservation"
type="object"/>
<button class="oe_inline oe_stat_button" name="action_view_reservations"
type="object" groups="base.group_sale_salesman" icon="fa-lock">
<field string="Stock Reservations" name="reservation_count" widget="statinfo" />
</button>
</xpath>
</field>
</record>
<record model="ir.ui.view" id="product_product_form_view_reservation_button">
<field name="name">product.template.reservation.button</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='buttons']" position="inside">
<button class="oe_inline oe_stat_button" name="action_view_reservations"
type="object" groups="base.group_sale_salesman" icon="fa-lock">
<field string="Stock Reservations" name="reservation_count" widget="statinfo" />
</button>
</xpath>
</field>
</record>
</data>
</openerp>

View File

@@ -108,11 +108,10 @@
</field>
</record>
<record id="action_stock_reservation" model="ir.actions.act_window">
<record id="action_stock_reservation_tree" model="ir.actions.act_window">
<field name="name">Stock Reservations</field>
<field name="res_model">stock.reservation</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_stock_reservation_tree"/>
<field name="search_view_id" ref="view_stock_reservation_search"/>
<field name="context">{'search_default_draft': 1,
@@ -128,7 +127,7 @@
</field>
</record>
<menuitem action="action_stock_reservation"
<menuitem action="action_stock_reservation_tree"
id="menu_action_stock_reservation"
parent="stock.menu_stock_inventory_control"
sequence="30"/>