diff --git a/animal_owner/README.rst b/animal_owner/README.rst new file mode 100644 index 000000000..21cd7854d --- /dev/null +++ b/animal_owner/README.rst @@ -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. diff --git a/animal_owner/__init__.py b/animal_owner/__init__.py new file mode 100644 index 000000000..3b2a810b9 --- /dev/null +++ b/animal_owner/__init__.py @@ -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 diff --git a/animal_owner/__manifest__.py b/animal_owner/__manifest__.py new file mode 100644 index 000000000..dcee2735f --- /dev/null +++ b/animal_owner/__manifest__.py @@ -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"], +} diff --git a/animal_owner/models/__init__.py b/animal_owner/models/__init__.py new file mode 100644 index 000000000..4324c4e96 --- /dev/null +++ b/animal_owner/models/__init__.py @@ -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 diff --git a/animal_owner/models/animal.py b/animal_owner/models/animal.py new file mode 100644 index 000000000..3bc4e8461 --- /dev/null +++ b/animal_owner/models/animal.py @@ -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" + ) diff --git a/animal_owner/models/res_partner.py b/animal_owner/models/res_partner.py new file mode 100644 index 000000000..66945cb70 --- /dev/null +++ b/animal_owner/models/res_partner.py @@ -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 diff --git a/animal_owner/readme/CONTRIBUTORS.rst b/animal_owner/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..cddff22dc --- /dev/null +++ b/animal_owner/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Open Source Integrators + + * Maxime Chambreuil diff --git a/animal_owner/readme/DESCRIPTION.rst b/animal_owner/readme/DESCRIPTION.rst new file mode 100644 index 000000000..539fc224c --- /dev/null +++ b/animal_owner/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows you to store the owner of a pet. diff --git a/animal_owner/readme/USAGE.rst b/animal_owner/readme/USAGE.rst new file mode 100644 index 000000000..dbb34ff8c --- /dev/null +++ b/animal_owner/readme/USAGE.rst @@ -0,0 +1,3 @@ +* Go to Animals +* Create or select an animal +* Select his owner diff --git a/animal_owner/static/description/icon.png b/animal_owner/static/description/icon.png new file mode 100644 index 000000000..85d01763f Binary files /dev/null and b/animal_owner/static/description/icon.png differ diff --git a/animal_owner/views/animal.xml b/animal_owner/views/animal.xml new file mode 100644 index 000000000..6968c30cf --- /dev/null +++ b/animal_owner/views/animal.xml @@ -0,0 +1,58 @@ + + + + + view.animal.owner.tree + animal + + + + + + + + + + + view.animal.owner.form + animal + + + + + + + + + + + view.animal.owner.kanban + animal + + + + + + +
  • +
    +
    +
    + + + + view.animal.owner.search + animal + + + + + + + + + + + +
    diff --git a/animal_owner/views/res_partner.xml b/animal_owner/views/res_partner.xml new file mode 100644 index 000000000..b7a1c1495 --- /dev/null +++ b/animal_owner/views/res_partner.xml @@ -0,0 +1,22 @@ + + + + + view.partner.animal.owner.form + res.partner + + + + + + + +