Skip to content

Commit

Permalink
[ADD] animal_owner
Browse files Browse the repository at this point in the history
  • Loading branch information
max3903 authored and bealdav committed Dec 7, 2021
1 parent ed02f27 commit 7758b04
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 0 deletions.
21 changes: 21 additions & 0 deletions animal_owner/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
**This file is going to be generated by oca-gen-addon-readme.**

*Manual changes will be overwritten.*

Please provide content in the ``readme`` directory:

* **DESCRIPTION.rst** (required)
* INSTALL.rst (optional)
* CONFIGURE.rst (optional)
* **USAGE.rst** (optional, highly recommended)
* DEVELOP.rst (optional)
* ROADMAP.rst (optional)
* HISTORY.rst (optional, recommended)
* **CONTRIBUTORS.rst** (optional, highly recommended)
* CREDITS.rst (optional)

Content of this README will also be drawn from the addon manifest,
from keys such as name, authors, maintainers, development_status,
and license.

A good, one sentence summary in the manifest is also highly recommended.
3 changes: 3 additions & 0 deletions animal_owner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models
16 changes: 16 additions & 0 deletions animal_owner/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Animal Owner",
"version": "12.0.1.0.0",
"license": "AGPL-3",
"summary": "Add owner to the animal",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"maintainer": "Open Source Integrators",
"website": "https://github.com/OCA/partner-contact",
"depends": ["animal"],
"data": ["views/animal.xml", "views/res_partner.xml"],
"application": False,
"development_status": "Beta",
"maintainers": ["max3903"],
}
3 changes: 3 additions & 0 deletions animal_owner/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import animal, res_partner
11 changes: 11 additions & 0 deletions animal_owner/models/animal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models


class Animal(models.Model):
_inherit = "animal"

partner_id = fields.Many2one(
"res.partner", string="Owner", index=True, track_visibility="onchange"
)
27 changes: 27 additions & 0 deletions animal_owner/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models


class ResPartner(models.Model):
_inherit = "res.partner"

@api.depends("animal_ids")
def _compute_animal_count(self):
for rec in self:
rec.animal_count = len(rec.animal_ids)

animal_ids = fields.One2many("animal", "partner_id", string="Animals")
animal_count = fields.Integer(
compute=_compute_animal_count, string="Number of Animals", store=True
)

@api.multi
def action_view_animals(self):
action = self.env.ref("animal.action_animal").read()[0]
if self.animal_count > 1:
action["domain"] = [("id", "in", self.animal_ids.ids)]
else:
action["views"] = [(self.env.ref("animal.view_animal_form").id, "form")]
action["res_id"] = self.animal_ids and self.animal_ids.ids[0] or False
return action
3 changes: 3 additions & 0 deletions animal_owner/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Open Source Integrators <https://www.opensourceintegrators.com>

* Maxime Chambreuil <[email protected]>
1 change: 1 addition & 0 deletions animal_owner/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows you to store the owner of a pet.
3 changes: 3 additions & 0 deletions animal_owner/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Go to Animals
* Create or select an animal
* Select his owner
Binary file added animal_owner/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions animal_owner/views/animal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<odoo>

<!-- Animal Tree View -->
<record id="view_animal_owner_tree" model="ir.ui.view">
<field name="name">view.animal.owner.tree</field>
<field name="model">animal</field>
<field name="inherit_id" ref="animal.view_animal_tree"/>
<field name="arch" type="xml">
<field name="color_id" position="after">
<field name="partner_id"/>
</field>
</field>
</record>

<!-- Animal Form View -->
<record id="view_animal_owner_form" model="ir.ui.view">
<field name="name">view.animal.owner.form</field>
<field name="model">animal</field>
<field name="inherit_id" ref="animal.view_animal_form"/>
<field name="arch" type="xml">
<field name="birth_date" position="after">
<field name="partner_id"/>
</field>
</field>
</record>

<!-- Animal Kanban View -->
<record id="view_animal_owner_kanban" model="ir.ui.view">
<field name="name">view.animal.owner.kanban</field>
<field name="model">animal</field>
<field name="inherit_id" ref="animal.view_animal_kanban"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="partner_id"/>
</field>
<xpath expr="//div[hasclass('oe_kanban_details')]/ul" position="inside">
<li t-if="record.partner_id.raw_value"><field name="partner_id"/></li>
</xpath>
</field>
</record>

<!-- Animal Search View -->
<record id="view_animal_owner_search" model="ir.ui.view">
<field name="name">view.animal.owner.search</field>
<field name="model">animal</field>
<field name="inherit_id" ref="animal.view_animal_search"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="partner_id"/>
</field>
<filter name="gender" position="before">
<filter name="partner_id" string="Owner" domain=""
context="{'group_by': 'partner_id'}"/>
</filter>
</field>
</record>

</odoo>
22 changes: 22 additions & 0 deletions animal_owner/views/res_partner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<odoo>

<!-- Partner Form View -->
<record id="view_partner_animal_owner_form" model="ir.ui.view">
<field name="name">view.partner.animal.owner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<button name="toggle_active" position="before">
<button class="oe_stat_button" type="object"
name="action_view_animals" icon="fa-pencil-square-o"
context="{'default_partner_id': id}">
<div class="o_stat_info">
<field name="animal_count" class="o_stat_value"/>
<span class="o_stat_text"> Animals</span>
</div>
</button>
</button>
</field>
</record>

</odoo>

0 comments on commit 7758b04

Please sign in to comment.