Skip to content

Commit

Permalink
Starting point views and fields
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonGenin committed Sep 18, 2024
1 parent 05f1cb1 commit ca54758
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 0 deletions.
2 changes: 2 additions & 0 deletions shelter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import models
27 changes: 27 additions & 0 deletions shelter/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
{
"name": "Shelter",
"summary": """
Companion addon for the Odoo Smartclass 2024 on the JS Framework
""",
"description": """
Companion addon for the Odoo Smartclass 2024 on the JS Framework
""",
"author": "Odoo",
"website": "https://www.odoo.com/",
"category": "Tutorials",
"version": "0.1",
"application": True,
"installable": True,
"depends": ["base", "web", "contacts"],
"data": [
"views/views.xml",
"security/ir.model.access.csv",
],
"assets": {
"web.assets_backend": [
"shelter/static/src/**/*",
],
},
"license": "AGPL-3",
}
6 changes: 6 additions & 0 deletions shelter/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import animal
from . import animal_type
from . import animal_race
29 changes: 29 additions & 0 deletions shelter/models/animal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models, api


class Animal(models.Model):
_name = "shelter.animal"
_description = "Animal"
_inherit = ["mail.thread", "mail.activity.mixin"]

name = fields.Char(required=True)
picture = fields.Image("Picture")
type_id = fields.Many2one("shelter.animal_type", "Type", required=True)
pictogram = fields.Image(related="type_id.pictogram")
state = fields.Selection(
selection=[
("on_site", "On site"),
("adopted", "Adopted"),
],
default="on_site",
required=True,
string="State",
)
race_id = fields.Many2one("shelter.animal_race", "Race")
notes = fields.Html("Notes")
dropper_id = fields.Many2one("res.partner", "Dropper")
owner_id = fields.Many2one("res.partner", "Owner", tracking=True)
birth_date = fields.Date("Birth Date")
11 changes: 11 additions & 0 deletions shelter/models/animal_race.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models


class AnimalRace(models.Model):
_name = "shelter.animal_race"
_description = "Race"

name = fields.Char(required=True)
12 changes: 12 additions & 0 deletions shelter/models/animal_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models


class AnimalType(models.Model):
_name = "shelter.animal_type"
_description = "Type"

name = fields.Char(required=True)
pictogram = fields.Image("Pictogram")
4 changes: 4 additions & 0 deletions shelter/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
shelter.access_shelter_animal,access_shelter_animal,shelter.model_shelter_animal,base.group_user,1,1,1,1
shelter.access_shelter_animal_type,access_shelter_animal_type,shelter.model_shelter_animal_type,base.group_user,1,1,1,1
shelter.access_shelter_animal_race,access_shelter_animal_race,shelter.model_shelter_animal_race,base.group_user,1,1,1,1
87 changes: 87 additions & 0 deletions shelter/views/views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<odoo>
<data>

<record id="shelter.animal_action" model="ir.actions.act_window">
<field name="name">Animals</field>
<field name="res_model">shelter.animal</field>
<field name="view_mode">list,kanban,form</field>
</record>

<record id='shelter.animal_view_list' model='ir.ui.view'>
<field name="name">shelter.animal.list</field>
<field name="model">shelter.animal</field>
<field name="arch" type="xml">
<list string="Animals">
<field name="name" />
<field name="type_id" />
<field name="pictogram" widget="image" options="{ 'size': [18, 18] }"/>
<field name="race_id"/>
<field name="owner_id" widget="many2one_avatar"/>
<field name="birth_date" />
</list>
</field>
</record>

<record id='shelter.animal_view_kanban' model='ir.ui.view'>
<field name="name">shelter.animal.kanban</field>
<field name="model">shelter.animal</field>
<field name="arch" type="xml">
<kanban>
<templates>
<t t-name="kanban-card" class="flex-row">
<widget name="web_ribbon" title="Adopted" bg_color="text-bg-success" invisible="state != 'adopted'"/>
<aside class="o_kanban_aside_full">
<field name="picture" class="w-100" widget="image" options="{'img_class': 'object-fit-cover w-100 h-100'}" invisible="not picture"/>
<field name="pictogram" class="w-100" widget="image" options="{'img_class': 'object-fit-content w-100 h-100'}" invisible="picture"/>
</aside>
<main class="d-flex justify-content-evenly">
<field name="name"/>
<field name="owner_id" widget="many2one_avatar" />
</main>
</t>

</templates>
</kanban>
</field>

</record>

<record id='shelter.animal_view_form' model='ir.ui.view'>
<field name="name">shelter.animal.form</field>
<field name="model">shelter.animal</field>
<field name="arch" type="xml">
<form>
<header>
<field name="state" widget="statusbar" options="{ 'clickable': True }" />
</header>
<sheet>
<widget name="web_ribbon" title="Adopted" bg_color="text-bg-success" invisible="state != 'adopted'"/>
<group col="4">
<group col="2">
<field name="name" />
<field name="type_id" />
<field name="race_id" />
<field name="owner_id" widget="many2one_avatar" />
<field name="dropper_id" widget="many2one_avatar" />
<field name="birth_date" />
</group>
<group col="2">
<field nolabel="1" name="picture" widget="image"/>
</group>
</group>
<notebook>
<page name="notes" string="Notes">
<field name="notes" />
</page>
</notebook>
</sheet>
<chatter/>
</form>
</field>
</record>

<menuitem name="Shelter" id="shelter.menu_root" groups="base.group_user" web_icon="shelter,static/description/icon.png"/>
<menuitem name="Animals" id="shelter.animal_menu" parent="shelter.menu_root" action="shelter.animal_action" sequence="1"/>

</data>
</odoo>

0 comments on commit ca54758

Please sign in to comment.