OCA-git-bot
6 years ago
committed by
Jaume Planas
17 changed files with 354 additions and 21 deletions
-
67base_export_manager/i18n/base_export_manager.pot
-
2base_tier_validation_formula/__manifest__.py
-
38sequence_reset_period/README.rst
-
1sequence_reset_period/__init__.py
-
22sequence_reset_period/__manifest__.py
-
47sequence_reset_period/i18n/es.po
-
45sequence_reset_period/i18n/sequence_reset_period.pot
-
1sequence_reset_period/models/__init__.py
-
58sequence_reset_period/models/ir_sequence.py
-
BINsequence_reset_period/static/description/icon.png
-
1sequence_reset_period/tests/__init__.py
-
71sequence_reset_period/tests/test_period.py
-
12sequence_reset_period/views/sequence_views.xml
-
2setup/_metapackage/VERSION.txt
-
1setup/_metapackage/setup.py
-
1setup/base_export_manager/odoo/addons/base_export_manager
-
6setup/base_export_manager/setup.py
@ -0,0 +1,38 @@ |
|||||
|
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.png |
||||
|
:alt: License: LGPL-3 |
||||
|
|
||||
|
===================== |
||||
|
Sequence Reset period |
||||
|
===================== |
||||
|
|
||||
|
This module was written to reset the sequences on the specified times, because |
||||
|
by default they are reset yearly. |
||||
|
|
||||
|
Usage |
||||
|
===== |
||||
|
|
||||
|
* Access sequences and configurate the model to use. |
||||
|
* When sequence is computed, date_range will follow the specified rules |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
|
||||
|
* Enric Tobella <etobella@creublanca.es> |
||||
|
|
||||
|
Maintainer |
||||
|
---------- |
||||
|
|
||||
|
.. image:: https://odoo-community.org/logo.png |
||||
|
:alt: Odoo Community Association |
||||
|
: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. |
||||
|
|
||||
|
To contribute to this module, please visit https://odoo-community.org. |
@ -0,0 +1 @@ |
|||||
|
from . import models |
@ -0,0 +1,22 @@ |
|||||
|
# Copyright (C) 2017 Creu Blanca |
||||
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). |
||||
|
|
||||
|
{ |
||||
|
"name": "Reset Sequences on selected period ranges", |
||||
|
"version": "11.0.1.0.0", |
||||
|
"category": "Reporting", |
||||
|
"website": "https://github.com/OCA/server-ux", |
||||
|
"author": "Creu Blanca, " |
||||
|
"Odoo Community Association (OCA)", |
||||
|
"license": "LGPL-3", |
||||
|
"installable": True, |
||||
|
"application": False, |
||||
|
"summary": "Auto-generate yearly/monthly/weekly/daily sequence " |
||||
|
"period ranges", |
||||
|
"depends": [ |
||||
|
"base", |
||||
|
], |
||||
|
"data": [ |
||||
|
"views/sequence_views.xml", |
||||
|
], |
||||
|
} |
@ -0,0 +1,47 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * sequence_reset_period |
||||
|
# |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 11.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"PO-Revision-Date: 2018-07-13 08:46+0000\n" |
||||
|
"Last-Translator: Enric Tobella <etobella@creublanca.es>\n" |
||||
|
"Language-Team: none\n" |
||||
|
"Language: es\n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Plural-Forms: nplurals=2; plural=n != 1;\n" |
||||
|
"X-Generator: Weblate 3.0.1\n" |
||||
|
|
||||
|
#. module: sequence_reset_period |
||||
|
#: selection:ir.sequence,range_reset:0 |
||||
|
msgid "Daily" |
||||
|
msgstr "Diario" |
||||
|
|
||||
|
#. module: sequence_reset_period |
||||
|
#: selection:ir.sequence,range_reset:0 |
||||
|
msgid "Monthly" |
||||
|
msgstr "Mensual" |
||||
|
|
||||
|
#. module: sequence_reset_period |
||||
|
#: model:ir.model.fields,field_description:sequence_reset_period.field_ir_sequence_range_reset |
||||
|
msgid "Range Reset" |
||||
|
msgstr "Reinicio del Rango" |
||||
|
|
||||
|
#. module: sequence_reset_period |
||||
|
#: selection:ir.sequence,range_reset:0 |
||||
|
msgid "Weekly" |
||||
|
msgstr "Semanal" |
||||
|
|
||||
|
#. module: sequence_reset_period |
||||
|
#: selection:ir.sequence,range_reset:0 |
||||
|
msgid "Yearly" |
||||
|
msgstr "Anual" |
||||
|
|
||||
|
#. module: sequence_reset_period |
||||
|
#: model:ir.model,name:sequence_reset_period.model_ir_sequence |
||||
|
msgid "ir.sequence" |
||||
|
msgstr "ir.sequence" |
@ -0,0 +1,45 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * sequence_reset_period |
||||
|
# |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 11.0\n" |
||||
|
"Report-Msgid-Bugs-To: \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: sequence_reset_period |
||||
|
#: selection:ir.sequence,range_reset:0 |
||||
|
msgid "Daily" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: sequence_reset_period |
||||
|
#: selection:ir.sequence,range_reset:0 |
||||
|
msgid "Monthly" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: sequence_reset_period |
||||
|
#: model:ir.model.fields,field_description:sequence_reset_period.field_ir_sequence_range_reset |
||||
|
msgid "Range Reset" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: sequence_reset_period |
||||
|
#: selection:ir.sequence,range_reset:0 |
||||
|
msgid "Weekly" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: sequence_reset_period |
||||
|
#: selection:ir.sequence,range_reset:0 |
||||
|
msgid "Yearly" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: sequence_reset_period |
||||
|
#: model:ir.model,name:sequence_reset_period.model_ir_sequence |
||||
|
msgid "ir.sequence" |
||||
|
msgstr "" |
||||
|
|
@ -0,0 +1 @@ |
|||||
|
from . import ir_sequence |
@ -0,0 +1,58 @@ |
|||||
|
# Copyright (C) 2017 Creu Blanca |
||||
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). |
||||
|
|
||||
|
from odoo import fields, models |
||||
|
from datetime import datetime, timedelta, date as datetime_date |
||||
|
from dateutil.relativedelta import relativedelta |
||||
|
|
||||
|
|
||||
|
class IrSequence(models.Model): |
||||
|
_inherit = "ir.sequence" |
||||
|
|
||||
|
range_reset = fields.Selection([ |
||||
|
('daily', 'Daily'), |
||||
|
('weekly', 'Weekly'), |
||||
|
('monthly', 'Monthly'), |
||||
|
('yearly', 'Yearly') |
||||
|
]) |
||||
|
|
||||
|
def _compute_date_from_to(self, date): |
||||
|
self.ensure_one() |
||||
|
date_from = date_to = fields.Date.from_string(date) |
||||
|
if self.range_reset == 'weekly': |
||||
|
date_from = date_from - timedelta(days=date_from.weekday()) |
||||
|
date_to = date_from + timedelta(days=6) |
||||
|
elif self.range_reset == 'monthly': |
||||
|
date_from = datetime_date(date_from.year, date_from.month, 1) |
||||
|
date_to = date_from + relativedelta(months=1) |
||||
|
date_to += relativedelta(days=-1) |
||||
|
elif self.range_reset == 'yearly': |
||||
|
date_from = datetime_date(date_from.year, 1, 1) |
||||
|
date_to = datetime_date(date_from.year, 12, 31) |
||||
|
return date_from.strftime('%Y-%m-%d'), date_to.strftime('%Y-%m-%d') |
||||
|
|
||||
|
def _create_date_range_seq(self, date): |
||||
|
self.ensure_one() |
||||
|
if not self.range_reset: |
||||
|
return super()._create_date_range_seq(date) |
||||
|
date_from, date_to = self._compute_date_from_to(date) |
||||
|
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 |
After Width: 128 | Height: 128 | Size: 9.2 KiB |
@ -0,0 +1 @@ |
|||||
|
from . import test_period |
@ -0,0 +1,71 @@ |
|||||
|
# Copyright 2017 Creu Blanca <https://creublanca.es/> |
||||
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). |
||||
|
|
||||
|
|
||||
|
from odoo.tests import common |
||||
|
from datetime import datetime |
||||
|
|
||||
|
|
||||
|
class TestSequence(common.TransactionCase): |
||||
|
def setUp(self): |
||||
|
super().setUp() |
||||
|
self.date = datetime(2018, 3, 14).strftime('%Y-%m-%d') |
||||
|
|
||||
|
def get_sequence(self, method): |
||||
|
return self.env['ir.sequence'].create({ |
||||
|
'name': 'Test sequence', |
||||
|
'implementation': 'standard', |
||||
|
'use_date_range': True, |
||||
|
'range_reset': method, |
||||
|
'padding': '5' |
||||
|
}) |
||||
|
|
||||
|
def test_none(self): |
||||
|
sequence = self.get_sequence(False) |
||||
|
self.assertFalse(sequence.date_range_ids) |
||||
|
self.assertEqual('00001', sequence.with_context( |
||||
|
ir_sequence_date=self.date).next_by_id()) |
||||
|
range = sequence.date_range_ids |
||||
|
self.assertTrue(range) |
||||
|
self.assertEqual('2018-01-01', range.date_from) |
||||
|
self.assertEqual('2018-12-31', range.date_to) |
||||
|
|
||||
|
def test_daily(self): |
||||
|
sequence = self.get_sequence('daily') |
||||
|
self.assertFalse(sequence.date_range_ids) |
||||
|
self.assertEqual('00001', sequence.with_context( |
||||
|
ir_sequence_date=self.date).next_by_id()) |
||||
|
range = sequence.date_range_ids |
||||
|
self.assertTrue(range) |
||||
|
self.assertEqual(self.date, range.date_from) |
||||
|
self.assertEqual(self.date, range.date_to) |
||||
|
|
||||
|
def test_weekly(self): |
||||
|
sequence = self.get_sequence('weekly') |
||||
|
self.assertFalse(sequence.date_range_ids) |
||||
|
self.assertEqual('00001', sequence.with_context( |
||||
|
ir_sequence_date=self.date).next_by_id()) |
||||
|
range = sequence.date_range_ids |
||||
|
self.assertTrue(range) |
||||
|
self.assertEqual('2018-03-12', range.date_from) |
||||
|
self.assertEqual('2018-03-18', range.date_to) |
||||
|
|
||||
|
def test_monthly(self): |
||||
|
sequence = self.get_sequence('monthly') |
||||
|
self.assertFalse(sequence.date_range_ids) |
||||
|
self.assertEqual('00001', sequence.with_context( |
||||
|
ir_sequence_date=self.date).next_by_id()) |
||||
|
range = sequence.date_range_ids |
||||
|
self.assertTrue(range) |
||||
|
self.assertEqual('2018-03-01', range.date_from) |
||||
|
self.assertEqual('2018-03-31', range.date_to) |
||||
|
|
||||
|
def test_yearly(self): |
||||
|
sequence = self.get_sequence('yearly') |
||||
|
self.assertFalse(sequence.date_range_ids) |
||||
|
self.assertEqual('00001', sequence.with_context( |
||||
|
ir_sequence_date=self.date).next_by_id()) |
||||
|
range = sequence.date_range_ids |
||||
|
self.assertTrue(range) |
||||
|
self.assertEqual('2018-01-01', range.date_from) |
||||
|
self.assertEqual('2018-12-31', range.date_to) |
@ -0,0 +1,12 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<record id="sequence_view" model="ir.ui.view"> |
||||
|
<field name="model">ir.sequence</field> |
||||
|
<field name="inherit_id" ref="base.sequence_view"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<field name="use_date_range" position="after"> |
||||
|
<field name="range_reset" attrs="{'invisible': [('use_date_range','=', False)]}"/> |
||||
|
</field> |
||||
|
</field> |
||||
|
</record> |
||||
|
</odoo> |
@ -1 +1 @@ |
|||||
12.0.20190528.0 |
|
||||
|
12.0.20190605.0 |
@ -0,0 +1 @@ |
|||||
|
../../../../base_export_manager |
@ -0,0 +1,6 @@ |
|||||
|
import setuptools |
||||
|
|
||||
|
setuptools.setup( |
||||
|
setup_requires=['setuptools-odoo'], |
||||
|
odoo_addon=True, |
||||
|
) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue