Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Port hr_expense_sequence to v10
  • Loading branch information
alexis-via committed Jun 6, 2017
1 parent 8d6a3b7 commit de25704
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 135 deletions.
42 changes: 32 additions & 10 deletions hr_expense_sequence/README.rst
@@ -1,18 +1,38 @@
Sequence for HR expense
=======================
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

This module gives a unique number for each HR expense declaration.
============================
Sequence for Expense Reports
============================

This module gives a unique number for each *Expense Report* (object *hr.expense.sheet*).

Configuration
=============

You can change the default sequence (EX0000...) by the one of your choice
going to Settings > Technical > Sequences & Identifiers > Sequences, and
editing _HR expense_ record.
You can change the default sequence (EX0001) by the one of your choice
going to *Settings > Technical > Sequences & Identifiers > Sequences*, and
editing the record _Expense Report sequence_.

You will only have access to that section if your section has _Technical
features_ permission check marked.

Usage
=====

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/116/10.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/hr/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.

Credits
=======

Expand All @@ -24,12 +44,14 @@ Contributors
Maintainer
----------

.. image:: http://odoo-community.org/logo.png
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit http://odoo-community.org.
To contribute to this module, please visit https://odoo-community.org.
21 changes: 9 additions & 12 deletions hr_expense_sequence/__init__.py
@@ -1,17 +1,14 @@
# -*- encoding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################
# -*- coding: utf-8 -*-

from . import models
from openerp import SUPERUSER_ID
from odoo import api, SUPERUSER_ID


def assign_old_sequences(cr, registry):
expense_obj = registry['hr.expense.expense']
sequence_obj = registry['ir.sequence']
expense_ids = expense_obj.search(cr, SUPERUSER_ID, [], order="id")
for expense_id in expense_ids:
expense_obj.write(cr, SUPERUSER_ID, expense_id,
{'number': sequence_obj.get(
cr, SUPERUSER_ID, 'hr.expense')})
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
expense_obj = env['hr.expense.sheet']
sequence_obj = env['ir.sequence']
for expense in expense_obj.search([], order='id'):
expense.write({
'number': sequence_obj.next_by_code('hr.expense.sheet')})
28 changes: 6 additions & 22 deletions hr_expense_sequence/__manifest__.py
@@ -1,28 +1,11 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Odoo Source Management Solution
# Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# -*- coding: utf-8 -*-
# © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'HR expense sequence',
'version': '8.0.1.0.0',
'version': '10.0.1.0.0',
'category': 'HR',
'author': "Serv. Tecnol. Avanzados - Pedro M. Baeza,"
"Odoo Community Association (OCA)",
Expand All @@ -33,7 +16,8 @@
'data': [
'data/hr_expense_data.xml',
'views/hr_expense_expense_view.xml',
'report/report_expense_sheet.xml',
],
'installable': False,
'installable': True,
"post_init_hook": "assign_old_sequences",
}
23 changes: 8 additions & 15 deletions hr_expense_sequence/data/hr_expense_data.xml
@@ -1,18 +1,11 @@
<?xml version="1.0"?>
<openerp>
<data noupdate="1">
<odoo noupdate="1">

<record model="ir.sequence.type" id="seq_type_expense">
<field name="name">Expense sequence</field>
<field name="code">hr.expense</field>
</record>
<record model="ir.sequence" id="seq_expense">
<field name="name">Expense report sequence</field>
<field name="code">hr.expense.sheet</field>
<field name="padding" eval="4"/>
<field name="prefix">EX</field>
</record>

<record model="ir.sequence" id="seq_expense">
<field name="name">Expense sequence</field>
<field name="code">hr.expense</field>
<field name="padding" eval="4"/>
<field name="prefix">EX</field>
</record>

</data>
</openerp>
</odoo>
7 changes: 2 additions & 5 deletions hr_expense_sequence/models/__init__.py
@@ -1,6 +1,3 @@
# -*- encoding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################
# -*- coding: utf-8 -*-

from . import hr_expense_expense
from . import hr_expense_sheet
26 changes: 0 additions & 26 deletions hr_expense_sequence/models/hr_expense_expense.py

This file was deleted.

19 changes: 19 additions & 0 deletions hr_expense_sequence/models/hr_expense_sheet.py
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models, fields, api


class HrExpenseSheet(models.Model):
_inherit = 'hr.expense.sheet'

number = fields.Char(required=True, default="/", readonly=True, copy=False)

@api.model
def create(self, vals):
if vals.get('number', '/') == '/':
number = self.env['ir.sequence'].next_by_code('hr.expense.sheet')
vals['number'] = number
return super(HrExpenseSheet, self).create(vals)
10 changes: 10 additions & 0 deletions hr_expense_sequence/report/report_expense_sheet.xml
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<template id="report_expense_sheet" inherit_id="hr_expense.report_expense_sheet">
<xpath expr="//h2" position="replace">
<h2>Expenses Report <span t-field="o.number"/></h2>
</xpath>
</template>

</odoo>
74 changes: 29 additions & 45 deletions hr_expense_sequence/views/hr_expense_expense_view.xml
@@ -1,53 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>

<record id="view_expenses_tree_sequence" model="ir.ui.view">
<field name="name">hr.expense.expense.tree.sequence</field>
<field name="model">hr.expense.expense</field>
<field name="inherit_id" ref="hr_expense.view_expenses_tree"/>
<field name="arch" type="xml">
<field name="employee_id" position="before">
<field name="number"/>
</field>
<record id="view_hr_expense_sheet_tree" model="ir.ui.view">
<field name="name">hr.expense.sheet.tree.sequence</field>
<field name="model">hr.expense.sheet</field>
<field name="inherit_id" ref="hr_expense.view_hr_expense_sheet_tree"/>
<field name="arch" type="xml">
<field name="name" position="before">
<field name="number"/>
</field>
</record>
</field>
</record>

<record id="view_editable_expenses_tree_sequence" model="ir.ui.view">
<field name="name">hr.expense.expense.tree.sequence</field>
<field name="model">hr.expense.expense</field>
<field name="inherit_id" ref="hr_expense.view_editable_expenses_tree"/>
<field name="arch" type="xml">
<field name="employee_id" position="before">
<field name="number"/>
</field>
<record id="view_hr_expense_sheet_form" model="ir.ui.view">
<field name="name">hr.expense.sheet.form.sequence</field>
<field name="model">hr.expense.sheet</field>
<field name="inherit_id" ref="hr_expense.view_hr_expense_sheet_form"/>
<field name="arch" type="xml">
<field name="employee_id" position="before">
<field name="number"/>
</field>
</record>
</field>
</record>

<record id="view_expenses_form_sequence" model="ir.ui.view">
<field name="name">hr.expense.form.sequence</field>
<field name="model">hr.expense.expense</field>
<field name="inherit_id" ref="hr_expense.view_expenses_form"/>
<field name="arch" type="xml">
<xpath expr="//sheet/group" position="before">
<h1>
<label string="Expense "/>
<field name="number" class="oe_inline"/>
</h1>
</xpath>
<record id="view_hr_expense_sheet_filter" model="ir.ui.view">
<field name="name">hr.expense.sheet.filter.sequence</field>
<field name="model">hr.expense.sheet</field>
<field name="inherit_id" ref="hr_expense.view_hr_expense_sheet_filter"/>
<field name="arch" type="xml">
<field name="name" position="attributes">
<attribute name="filter_domain">['|', ('name', 'ilike', self), ('number', 'ilike', self)]</attribute>
</field>
</record>
</field>
</record>

<record id="view_hr_expense_filter_sequence" model="ir.ui.view">
<field name="name">hr.expense.expense.filter.sequence</field>
<field name="model">hr.expense.expense</field>
<field name="inherit_id" ref="hr_expense.view_hr_expense_filter"/>
<field name="arch" type="xml">
<field name="name" position="attributes">
<attribute name="filter_domain">['|', ('name', 'ilike', self), ('number', 'ilike', self)]</attribute>
</field>
</field>
</record>

</data>
</openerp>
</odoo>

0 comments on commit de25704

Please sign in to comment.