diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..e135712e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,41 @@ +language: python +sudo: false +cache: + apt: true + directories: + - $HOME/.cache/pip + +python: + - "3.5" + +addons: + postgresql: "9.6" + apt: + packages: + - expect-dev # provides unbuffer utility + - python-lxml # because pip installation is slow + - python-simplejson + - python-serial + - python-yaml +env: + global: + - VERSION="12.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0" + - TRANSIFEX_USER='transbot@odoo-community.org' + + matrix: + - LINT_CHECK="1" + - TRANSIFEX="1" + - TESTS="1" ODOO_REPO="OCA/OCB" + - TESTS="1" ODOO_REPO="odoo/odoo" + + +install: + - git clone --depth=1 https://github.com/Eficent/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools + - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} + - travis_install_nightly + +script: + - travis_run_tests + +after_success: + - travis_after_tests_success \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 00000000..182e22b3 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +My Odoo Custom Addons diff --git a/certification/__init__.py b/certification/__init__.py new file mode 100644 index 00000000..be69358d --- /dev/null +++ b/certification/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import models +from . import reports \ No newline at end of file diff --git a/certification/__manifest__.py b/certification/__manifest__.py new file mode 100644 index 00000000..d397ce90 --- /dev/null +++ b/certification/__manifest__.py @@ -0,0 +1,36 @@ +# Copyright 2014-2015 Grupo ESOC +# Copyright 2017-Apertoso N.V. () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Certification", + "summary": "Track partner certifications", + 'version': '12.0.1.0.0', + "category": "Customer Relationship Management", + "website": "https://github.com/oca/partner-contact", + "author": "Grupo ESOC, Tecnativa, Odoo Community Association (OCA)", + "contributors": [ + 'Jairo Llopis ', + 'Richard deMeester ', + ], + "license": "AGPL-3", + 'application': False, + 'installable': True, + 'auto_install': False, + "depends": [ + "base", + ], + "data": [ + "views/certification.xml", + "views/standart.xml", + 'security/ir.model.access.csv', + 'security/certification_security.xml', + "views/res_partner.xml", + "reports/certification_view.xml", + "reports/report_certification_pdf.xml", + "reports/certification_template_pdf.xml", + + + ], + 'demo': ['demo/certification_data.xml'], + +} diff --git a/certification/demo/certification_data.xml b/certification/demo/certification_data.xml new file mode 100644 index 00000000..4eaf0776 --- /dev/null +++ b/certification/demo/certification_data.xml @@ -0,0 +1,33 @@ + + + + + + Entity Demo + True + + + + Supplier Demo + False + + + + Standard Demo + + + + Demo Certification + 2019-12-31 + + + + + + + + \ No newline at end of file diff --git a/certification/models/__init__.py b/certification/models/__init__.py new file mode 100644 index 00000000..ff999ad8 --- /dev/null +++ b/certification/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import certification +from . import standart +from . import res_partner diff --git a/certification/models/certification.py b/certification/models/certification.py new file mode 100644 index 00000000..29d3fbd7 --- /dev/null +++ b/certification/models/certification.py @@ -0,0 +1,51 @@ +# Copyright 2014-2015 Grupo ESOC +# Copyright 2017-Apertoso N.V. () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from datetime import timedelta +from odoo import fields, models, api +from odoo.exceptions import ValidationError + + +class Certification(models.Model): + _name = 'certification' + _description = 'Certification' + + number = fields.Char() + date = fields.Date(string='Validation Date') + description = fields.Text(string='Validation Details') + standard_id = fields.Many2one('certification.standard') + owner_id = fields.Many2one("res.partner") + entity_id = fields.Many2one("res.partner") + + expiry_days = fields.Integer('Expiry Days', readonly=True, + compute='_compute_expiry_days') + expiry_status = fields.Selection([ + ('expired', "Expired"), + ('available', "Available") + ], readonly=True, compute='_compute_expiry_days', store=True) + + @api.constrains('entity_id') + def _check_entity_id(self): + if self.entity_id and self.entity_id.is_certification_body == False: + raise ValidationError('It is not a certification entity') + + @api.onchange('date') + def _compute_expiry_days(self): + if self.date: + self.expiry_days = (self.date - fields.Date.today()).days + + if self.expiry_days > 0: + self.expiry_status = 'available' + else: + self.expiry_status = 'expired' + + + @api.multi + def update_date_one_month(self): + + self.ensure_one() + if self.date: + self.write({'date': self.date + timedelta(days=30)}) + + + diff --git a/certification/models/identity.py b/certification/models/identity.py new file mode 100644 index 00000000..a6924cf1 --- /dev/null +++ b/certification/models/identity.py @@ -0,0 +1,25 @@ +# Copyright 2014-2015 Grupo ESOC +# Copyright 2017-Apertoso N.V. () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models, api +from odoo.exceptions import ValidationError + + +class Identity(models.Model): + _name = 'id' + _description = 'Certification' + + number = fields.Char() + date = fields.Date(string='Validation Date') + description = fields.Text(string='Validation Details') + standard_id = fields.Many2one('certification.standard') + owner_id = fields.Many2one("res.partner") + entity_id = fields.Many2one("res.partner") + + + @api.constrains('entity_id') + def _check_entity_id(self): + + if self.entity_id and self.entity_id.is_certification_body == False: + raise ValidationError('It is not a certification entity') diff --git a/certification/models/res_partner.py b/certification/models/res_partner.py new file mode 100644 index 00000000..c142fe0b --- /dev/null +++ b/certification/models/res_partner.py @@ -0,0 +1,13 @@ +# Copyright 2014-2015 Grupo ESOC +# Copyright 2017-Apertoso N.V. () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + certification_ids = fields.One2many(comodel_name='certification', inverse_name='owner_id') + is_certification_body = fields.Boolean(string='It is an entity', default='True', + help='Check this box if the contact is a certification entity') diff --git a/certification/models/standart.py b/certification/models/standart.py new file mode 100644 index 00000000..fd599c86 --- /dev/null +++ b/certification/models/standart.py @@ -0,0 +1,13 @@ +# Copyright 2014-2015 Grupo ESOC +# Copyright 2017-Apertoso N.V. () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields, api + + +class CertificationStandard(models.Model): + _name = 'certification.standard' + _description = 'Certification Types' + + name = fields.Char() + description = fields.Text() diff --git a/certification/reports/__init__.py b/certification/reports/__init__.py new file mode 100644 index 00000000..da762a74 --- /dev/null +++ b/certification/reports/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import certification_report diff --git a/certification/reports/certification_report.py b/certification/reports/certification_report.py new file mode 100644 index 00000000..fc0de1d6 --- /dev/null +++ b/certification/reports/certification_report.py @@ -0,0 +1,69 @@ +from psycopg2.extensions import AsIs +from odoo import tools +from odoo import api, fields, models + + +class CertificationReport(models.Model): + _name = "certification.report" + _description = "Certification Report" + _auto = False + + entity_id = fields.Many2one('res.partner', readonly=True) + certification_count = fields.Integer(readonly=True) + standard_id = fields.Many2one('certification.standard') + expiry_status = fields.Selection([ + ('expired', "Expired"), + ('available', "Available")], readonly=True) + + def _select(self): + select_str = """ + SELECT + rp.id AS id, + rp.id AS entity_id, + cs.id AS standard_id, + c.expiry_status AS expiry_status, + count(c.id) AS certification_count + """ + + return select_str + + def _from(self): + from_str = """ + res_partner AS rp + JOIN certification AS c + ON c.entity_id = rp.id + JOIN certification_standard AS cs + ON cs.id = c.standard_id + """ + + return from_str + + def _where(self): + where_str = """rp.is_certification_body is True""" + + return where_str + + def _group_by(self): + group_by_str = """ + GROUP BY + rp.id, + rp.id, + cs.id, + c.expiry_status + """ + + return group_by_str + + @api.model_cr + def init(self): + tools.drop_view_if_exists(self.env.cr, + self._table) + self.env.cr.execute( + """ + CREATE or REPLACE VIEW %s as (%s + FROM ( %s ) WHERE ( %s ) + %s)""", + (AsIs(self._table), AsIs(self._select()), + AsIs(self._from()), AsIs(self._where()), + AsIs(self._group_by())), + ) diff --git a/certification/reports/certification_template_pdf.xml b/certification/reports/certification_template_pdf.xml new file mode 100644 index 00000000..31b45abc --- /dev/null +++ b/certification/reports/certification_template_pdf.xml @@ -0,0 +1,46 @@ + + + + \ No newline at end of file diff --git a/certification/reports/certification_view.xml b/certification/reports/certification_view.xml new file mode 100644 index 00000000..77e64fc0 --- /dev/null +++ b/certification/reports/certification_view.xml @@ -0,0 +1,48 @@ + + + + certification.report.pivot + certification.report + + + + + + + + + + + + + certification.report.graph + certification.report + + + + + + + + + + + + + + + + diff --git a/certification/reports/report_certification_pdf.xml b/certification/reports/report_certification_pdf.xml new file mode 100644 index 00000000..4644db0b --- /dev/null +++ b/certification/reports/report_certification_pdf.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/certification/security/certification_security.xml b/certification/security/certification_security.xml new file mode 100644 index 00000000..5eca9731 --- /dev/null +++ b/certification/security/certification_security.xml @@ -0,0 +1,22 @@ + + + + + Certification + 10 + + + + Certification User + + + + + Certification Manager + + + + + + \ No newline at end of file diff --git a/certification/security/ir.model.access.csv b/certification/security/ir.model.access.csv new file mode 100644 index 00000000..ef338006 --- /dev/null +++ b/certification/security/ir.model.access.csv @@ -0,0 +1,4 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_certification_user,certification,model_certification,base.group_user,1,1,1,1 +access_certification_standard_user,certification.standard,model_certification_standard,base.group_user,1,1,1,1 +access_certification_report_user,certification.report,model_certification_report,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/certification/tests/__init__.py b/certification/tests/__init__.py new file mode 100644 index 00000000..21baaf66 --- /dev/null +++ b/certification/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import test_certification diff --git a/certification/tests/test_certification.py b/certification/tests/test_certification.py new file mode 100644 index 00000000..4529d89d --- /dev/null +++ b/certification/tests/test_certification.py @@ -0,0 +1,18 @@ +import odoo.tests.common as common + +class TestCertification(common.TransactionCase): + + def setUp(self): + super(TestCertification, self).setUp() + + self.res_partner = self.env['res.partner'] + self.partner = self.res_partner.create({ + 'name': "test1", + 'email': "test@test.com"}) + + def test_certification(self): + certification = self.env['certification'].create({ + 'number': 'AAA', + 'date': '2025-12-31'}) + + self.assertEqual(certification.expiry_status, 'available') \ No newline at end of file diff --git a/certification/views/certification.xml b/certification/views/certification.xml new file mode 100644 index 00000000..847516b3 --- /dev/null +++ b/certification/views/certification.xml @@ -0,0 +1,52 @@ + + + + Certification + certification + + + + + + + + + + + + + Certification + certification + +
+ + + + + + + + + + +