Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request #5

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
My Odoo Custom Addons
3 changes: 3 additions & 0 deletions certification/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models
from . import reports
36 changes: 36 additions & 0 deletions certification/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2014-2015 Grupo ESOC <www.grupoesoc.es>
# Copyright 2017-Apertoso N.V. (<http://www.apertoso.be>)
# 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 <j.llopis@grupoesoc.es>',
'Richard deMeester <richard@willowit.com.au>',
],
"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'],

}
33 changes: 33 additions & 0 deletions certification/demo/certification_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>


<record id="entity_demo"
model="res.partner">
<field name="name">Entity Demo</field>
<field name="is_certification_body">True</field>
</record>

<record id="supplier_demo"
model="res.partner">
<field name="name">Supplier Demo</field>
<field name="is_certification_body">False</field>
</record>

<record id="standard_demo"
model="certification.standard">
<field name="name">Standard Demo</field>
</record>

<record id="certification_demo"
model="certification">
<field name="number">Demo Certification</field>
<field name="date">2019-12-31</field>
<field name="standard_id" eval="ref('standard_demo')"/>
<field name="entity_id" eval="ref('entity_demo')"/>
<field name="owner_id" eval="ref('supplier_demo')"/>
</record>



</odoo>
4 changes: 4 additions & 0 deletions certification/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions certification/models/certification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2014-2015 Grupo ESOC <www.grupoesoc.es>
# Copyright 2017-Apertoso N.V. (<http://www.apertoso.be>)
# 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)})



25 changes: 25 additions & 0 deletions certification/models/identity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2014-2015 Grupo ESOC <www.grupoesoc.es>
# Copyright 2017-Apertoso N.V. (<http://www.apertoso.be>)
# 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')
13 changes: 13 additions & 0 deletions certification/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2014-2015 Grupo ESOC <www.grupoesoc.es>
# Copyright 2017-Apertoso N.V. (<http://www.apertoso.be>)
# 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')
13 changes: 13 additions & 0 deletions certification/models/standart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2014-2015 Grupo ESOC <www.grupoesoc.es>
# Copyright 2017-Apertoso N.V. (<http://www.apertoso.be>)
# 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()
2 changes: 2 additions & 0 deletions certification/reports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import certification_report
69 changes: 69 additions & 0 deletions certification/reports/certification_report.py
Original file line number Diff line number Diff line change
@@ -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())),
)
46 changes: 46 additions & 0 deletions certification/reports/certification_template_pdf.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="certification_template_pdf">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="doc">
<t t-call="web.internal_layout">
<div class="page">
<h1>Certification Number
<t t-esc="doc.number"/>
</h1>
<table class="table table-condensed">
<thead>
<tr>
<th>Standard</th>
<th>Owner</th>
<th>Owner Category</th>
<th>Certification Body</th>
<th>Expiry Date</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<t t-esc="doc.standard_id.name"/>
</td>
<td>
<t t-esc="doc.owner_id.name"/>
</td>
<td>
<t t-esc="doc.owner_id.category_id.name"/>
</td>
<td>
<t t-esc="doc.entity_id.name"/>
</td>
<td>
<t t-esc="doc.date"/>
</td>
</tr>
</tbody>
</table>
</div>
</t>
</t>
</t>
</template>
</odoo>
Loading