[IMP] product_margin:Changes in wizard by converting them into OSV memory

bzr revid: mso@mso-20100309120043-kadkz0b2xdo47c3k
This commit is contained in:
mso 2010-03-09 17:30:43 +05:30
parent 3ea804d7fb
commit d4ac06e0c7
8 changed files with 139 additions and 105 deletions

View File

@ -18,7 +18,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import wizard
import product_margin

View File

@ -31,7 +31,7 @@ the report has several options to help you get the data you need.
""",
'author': 'Tiny',
'depends': ['base', 'product', 'account'],
'update_xml': ['product_margin_view.xml'],
'update_xml': ['wizard/product_margin_view.xml','product_margin_view.xml'],
'demo_xml': [],
'installable': True,
'active': False,

View File

@ -1,15 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<wizard id="action_open_margin" menu="False" model="product.product" name="product.margins" string="Product Margins"/>
<!-- <menuitem id="menu_product_reporting"-->
<!-- name="Reporting" parent ="product.menu_main_product"-->
<!-- groups="product.group_product_manager"/>-->
<!---->
<!-- <menuitem icon="STOCK_JUSTIFY_FILL" action="action_open_margin" id="menu_action_product_margin" type="wizard" sequence="5" parent="menu_product_reporting" />-->
<menuitem id="main" name="OSV Memory Wizard Test"/>
<menuitem
action="product_margin_action"
id="menu_mrp_property_action"
parent="main" />
<record model="ir.ui.view" id="view_product_margin_graph">
<field name="name">product.margin.graph</field>
<field name="model">product.product</field>

View File

@ -19,7 +19,7 @@
#
##############################################################################
import wizard_product_margin
import product_margin
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,98 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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/>.
#
##############################################################################
import time
from osv import osv
from osv import fields
import netsvc
import time
from tools.translate import _
class product_margin(osv.osv_memory):
'''
Product Margin
'''
_name = 'product.margin'
_description = 'Product Margin'
def _action_open_window(self, cr, uid, ids, context):
"""
@summary:
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: the account ID or list of IDs if we want more than one
@return:
"""
mod_obj = self.pool.get('ir.model.data')
result = mod_obj._get_id(cr, uid, 'product', 'product_search_form_view')
id = mod_obj.read(cr, uid, result, ['res_id'])
cr.execute('select id,name from ir_ui_view where name=%s and type=%s', ('product.margin.graph', 'graph'))
view_res3 = cr.fetchone()[0]
cr.execute('select id,name from ir_ui_view where name=%s and type=%s', ('product.margin.form.inherit', 'form'))
view_res2 = cr.fetchone()[0]
cr.execute('select id,name from ir_ui_view where name=%s and type=%s', ('product.margin.tree', 'tree'))
view_res = cr.fetchone()[0]
#get the current product.margin object to obtain the values from it
product_margin_obj = self.browse(cr,uid,ids)[0]
return {
'name': _('Product Margins'),
'context':{'date_from':product_margin_obj.from_date,'date_to':product_margin_obj.to_date,'invoice_state' : product_margin_obj.invoice_state},
'view_type': 'form',
"view_mode": 'tree,form,graph',
'res_model':'product.product',
'type': 'ir.actions.act_window',
'views': [(view_res,'tree'), (view_res2,'form'), (view_res3,'graph')],
'view_id': False,
'search_view_id': id['res_id']
}
def action_cancel(self, cr, uid, ids, context=None):
"""
@summary:
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: the account ID or list of IDs if we want more than one
@return:
"""
return {'type':'ir.actions.act_window_close'}
_columns = {
#TODO : import time required to get currect date
'from_date': fields.date('From'),
#TODO : import time required to get currect date
'to_date': fields.date('To'),
'invoice_state':fields.selection([
('paid','Paid'),
('open_paid','Open and Paid'),
('draft_open_paid','Draft, Open and Paid'),
],'Invoice State', select=True, required=True),
}
_defaults = {
'from_date': lambda *a:time.strftime('%Y-01-01'),
'to_date': lambda *a:time.strftime('%Y-01-01'),
'invoice_state': lambda *a:"open_paid",
}
product_margin()

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="product_margin_form_view" model="ir.ui.view">
<field name="name">product.margin.form</field>
<field name="model">product.margin</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Properties categories">
<separator colspan="4" string="General Information"/>
<field name="from_date" />
<field name="to_date" />
<field name="invoice_state" />
<group col="4" colspan="2">
<button special="cancel" string="Cancel" type="object"/>
<button name="_action_open_window" string="Open Margins" type="object"/>
</group>
</form>
</field>
</record>
<record id="product_margin_action" model="ir.actions.act_window">
<field name="name">Product Margine</field>
<field name="type">ir.actions.act_window</field>
<field name="target">new</field>
<field name="res_model">product.margin</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="product_margin_form_view"/>
</record>
</data>
</openerp>

View File

@ -1,93 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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/>.
#
##############################################################################
import wizard
import pooler
import time
from tools.translate import _
def _action_open_window(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
mod_obj = pool.get('ir.model.data')
result = mod_obj._get_id(cr, uid, 'product', 'product_search_form_view')
id = mod_obj.read(cr, uid, result, ['res_id'])
cr.execute('select id,name from ir_ui_view where name=%s and type=%s', ('product.margin.graph', 'graph'))
view_res3 = cr.fetchone()[0]
cr.execute('select id,name from ir_ui_view where name=%s and type=%s', ('product.margin.form.inherit', 'form'))
view_res2 = cr.fetchone()[0]
cr.execute('select id,name from ir_ui_view where name=%s and type=%s', ('product.margin.tree', 'tree'))
view_res = cr.fetchone()[0]
return {
'name': _('Product Margins'),
'context':{'date_from':data['form']['from_date'],'date_to':data['form']['to_date'],'invoice_state' : data['form']['invoice_state']},
'view_type': 'form',
"view_mode": 'tree,form,graph',
'res_model':'product.product',
'type': 'ir.actions.act_window',
'views': [(view_res,'tree'), (view_res2,'form'), (view_res3,'graph')],
'view_id': False,
'search_view_id': id['res_id']
}
class product_margins(wizard.interface):
form1 = '''<?xml version="1.0"?>
<form string="View Stock of Products">
<separator string="Select " colspan="4"/>
<field name="from_date"/>
<field name="to_date"/>
<field name="invoice_state"/>
</form>'''
form1_fields = {
'from_date': {
'string': 'From',
'type': 'date',
'default': lambda *a:time.strftime('%Y-01-01'),
},
'to_date': {
'string': 'To',
'type': 'date',
'default': lambda *a:time.strftime('%Y-12-31'),
},
'invoice_state': {
'string': 'Invoice State',
'type': 'selection',
'selection': [('paid','Paid'),('open_paid','Open and Paid'),('draft_open_paid','Draft, Open and Paid'),],
'required': True,
'default': lambda *a:"open_paid",
},
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':form1, 'fields':form1_fields, 'state': [('end', 'Cancel','gtk-cancel'),('open', 'Open Margins','gtk-ok')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
product_margins('product.margins')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--<menuitem icon="terp-purchase" id="base.menu_purchase_root" name="Purchase Management"
groups="group_purchase_user"/>-->
<menuitem icon="terp-purchase" id="base.menu_purchase_root" name="Procurement Management"