Openerp/module 3
รุ่นแก้ไขเมื่อ 08:09, 4 ธันวาคม 2556 โดย Jittat (คุย | มีส่วนร่วม)
เนื้อหา
Template: view
module_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
</data>
</openerp>
views / actions
<record model="ir.ui.view" id="view_MODULE_MODEL_tree">
<field name="name">MODULE.MODEL.tree</field>
<field name="model">MODULE.MODEL</field>
<field name="arch" type="xml">
<tree string="MODEL">
<field name="xxxxxxxxx"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_MODULE_MODEL_form">
<field name="name">MODULE.MODEL.form</field>
<field name="model">MODULE.MODEL</field>
<field name="arch" type="xml">
<form string="MODEL">
<field name="xxxxxxxxxxx"/>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_MODULE_MODEL">
<field name="name">MODEL</field>
<field name="res_model">MODULE.MODEL</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{'search_default_open_true':True}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to add a ..............
</p>
</field>
</record>
<menuitem name="MENUTITLETOP" id="menu_MODULE_top"
parent="" sequence="1"
action="MODULE.action_MODULE_MODEL"/>
<menuitem name="MENUTITLE" id="menu_MODULE_main"
parent="menu_MODULE_top" sequence="1"/>
<menuitem name="MODELTITLE" id="menu_MODULE_MODEL"
parent="menu_MODULE_main" sequence="1"
action="MODULE.action_MODULE_MODEL"/>
ezbill: version 1
ezbill.py
from osv import osv, fields
class Product(osv.Model):
_name = 'ezbill.product'
_columns = {
'name': fields.char('Name', size=50, required=True),
'price_per_unit': fields.float('Price per unit', required=True),
}
class Customer(osv.Model):
_name = 'ezbill.customer'
_rec_name = 'first_name'
_columns = {
'first_name': fields.char('First name', size=50, required=True),
'last_name': fields.char('Last name', size=50, required=True),
}
ezbill_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_ezbill_customer_tree">
<field name="name">ezbill.customer.tree</field>
<field name="model">ezbill.customer</field>
<field name="arch" type="xml">
<tree string="customer">
<field name="first_name"/>
<field name="last_name"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_ezbill_customer_form">
<field name="name">ezbill.customer.form</field>
<field name="model">ezbill.customer</field>
<field name="arch" type="xml">
<form string="customer">
<field name="first_name"/>
<field name="last_name"/>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_ezbill_customer">
<field name="name">customer</field>
<field name="res_model">ezbill.customer</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{'search_default_open_true':True}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to add a ..............
</p>
</field>
</record>
<record model="ir.ui.view" id="view_ezbill_product_tree">
<field name="name">ezbill.product.tree</field>
<field name="model">ezbill.product</field>
<field name="arch" type="xml">
<tree string="product">
<field name="name"/>
<field name="price_per_unit"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_ezbill_product_form">
<field name="name">ezbill.product.form</field>
<field name="model">ezbill.product</field>
<field name="arch" type="xml">
<form string="product">
<field name="name"/>
<field name="price_per_unit"/>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_ezbill_product">
<field name="name">product</field>
<field name="res_model">ezbill.product</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{'search_default_open_true':True}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to add a new product
</p>
</field>
</record>
<menuitem name="Bills" id="menu_ezbill_top"
parent="" sequence="1"
action="ezbill.action_ezbill_product"/>
<menuitem name="Billing System" id="menu_ezbill_main"
parent="menu_ezbill_top" sequence="1"/>
<menuitem name="Products" id="menu_ezbill_product"
parent="menu_ezbill_main" sequence="1"
action="ezbill.action_ezbill_product"/>
<menuitem name="Customers" id="menu_ezbill_customer"
parent="menu_ezbill_main" sequence="2"
action="ezbill.action_ezbill_customer"/>
</data>
</openerp>
ezbill.py version 2
<syntexhighlight lang="py"> import time
class Bill(osv.Model):
_name = 'ezbill.bill' _columns = { 'customer': fields.many2one('ezbill.customer', string='Customer', required=True), 'bill_date': fields.datetime('Bill Date', required=True), }
def _get_date(self, cr, uid, context): return time.strftime('%Y-%m-%d %H:%M:%S')
_defaults = { 'bill_date': _get_date, }
</syntaxhighlight>