Skip to content

Commit

Permalink
凭证号自动重置,模块升级。
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbert-yuan committed May 12, 2017
1 parent fe78196 commit 400a155
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ir_sequence_autoreset/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Auto reset sequence by year,month,day
# Copyright 2013 wangbuke <[email protected]>
# Copyright 2017 开阖软件 <www.osbzr.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/>.
#
##############################################################################
import ir_sequence
48 changes: 48 additions & 0 deletions ir_sequence_autoreset/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Auto reset sequence by year,month,day
# Copyright 2017 开阖软件 <www.osbzr.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/>.
#
##############################################################################
{
'name': 'ir_sequence_autoreset',
'version': '0.1',
'category' : 'Others',
'description': """
Auto reset sequence by year,month,day
功能:自动重置序列编号
如果您觉得好用,请进入下面的网址,付费支持作者 ~
http://me.alipay.com/wangbuke
谢谢!
""",
'author': '[email protected]',
'website': 'http://buke.github.io',
'depends': ['base'],
'data': [
'ir_sequence.xml',
],
'installable': True,
'images': [],
}

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
94 changes: 94 additions & 0 deletions ir_sequence_autoreset/i18n/ir_sequence_autoreset.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * ir_sequence_autoreset
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0-20130723-231040\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-08-20 07:27+0000\n"
"PO-Revision-Date: 2013-08-20 07:27+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: ir_sequence_autoreset
#: selection:ir.sequence,reset_period:0
msgid "Every Hour"
msgstr ""

#. module: ir_sequence_autoreset
#: model:ir.model.fields,field_description:ir_sequence_autoreset.field_ir_sequence_reset_init_number
#: field:ir.sequence,reset_init_number:0
msgid "Reset Number"
msgstr ""

#. module: ir_sequence_autoreset
#: model:ir.model.fields,field_description:ir_sequence_autoreset.field_ir_sequence_reset_time
#: field:ir.sequence,reset_time:0
msgid "Name"
msgstr ""

#. module: ir_sequence_autoreset
#: selection:ir.sequence,reset_period:0
msgid "Every Second"
msgstr ""

#. module: ir_sequence_autoreset
#: model:ir.model.fields,field_description:ir_sequence_autoreset.field_ir_sequence_reset_period
#: field:ir.sequence,reset_period:0
msgid "Reset Period"
msgstr ""

#. module: ir_sequence_autoreset
#: code:addons/ir_sequence_autoreset/ir_sequence.py:71
#, python-format
msgid "Invalid prefix or suffix for sequence '%s'"
msgstr ""

#. module: ir_sequence_autoreset
#: selection:ir.sequence,reset_period:0
msgid "Every Year"
msgstr ""

#. module: ir_sequence_autoreset
#: selection:ir.sequence,reset_period:0
msgid "Every Month"
msgstr ""

#. module: ir_sequence_autoreset
#: help:ir.sequence,reset_init_number:0
msgid "Reset number of this sequence"
msgstr ""

#. module: ir_sequence_autoreset
#: selection:ir.sequence,reset_period:0
msgid "Every Day"
msgstr ""

#. module: ir_sequence_autoreset
#: code:addons/ir_sequence_autoreset/ir_sequence.py:71
#, python-format
msgid "Warning"
msgstr ""

#. module: ir_sequence_autoreset
#: model:ir.model,name:ir_sequence_autoreset.model_ir_sequence
msgid "ir.sequence"
msgstr ""

#. module: ir_sequence_autoreset
#: model:ir.model.fields,field_description:ir_sequence_autoreset.field_ir_sequence_auto_reset
#: view:ir.sequence:0
#: field:ir.sequence,auto_reset:0
msgid "Auto Reset"
msgstr ""

#. module: ir_sequence_autoreset
#: selection:ir.sequence,reset_period:0
msgid "Every Minute"
msgstr ""

94 changes: 94 additions & 0 deletions ir_sequence_autoreset/i18n/zh_CN.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * ir_sequence_autoreset
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0-20130723-231040\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-08-20 07:29+0000\n"
"PO-Revision-Date: 2013-08-20 07:29+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: ir_sequence_autoreset
#: selection:ir.sequence,reset_period:0
msgid "Every Hour"
msgstr "每小时"

#. module: ir_sequence_autoreset
#: model:ir.model.fields,field_description:ir_sequence_autoreset.field_ir_sequence_reset_init_number
#: field:ir.sequence,reset_init_number:0
msgid "Reset Number"
msgstr "起始序号"

#. module: ir_sequence_autoreset
#: model:ir.model.fields,field_description:ir_sequence_autoreset.field_ir_sequence_reset_time
#: field:ir.sequence,reset_time:0
msgid "Name"
msgstr "名称"

#. module: ir_sequence_autoreset
#: selection:ir.sequence,reset_period:0
msgid "Every Second"
msgstr "每秒"

#. module: ir_sequence_autoreset
#: model:ir.model.fields,field_description:ir_sequence_autoreset.field_ir_sequence_reset_period
#: field:ir.sequence,reset_period:0
msgid "Reset Period"
msgstr "重置周期"

#. module: ir_sequence_autoreset
#: code:addons/ir_sequence_autoreset/ir_sequence.py:71
#, python-format
msgid "Invalid prefix or suffix for sequence '%s'"
msgstr "无效前缀 '%s'"

#. module: ir_sequence_autoreset
#: selection:ir.sequence,reset_period:0
msgid "Every Year"
msgstr "每年"

#. module: ir_sequence_autoreset
#: selection:ir.sequence,reset_period:0
msgid "Every Month"
msgstr "每月"

#. module: ir_sequence_autoreset
#: help:ir.sequence,reset_init_number:0
msgid "Reset number of this sequence"
msgstr "起始序号"

#. module: ir_sequence_autoreset
#: selection:ir.sequence,reset_period:0
msgid "Every Day"
msgstr "每天"

#. module: ir_sequence_autoreset
#: code:addons/ir_sequence_autoreset/ir_sequence.py:71
#, python-format
msgid "Warning"
msgstr "警告"

#. module: ir_sequence_autoreset
#: model:ir.model,name:ir_sequence_autoreset.model_ir_sequence
msgid "ir.sequence"
msgstr "ir.sequence"

#. module: ir_sequence_autoreset
#: model:ir.model.fields,field_description:ir_sequence_autoreset.field_ir_sequence_auto_reset
#: view:ir.sequence:0
#: field:ir.sequence,auto_reset:0
msgid "Auto Reset"
msgstr "自动重置"

#. module: ir_sequence_autoreset
#: selection:ir.sequence,reset_period:0
msgid "Every Minute"
msgstr "每分钟"

68 changes: 68 additions & 0 deletions ir_sequence_autoreset/ir_sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Auto reset sequence by year,month,day
# Copyright 2013 wangbuke <[email protected]>
# Copyright 2017 开阖软件 <www.osbzr.com> port to GoodERP v11
#
# 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/>.
#
##############################################################################

from odoo import models, fields, api,_
from odoo.exceptions import UserError
import pytz
from datetime import datetime

class ir_sequence(models.Model):
_inherit = 'ir.sequence'

auto_reset = fields.Boolean('Auto Reset')
reset_period = fields.Selection(
[('year', 'Every Year'), ('month', 'Every Month'), ('day', 'Every Day'), ('h24', 'Every Hour'), ('min', 'Every Minute'), ('sec', 'Every Second')],
'Reset Period', required=True, default='month')
reset_time = fields.Char('Last reset time', size=64, help="Last time the sequence was reset")
reset_init_number = fields.Integer('Reset Number', required=True, default=1,help="Reset number of this sequence")



def get_next_char(self, number_next):
def _interpolation_dict():
now = range_date = effective_date = datetime.now(pytz.timezone(self._context.get('tz') or 'UTC'))
if self._context.get('ir_sequence_date'):
effective_date = datetime.strptime(self._context.get('ir_sequence_date'), '%Y-%m-%d')
if self._context.get('ir_sequence_date_range'):
range_date = datetime.strptime(self._context.get('ir_sequence_date_range'), '%Y-%m-%d')
sequences = {'year': '%Y', 'month': '%m', 'day': '%d', 'y': '%y', 'doy': '%j', 'woy': '%W',
'weekday': '%w', 'h24': '%H', 'h12': '%I', 'min': '%M', 'sec': '%S'}
res = {}
for key, format in sequences.iteritems():
res[key] = effective_date.strftime(format)
res['range_' + key] = range_date.strftime(format)
res['current_' + key] = now.strftime(format)
return res

d = _interpolation_dict()
current_time = d.get(self['reset_period'])
number_next_actual = False
if self['auto_reset'] and current_time != self['reset_time']:
self.env.cr.execute("UPDATE ir_sequence SET reset_time=%s WHERE id=%s ", (current_time, self['id']))
self.env.cr.commit()
number_next = (self['reset_init_number'],)
number_next_actual = self['reset_init_number'] + self['number_increment']
return_vals = super(ir_sequence, self).get_next_char(number_next)
if number_next_actual:
self.number_next_actual = number_next_actual
self.write({'number_next': number_next_actual})
return return_vals
20 changes: 20 additions & 0 deletions ir_sequence_autoreset/ir_sequence.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record model="ir.ui.view" id="sequence_autoreset_view">
<field name="model">ir.sequence</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.sequence_view" />
<field name="arch" type="xml">
<field name="number_next_actual" position="after">
<field name="auto_reset"/>
<field name="reset_period"/>
<field name="reset_time"/>
<field name="reset_init_number"/>
</field>
</field>
</record>
</data>
</openerp>

0 comments on commit 400a155

Please sign in to comment.