Skip to content

Commit

Permalink
demo_expense_tutorial_v1
Browse files Browse the repository at this point in the history
  • Loading branch information
twtrubiks committed Jul 7, 2020
1 parent b28d147 commit 8551cb6
Show file tree
Hide file tree
Showing 13 changed files with 772 additions and 0 deletions.
470 changes: 470 additions & 0 deletions demo_expense_tutorial_v1/README.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions demo_expense_tutorial_v1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# from . import controllers
from . import models
36 changes: 36 additions & 0 deletions demo_expense_tutorial_v1/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
'name': "demo expense tutorial v1",
'summary': """
tutorial - Many2one, Many2many, One2many
demo expense tutorial v1
""",
'description': """
tutorial - Many2one, Many2many, One2many
demo expense tutorial v1
""",
'author': "My Company",
'website': "http://www.yourcompany.com",

# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/12.0/odoo/addons/base/data/ir_module_category_data.xml
# for the full list
'category': 'Uncategorized',
'version': '0.1',

# any module necessary for this one to work correctly
'depends': ['hr_contract'],

# always loaded
'data': [
'security/security.xml',
'security/ir.model.access.csv',
'security/ir_rule.xml',
'views/menu.xml',
'views/view.xml'
],
# only loaded in demonstration mode
# 'demo': [
# 'demo/demo.xml',
# ],
'application': True,
}
1 change: 1 addition & 0 deletions demo_expense_tutorial_v1/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import controllers
1 change: 1 addition & 0 deletions demo_expense_tutorial_v1/controllers/controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# from odoo import http
5 changes: 5 additions & 0 deletions demo_expense_tutorial_v1/demo/demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<odoo>
<data>

</data>
</odoo>
1 change: 1 addition & 0 deletions demo_expense_tutorial_v1/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
70 changes: 70 additions & 0 deletions demo_expense_tutorial_v1/models/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from odoo import models, fields, api

class DemoTag(models.Model):
_name = 'demo.tag'
_description = 'Demo Tags'

name = fields.Char(string='Tag Name', index=True, required=True)
active = fields.Boolean(default=True, help="Set active.")

class DemoExpenseTutorial(models.Model):
_name = 'demo.expense.tutorial'
_description = 'Demo Expense Tutorial'

name = fields.Char('Description', required=True)
employee_id = fields.Many2one('hr.employee', string="Employee", required=True)
user_id = fields.Many2one('res.users', default=lambda self: self.env.user)

# https://www.odoo.com/documentation/12.0/reference/orm.html#odoo.fields.Many2many
# Many2many(comodel_name=<object object>, relation=<object object>, column1=<object object>, column2=<object object>, string=<object object>, **kwargs)
#
# relation: database table name
#

# By default, the relationship table name is the two table names
# joined with an underscore and _rel appended at the end.
# In the case of our books or authors relationship, it should be named demo_expense_tutorial_demo_tag_rel.

tag_ids = fields.Many2many('demo.tag', 'demo_expense_tag', 'demo_expense_id', 'tag_id', string='Tges')
sheet_id = fields.Many2one('demo.expense.sheet.tutorial', string="Expense Report")

# Related (Reference) fields (不會存在 db)
# readonly default 為 True
# store default 為 False
gender = fields.Selection('Gender', related='employee_id.gender')

@api.multi
def button_sheet_id(self):
return {
'view_mode': 'form',
'res_model': 'demo.expense.sheet.tutorial',
'res_id': self.sheet_id.id,
'type': 'ir.actions.act_window'
}


class DemoExpenseSheetTutorial(models.Model):
_name = 'demo.expense.sheet.tutorial'
_description = 'Demo Expense Sheet Tutorial'

name = fields.Char('Expense Demo Report Summary', required=True)

# One2many is a virtual relationship, there must be a Many2one field in the other_model,
# and its name must be related_field
expense_line_ids = fields.One2many(
'demo.expense.tutorial', # related model
'sheet_id', # field for "this" on related model
string='Expense Lines')

@api.multi
def button_line_ids(self):
return {
'name': 'Demo Expense Line IDs',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'demo.expense.tutorial',
'view_id': False,
'type': 'ir.actions.act_window',
'domain': [('sheet_id', '=', self.id)],
}

9 changes: 9 additions & 0 deletions demo_expense_tutorial_v1/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_demo_expense_user,Demo Expense Tutorial User Access,model_demo_expense_tutorial,demo_expense_tutorial_group_user,1,1,1,0
access_demo_expense_manager,Demo Expense Tutorial Manager Access,model_demo_expense_tutorial,demo_expense_tutorial_group_manager,1,1,1,1

access_demo_expense_user_tag,Demo Expense Tutorial Tag User Access,model_demo_tag,demo_expense_tutorial_group_user,1,0,0,0
access_demo_expense_manager_tag,Demo Expense Tutorial Tag Manager Access,model_demo_tag,demo_expense_tutorial_group_manager,1,1,1,1

access_demo_expense_sheet_user,Demo Expense Sheet User Tutorial Access,model_demo_expense_sheet_tutorial,demo_expense_tutorial_group_user,1,1,1,0
access_demo_expense_sheet_manager,Demo Expense Sheet Manager Tutorial Access,model_demo_expense_sheet_tutorial,demo_expense_tutorial_group_manager,1,1,1,1
19 changes: 19 additions & 0 deletions demo_expense_tutorial_v1/security/ir_rule.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">

<record id="ir_rule_demo_expense_user" model="ir.rule">
<field name="name">Demo Expense User</field>
<field name="model_id" ref="model_demo_expense_tutorial"/>
<field name="domain_force">[('employee_id.user_id.id', '=', user.id)]</field>
<field name="groups" eval="[(4, ref('demo_expense_tutorial_group_user'))]"/>
</record>

<record id="ir_rule_demo_expense_manager" model="ir.rule">
<field name="name">Demo Expense Manager</field>
<field name="model_id" ref="model_demo_expense_tutorial"/>
<field name="domain_force">[(1, '=', 1)]</field>
<field name="groups" eval="[(4, ref('demo_expense_tutorial_group_manager'))]"/>
</record>
</data>
</odoo>
27 changes: 27 additions & 0 deletions demo_expense_tutorial_v1/security/security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" ?>
<odoo>

<record id="module_demo_expense_tutorial" model="ir.module.category">
<field name="name">Demo expense tutorial category</field>
</record>

<record id="demo_expense_tutorial_group_user" model="res.groups">
<field name="name">User</field>
<field name="category_id"
ref="module_demo_expense_tutorial"/>
<field name="implied_ids"
eval="[(4, ref('base.group_user'))]"/>
</record>

<record id="demo_expense_tutorial_group_manager" model="res.groups">
<field name="name">Manager</field>
<field name="category_id"
ref="module_demo_expense_tutorial"/>
<field name="implied_ids"
eval="[(4, ref('demo_expense_tutorial_group_user'))]"/>
<field name="users"
eval="[(4, ref('base.user_root')),
(4, ref('base.user_admin'))]"/>
</record>

</odoo>
32 changes: 32 additions & 0 deletions demo_expense_tutorial_v1/views/menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<odoo>
<!-- demo_expense_tutorial App Menu -->
<menuitem id="demo_expense_tutorial_menu"
name="Demo Expense Tutorial" />

<!-- Action to open the demo_expense_tutorial -->
<act_window id="action_expense_tutorial"
name="Demo Expense Tutorial Action"
res_model="demo.expense.tutorial"
view_mode="tree,form"/>

<!-- Menu item to open the demo_expense_tutorial -->
<menuitem id="menu_expense_tutorial"
name="Demo Expense Tutorial"
action="action_expense_tutorial"
parent="demo_expense_tutorial_menu" />

<!-- Action to open the demo_expense_sheet_tutorial -->
<act_window id="action_expense_sheet_tutorial"
name="Demo Expense Sheet Tutorial Action"
res_model="demo.expense.sheet.tutorial"
view_mode="tree,form"/>

<!-- Menu item to open the demo_expense_sheet_tutorial -->
<menuitem id="menu_expense_sheet_tutorial"
name="Demo Expense Sheet Tutorial"
action="action_expense_sheet_tutorial"
parent="demo_expense_tutorial_menu" />
</odoo>


99 changes: 99 additions & 0 deletions demo_expense_tutorial_v1/views/view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0"?>
<odoo>

<record id="view_form_demo_expense_tutorial" model="ir.ui.view">
<field name="name">Demo Expense Tutorial Form</field>
<field name="model">demo.expense.tutorial</field>
<field name="arch" type="xml">
<form string="Demo Expense Tutorial">
<sheet>
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" name="button_sheet_id"
string="SHEET ID" type="object"
attrs="{'invisible':[('sheet_id','=', False)]}" icon="fa-bars"/>
</div>
<group>
<field name="name"/>
<field name="employee_id"/>
<field name="user_id"/>
<!-- <field name="tag_ids"/> -->
<field name="tag_ids" widget="many2many_tags"/> <!-- widget -->
<field name="sheet_id"/>
<field name="gender"/>
</group>
</sheet>
</form>
</field>
</record>

<record id="view_tree_demo_expense_tutorial" model="ir.ui.view">
<field name="name">Demo Expense Tutorial List</field>
<field name="model">demo.expense.tutorial</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="employee_id"/>
<field name="user_id"/>
<field name="tag_ids"/>
<field name="sheet_id"/>
</tree>
</field>
</record>


<record id="view_form_demo_expense_sheet_tutorial" model="ir.ui.view">
<field name="name">Demo Expense Sheet Tutorial Form</field>
<field name="model">demo.expense.sheet.tutorial</field>
<field name="arch" type="xml">
<form string="Demo Expense Sheet Tutorial">
<sheet>
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" name="button_line_ids"
string="SHEET IDs" type="object"
attrs="{'invisible':[('expense_line_ids','=', False)]}" icon="fa-bars"/>
</div>
<group>
<field name="name"/>
</group>
<notebook>
<page string="Expense">
<field name="expense_line_ids">
<tree>
<field name="name"/>
<field name="employee_id"/>
<field name="tag_ids" widget="many2many_tags"/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

<record id="view_tree_demo_expense_sheet_tutorial" model="ir.ui.view">
<field name="name">Demo Expense Sheet Tutorial List</field>
<field name="model">demo.expense.sheet.tutorial</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="expense_line_ids"/>
</tree>
</field>
</record>

<record id="view_filter_demo_expense_tutorial" model="ir.ui.view">
<field name="name">Demo Expense Tutorial Filter</field>
<field name="model">demo.expense.tutorial</field>
<field name="arch" type="xml">
<search string="Demo Expense Tutorial Filter">
<field name="name" string="Name"/>
<group expand="0" string="Group By">
<filter string="Sheet" name="sheet" domain="[]" context="{'group_by': 'sheet_id'}"/>
<filter string="Employee" name="employee" domain="[]" context="{'group_by': 'employee_id'}"/>
</group>
</search>
</field>
</record>

</odoo>

0 comments on commit 8551cb6

Please sign in to comment.