如何在 openerp 7 中为 cuatom 模块创建自定义配置,如下所示
我的python文件
import logging
import shipment_utility
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as DF
from openerp.osv import fields, osv
_logger = logging.getLogger(__name__)
class shipment_config_settings(osv.osv_memory):
_name = 'shipment.config.settings'
_inherit = 'res.config.settings'
_columns = {
'default_us_custom_id': fields.many2one('res.partner', 'Us Customs', domain=[('supplier', '=', 1)], help='Select The Us Customs For Generation of Custom statements Invoices'),
'default_invoice_account_id': fields.many2one('account.account', 'Invoice Account',),
'default_invoice_journal_id': fields.many2one('account.journal', 'Invoice Journal',),
'default_invoice_line_account_id': fields.many2one('account.account', 'Invoice line Account',),
'default_invoice_line_product_id': fields.many2one('product.product', 'Default Product',),
}
_defaults = {
'default_us_custom_id': 1,
#'default_invoice_account_id': "",
}
def get_default_us_custom_id(self, cr, uid, fields, context=None):
search_ids = self.search(cr, uid, [])
first_id = search_ids and min(search_ids)
_logger.warning("ids " + str(search_ids))
if not search_ids:
return {'default_us_custom_id': ''}
us_customs = self.browse(cr, uid, first_id, context)
res = {}
for field in fields:
#_logger.warning("field " + str(field))
res[field] = getattr(us_customs, field).id
return res
"""def set_default_username(self, cr, uid, ids, context=None):
#some code...
#you can get the field content from some table and return it
#as a example
config = self.browse(cr, uid, ids[0], context)
new_username = config.default_us_custom_id.id
self.pool.get('shipment.config.settings').write(cr, uid, uid, {'default_us_custom_id': new_username})
class shipment_config_settings_wizard(osv.osv_memory):
_name = 'shipment.config.settings.wizard'
_inherit = 'shipment.config.settings'
_columns = {
'default_us_custom_id': fields.many2one('res.partner', 'Us Customs', default_model='res.config.settings'),
}"""
def create(self, cr, uid, values, context=None):
search_ids = self.search(cr, uid, [])
first_id = search_ids and min(search_ids)
#us_customs = self.browse(cr, uid, first_id, context)
#_logger.warning("us custom " + str(us_customs.default_us_custom_id.name))
res = {}
#for field, val in values.iteritems():
# #_logger.warning("key = %s, val = %s" % (field, val))
# res[field] = val
# DOWN STATEMENT IS DOING THE SAME WORK AS ABOVE COMMENTED LOOP
res.update(values)
if not first_id:
return super(shipment_config_settings, self).create(cr, uid, res, context)
self.write(cr, uid, first_id, res)
return first_id
我的视图文件
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Shipment config wizard -->
<record id="view_shipment_config_settings" model="ir.ui.view">
<field name="name">Shipment Settings</field>
<field name="model">shipment.config.settings</field>
<field name="arch" type="xml">
<form string="Configure Shipment" version="7.0" class="oe_form_configuration">
<header>
<button string="Apply" type="object" name="execute" class="oe_highlight"/>
or
<button string="Cancel" type="object" name="cancel" class="oe_link"/>
</header>
<div name="shipment.settings">
<separator string="Shipment Configuration"/>
<group name="Supplier">
<group>
<field name="default_us_custom_id" class="oe_inline"/>
<field name="default_invoice_account_id" class="oe_inline"/>
<field name="default_invoice_journal_id" class="oe_inline"/>
<field name="default_invoice_line_account_id" class="oe_inline"/>
<field name="default_invoice_line_product_id" class="oe_inline"/>
</group>
<group>
<label for="default_us_custom_id" string="Select US Custom Supplier"/>
</group>
</group>
</div>
<div name="config_other"/>
</form>
</field>
</record>
<record id="action_shipment_config" model="ir.actions.act_window">
<field name="name">Configure Shipment</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">shipment.config.settings</field>
<field name="view_id" ref="view_shipment_config_settings"/>
<field name="view_mode">form</field>
<field name="target">inline</field>
</record>
<menuitem id="base.menu_shipment_config" name="Shipment" parent="base.menu_config" sequence="10"
action="action_shipment_config"/>
<menuitem id="menu_item_config" parent="menu_section_config" name="US Custom Invoicing"
action="action_shipment_config"/>
</data>
</openerp>