From fe06c37cd58ee892cb4fc4064903f36a2da8627d Mon Sep 17 00:00:00 2001 From: David Beal Date: Wed, 12 Dec 2018 19:57:22 +0100 Subject: [PATCH] ADD 12.0 module company_code (#77) * ADD module company_code * FIX doc * FIX doc * Update company_code/readme/USAGE.rst Co-Authored-By: bealdav --- company_code/README.rst | 76 ++++ company_code/__init__.py | 1 + company_code/__manifest__.py | 20 + company_code/models/__init__.py | 1 + company_code/models/company.py | 32 ++ company_code/readme/CONTRIBUTORS.rst | 1 + company_code/readme/DESCRIPTION.rst | 2 + company_code/readme/USAGE.rst | 11 + company_code/static/description/index.html | 415 +++++++++++++++++++++ company_code/views/company_view.xml | 14 + 10 files changed, 573 insertions(+) create mode 100644 company_code/README.rst create mode 100644 company_code/__init__.py create mode 100644 company_code/__manifest__.py create mode 100644 company_code/models/__init__.py create mode 100644 company_code/models/company.py create mode 100644 company_code/readme/CONTRIBUTORS.rst create mode 100644 company_code/readme/DESCRIPTION.rst create mode 100644 company_code/readme/USAGE.rst create mode 100644 company_code/static/description/index.html create mode 100644 company_code/views/company_view.xml diff --git a/company_code/README.rst b/company_code/README.rst new file mode 100644 index 0000000..0155b00 --- /dev/null +++ b/company_code/README.rst @@ -0,0 +1,76 @@ +============ +Company Code +============ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-akretion%2Fodoo--usability-lightgray.png?logo=github + :target: https://github.com/akretion/odoo-usability/tree/12.0/company_code + :alt: akretion/odoo-usability + +|badge1| |badge2| |badge3| + +- add `code` field to company. +- update name_get with this field + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To display your company code with `name_get()` just +write this code in your custom code according your model + + +```python +class ResPartner(models.Model): + _inherit = 'res.partner' + + def name_get(self): + return self.env['res.company']._add_company_code(super()) +``` + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +David Beal + +Maintainers +~~~~~~~~~~~ + + + +This module is part of the `akretion/odoo-usability `_ project on GitHub. + + +You are welcome to contribute. diff --git a/company_code/__init__.py b/company_code/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/company_code/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/company_code/__manifest__.py b/company_code/__manifest__.py new file mode 100644 index 0000000..8260fbf --- /dev/null +++ b/company_code/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2019 David BEAL @ Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Company Code', + 'summary': 'Add a code field in company', + 'version': '12.0.0.0.1', + 'author': 'Akretion', + 'maintainer': 'Akretion', + 'license': 'AGPL-3', + 'category': 'base', + 'depends': [ + 'base', + ], + 'website': 'http://www.akretion.com/', + 'data': [ + 'views/company_view.xml', + ], + 'installable': True, +} diff --git a/company_code/models/__init__.py b/company_code/models/__init__.py new file mode 100644 index 0000000..52e1016 --- /dev/null +++ b/company_code/models/__init__.py @@ -0,0 +1 @@ +from . import company diff --git a/company_code/models/company.py b/company_code/models/company.py new file mode 100644 index 0000000..7dfca1d --- /dev/null +++ b/company_code/models/company.py @@ -0,0 +1,32 @@ +# Copyright 2019 David BEAL @ Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields + + +class ResCompany(models.Model): + _inherit = 'res.company' + + code = fields.Char( + required=True, default='CODE', + help="Field used in object name as suffix") + + def _add_company_code(self, super_object): + "" + """ Add the `code` field to your _rec_name. Use it like that: + + def name_get(self): + return self.env['res.company']._add_company_code(super()) + """ + records = super_object.__self__ + if records and records[0]._name == 'res.company': + codes = {x.id: x.code for x in records} + else: + codes = {x.id: x['company_id']['code'] for x in records + if getattr(x, 'company_id')} + res = [(elm[0], '%s (%s)' % (elm[1], codes[elm[0]] or '')) + for elm in super_object.name_get()] + return res + + def name_get(self): + return self.env['res.company']._add_company_code(super()) diff --git a/company_code/readme/CONTRIBUTORS.rst b/company_code/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..cc14d2f --- /dev/null +++ b/company_code/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +David Beal diff --git a/company_code/readme/DESCRIPTION.rst b/company_code/readme/DESCRIPTION.rst new file mode 100644 index 0000000..d2f383e --- /dev/null +++ b/company_code/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +- add `code` field to company. +- update name_get with this field diff --git a/company_code/readme/USAGE.rst b/company_code/readme/USAGE.rst new file mode 100644 index 0000000..f9a26e8 --- /dev/null +++ b/company_code/readme/USAGE.rst @@ -0,0 +1,11 @@ +To display your company code with `name_get()` just +write this in your custom code according to your model + + +```python +class ResPartner(models.Model): + _inherit = 'res.partner' + + def name_get(self): + return self.env['res.company']._add_company_code(super()) +``` diff --git a/company_code/static/description/index.html b/company_code/static/description/index.html new file mode 100644 index 0000000..256715f --- /dev/null +++ b/company_code/static/description/index.html @@ -0,0 +1,415 @@ + + + + + + +Company Code + + + +
+

Company Code

+ + +

Beta License: AGPL-3 akretion/odoo-usability

+
    +
  • add code field to company.
  • +
  • update name_get with this field
  • +
+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+ +
+

Maintainers

+

This module is part of the akretion/odoo-usability project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/company_code/views/company_view.xml b/company_code/views/company_view.xml new file mode 100644 index 0000000..241ddda --- /dev/null +++ b/company_code/views/company_view.xml @@ -0,0 +1,14 @@ + + + + + res.company + + + + + + + + +