From efbf71d57753ef97b8f2b23f6f7d4c07f54c8048 Mon Sep 17 00:00:00 2001 From: Ahmed Aly Date: Thu, 28 Sep 2017 11:48:45 +0200 Subject: [PATCH] added new module dp_sequence_date_range_monthly, which allows it to have a number range monthly instead of yearly --- .../__init__.py | 24 +++++++ .../__manifest__.py | 41 ++++++++++++ .../models/__init__.py | 26 ++++++++ .../models/ir_sequence.py | 60 ++++++++++++++++++ .../static/description/icon.png | Bin 0 -> 2225 bytes .../views/ir_sequence_view.xml | 18 ++++++ setup/lib/config_at.py | 9 ++- 7 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 ext/custom-addons/dp_sequence_date_range_monthly/__init__.py create mode 100644 ext/custom-addons/dp_sequence_date_range_monthly/__manifest__.py create mode 100644 ext/custom-addons/dp_sequence_date_range_monthly/models/__init__.py create mode 100644 ext/custom-addons/dp_sequence_date_range_monthly/models/ir_sequence.py create mode 100644 ext/custom-addons/dp_sequence_date_range_monthly/static/description/icon.png create mode 100644 ext/custom-addons/dp_sequence_date_range_monthly/views/ir_sequence_view.xml diff --git a/ext/custom-addons/dp_sequence_date_range_monthly/__init__.py b/ext/custom-addons/dp_sequence_date_range_monthly/__init__.py new file mode 100644 index 00000000..f6229e8e --- /dev/null +++ b/ext/custom-addons/dp_sequence_date_range_monthly/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# datenpol gmbh +# Copyright (C) 2013-TODAY datenpol gmbh () +# +# 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 . +# +############################################################################## + +import models + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/ext/custom-addons/dp_sequence_date_range_monthly/__manifest__.py b/ext/custom-addons/dp_sequence_date_range_monthly/__manifest__.py new file mode 100644 index 00000000..7e4bfdb8 --- /dev/null +++ b/ext/custom-addons/dp_sequence_date_range_monthly/__manifest__.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# datenpol gmbh +# Copyright (C) 2013-TODAY datenpol gmbh () +# +# 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 . +# +############################################################################## + + +# noinspection PyStatementEffect +{ + 'name': 'datenpol Sequence date range monthly', + 'category': 'Custom', + 'version': '1.0', + 'description': """Für jeden Monat gibt es eine eigenen Nummernkreis""", + 'author': 'datenpol gmbh', + 'website': 'http://www.datenpol.at/', + 'depends': [ + 'base', + ], + 'data': [ + 'views/ir_sequence_view.xml', + ], + 'installable': True, + 'auto_install': False, +} + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/ext/custom-addons/dp_sequence_date_range_monthly/models/__init__.py b/ext/custom-addons/dp_sequence_date_range_monthly/models/__init__.py new file mode 100644 index 00000000..44d8e2ca --- /dev/null +++ b/ext/custom-addons/dp_sequence_date_range_monthly/models/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 20014-2016 datenpol gmbh (). +# +# 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 . +# +############################################################################## + +import ir_sequence + + + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/ext/custom-addons/dp_sequence_date_range_monthly/models/ir_sequence.py b/ext/custom-addons/dp_sequence_date_range_monthly/models/ir_sequence.py new file mode 100644 index 00000000..b1fe83e6 --- /dev/null +++ b/ext/custom-addons/dp_sequence_date_range_monthly/models/ir_sequence.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# datenpol gmbh +# Copyright (C) 2013-TODAY datenpol gmbh () +# +# 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 . +# +############################################################################## + +from odoo import api, fields, models +from datetime import datetime, timedelta +from dateutil.relativedelta import relativedelta + + +class IrSequence(models.Model): + _inherit = 'ir.sequence' + + monthly_date_range = fields.Boolean('Monthly date_range') + + def _create_date_range_seq(self, date): + year = fields.Date.from_string(date).strftime('%Y') + if self.monthly_date_range: + month = fields.Date.from_string(date).strftime('%m') + last_day = datetime(int(year), int(month), 1) + relativedelta(day=31) + date_from = '{}-{}-01'.format(year, month) + date_to = '{}-{}-{}'.format(year, month, last_day.day) + else: + date_from = '{}-01-01'.format(year) + date_to = '{}-12-31'.format(year) + date_range = self.env['ir.sequence.date_range'].search \ + ([('sequence_id', '=', self.id), ('date_from', '>=', date), ('date_from', '<=', date_to)], + order='date_from desc', limit=1) + if date_range: + date_to = datetime.strptime(date_range.date_from, '%Y-%m-%d') + timedelta(days=-1) + date_to = date_to.strftime('%Y-%m-%d') + date_range = self.env['ir.sequence.date_range'].search \ + ([('sequence_id', '=', self.id), ('date_to', '>=', date_from), ('date_to', '<=', date)], + order='date_to desc', + limit=1) + if date_range: + date_from = datetime.strptime(date_range.date_to, '%Y-%m-%d') + timedelta(days=1) + date_from = date_from.strftime('%Y-%m-%d') + seq_date_range = self.env['ir.sequence.date_range'].sudo().create({ + 'date_from': date_from, + 'date_to': date_to, + 'sequence_id': self.id, + }) + return seq_date_range diff --git a/ext/custom-addons/dp_sequence_date_range_monthly/static/description/icon.png b/ext/custom-addons/dp_sequence_date_range_monthly/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..8387d76554e8c52cf9256f9dc3f0358744f26f8e GIT binary patch literal 2225 zcmV;i2u}BjP)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{005UN6GXZYpd*5GTM;9mttz230kztuXpqw7k0!Bk-aY#xp76VI(r5cRu^;~ayve)o z`g`Zx^W&a#fjsiaBab}t$Rm%O1kLpVeEvYW6vi3`uOQG;0ObG{0Vo1c82h&o0Amac z3c?@*S0U*yqwkfR@9k}wxT6U4cv@TwO0Ihd_zE+s0W3~qx(I+C0Dmlq7KS=I_l!7} zKyTgFVuQ>r%)AM}k_@~e0>V*g^6nEy_W#{61lHC*zVOz(@Q;XTTbxQ}8r@Rz)3ZS& zWmHv*uYVgrD}aS_u|F~Rxp~p~Etyp9j1aiKq51x($uAP{`7AJ$L(HQ2c*n0^$q53h zH*Q%^B!4qkQa7zM67L?n@v*0LTWzfb*3>sW3C6Qo?6!4_uvy>L)jpPW1XkAt_Yi1X zwmZHI^f6pDCl2o&)-j*ZLSB8aH5bT>NlcZ%#Od1F#}{UW1m=L+PAiE<*z}~U&aU*- zwyAL%@~(l<7h7pnh8*XaFap9!FwQXWfgpT=8DER{LkXyoMaHiIe05GFFc!o9Lv@ac zXy*qvN_NFtJFh=jX&BV3{)i0V8i3s*Y`&yQme(Jw6oO7q@eT+-><+cH&MJW(Pm9Z4 zeElo|RjR9SJhcDGnZh}u=o1-;O0F@mV{EuIG?SZBv$1&H`D6wj(ulmjlk;q zU@I~GK$+=Kcc{&lI%p(v2*A$K;nElE`ghfJO^pQnPW=EPY+Z`Pm9Za&u|S1*#O2GBu;T% zBf=R5{?Hw2>q$r7eZGKO&Nu!Bpd$WvxC|B6}U~Iy8e=SmQtMC9E zfUYC$R~UFrF$|4b2_%9~8S0sf6R-?sXkJ!^*4kBLdwU?`Q6-b{G8}}0XkkbhDwIXW zDlG*1{DE>c0B5*PIf=l|&OIZHSoY|)G5MSp0;Mq4s9}_Dr#3slmSlot_GlrH!7G&g z@EjZoI2ewg@!BW+&7GXjkN$ zP9V?c50t9~0|^8sJp#MB+Q&dRs(hvIdps?!oR>bsP%9BeVgjR&z)829_9`QbW1UDj zi}el7_s6PcZxc$~o=mxlZ34SH_MKG^paDFSOc_MB!IZoMO1iEB7 zuXu=3X&J~QdDC<$9qJCXeK(!CjdUI!yxjNpvWluOfVIk>Jj*Mp?ps{E?nE*@92wd3 zHf~uj1Wu}w7i%_r%x-VX^m!H?i%itH6kBA0LH<;%Te|RgT3qgu|NJ!3x&T~~aD7on zm6@Sqv4i~=ddeyubQ5T`@^$W&jBhPlS@qw0OV+(HThi$D2P+Hj8hw>O8xnm~hU?3^ zO7v!}<)48*B5Y5$%jm;mTT}85HNuFG1qz~tn{<{Z&-$ek47^5!U86Tjdv#U$`}~1& zQ-~mef|#axF()pah?fK#*PaY9@k<0cl?s_Yf1q5F@hB4-)pY!n_vF&GCl-~iYYM>L z#XAuO&I!UGOY}3uJMmQkEX4vMS<1vqh-oE&O4zt_iwFlzc5TmONpi-oewsY6i9R)x zdSw8)fAv#BA}5=yHzBz|9(m-EM;>|Pk)!w@TDLdXvm#rS00000NkvXXu0mjf$QcM^ literal 0 HcmV?d00001 diff --git a/ext/custom-addons/dp_sequence_date_range_monthly/views/ir_sequence_view.xml b/ext/custom-addons/dp_sequence_date_range_monthly/views/ir_sequence_view.xml new file mode 100644 index 00000000..ae36fd1f --- /dev/null +++ b/ext/custom-addons/dp_sequence_date_range_monthly/views/ir_sequence_view.xml @@ -0,0 +1,18 @@ + + + + + + + dp_ir_sequence_form + ir.sequence + + + + + + + + + + diff --git a/setup/lib/config_at.py b/setup/lib/config_at.py index 5c5fea13..6f5c17e0 100644 --- a/setup/lib/config_at.py +++ b/setup/lib/config_at.py @@ -141,13 +141,15 @@ class Config(): # 'number_next_actual': 1, 'prefix': '%(y)s', 'padding': 4, - 'use_date_range': True + 'use_date_range': True, + 'monthly_date_range': False }, 'account.invoice': { # 'number_next_actual': 0001, 'prefix': '%(y)s%(month)s', 'padding': 4, - 'use_date_range': True + 'use_date_range': True, + 'monthly_date_range': False }, # Wenn 'account.invoice_refund' auskommentiert ist, dann wird # für die Gutschrift der selbe Nummernkreis verwendet @@ -157,7 +159,8 @@ class Config(): 'implementation': 'no_gap', 'prefix': '%(y)s', 'padding': 4, - 'use_date_range': True + 'use_date_range': True, + 'monthly_date_range': False }, #'picking.out': { # # 'number_next_actual': 1,