From 5bf66c6a26186f4ec58780f64ccd658c12f12d10 Mon Sep 17 00:00:00 2001 From: Ignacio Cainelli Date: Wed, 6 Dec 2023 16:31:35 -0300 Subject: [PATCH] [NEW] account_followup_trafficlight: new module task 33784 --- account_followup_trafficlight/README.rst | 66 ++++++++++++++++ account_followup_trafficlight/__init__.py | 1 + account_followup_trafficlight/__manifest__.py | 19 +++++ .../data/ir_cron_data.xml | 35 +++++++++ .../models/__init__.py | 1 + .../models/res_partner.py | 8 ++ .../views/res_partner_views.xml | 76 +++++++++++++++++++ 7 files changed, 206 insertions(+) create mode 100644 account_followup_trafficlight/README.rst create mode 100644 account_followup_trafficlight/__init__.py create mode 100644 account_followup_trafficlight/__manifest__.py create mode 100644 account_followup_trafficlight/data/ir_cron_data.xml create mode 100644 account_followup_trafficlight/models/__init__.py create mode 100644 account_followup_trafficlight/models/res_partner.py create mode 100644 account_followup_trafficlight/views/res_partner_views.xml diff --git a/account_followup_trafficlight/README.rst b/account_followup_trafficlight/README.rst new file mode 100644 index 000000000..1e964b9ef --- /dev/null +++ b/account_followup_trafficlight/README.rst @@ -0,0 +1,66 @@ +.. |company| replace:: ADHOC SA + +.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png + :alt: ADHOC SA + :target: https://www.adhoc.com.ar + +.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png + +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +============================== +Account Follow-up Trafficlight +============================== + +TODO + +Installation +============ + +To install this module, you need to: + +#. Just install this module. + +Configuration +============= + +To configure this module, you need to: + +#. No configuration nedeed. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: http://runbot.adhoc.com.ar/ + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 +======= + +Images +------ + +* |company| |icon| + +Contributors +------------ + +Maintainer +---------- + +|company_logo| + +This module is maintained by the |company|. + +To contribute to this module, please visit https://www.adhoc.com.ar. diff --git a/account_followup_trafficlight/__init__.py b/account_followup_trafficlight/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_followup_trafficlight/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_followup_trafficlight/__manifest__.py b/account_followup_trafficlight/__manifest__.py new file mode 100644 index 000000000..7e0e08a22 --- /dev/null +++ b/account_followup_trafficlight/__manifest__.py @@ -0,0 +1,19 @@ +{ + 'name': 'Account Followup Trafficlight', + 'version': "15.0.1.0.0", + 'category': 'Accounting', + 'sequence': 14, + 'summary': 'Calculate semaphore through debt for selected partners', + 'author': 'ADHOC SA', + 'website': 'www.adhoc.com.ar', + 'license': 'AGPL-3', + 'depends': [ + 'account_followup', + ], + 'data': [ + 'data/ir_cron_data.xml', + 'views/res_partner_views.xml', + ], + 'installable': True, + 'application': False, +} diff --git a/account_followup_trafficlight/data/ir_cron_data.xml b/account_followup_trafficlight/data/ir_cron_data.xml new file mode 100644 index 000000000..1acbcd41b --- /dev/null +++ b/account_followup_trafficlight/data/ir_cron_data.xml @@ -0,0 +1,35 @@ + + + + Calcular Semaforo + + code + action + +domain = [('account_id.internal_type', '=', 'receivable'), ('full_reconcile_id', '=', False), ('amount_residual','>', 0), ('parent_state','=','posted')] +all_partner_ids = [] +to_date = datetime.date.today() +# first_date_of_year = to_date.replace(day=1, month=1) + +# vamos buscando en peridos de tiempo hacia atras, desde hace un mes hasta hoy, luego desde hace dos meses hasta hace un mes, etc... +# y vamos a ir escribiendo el valor de semaforo correspondiente. +# al hacerlo de esta manera solo hay 4 search y 4 write +for months, semaphore in [(1, '1'), (2, '2'), (3, '3'), (999, '999')]: + from_date = to_date - dateutil.relativedelta.relativedelta(months=months) + # si se queiere que solo se tengan en cuenta deudas de año actual + # res = env['account.move.line'].read_group(domain + [('first_date_of_year', '>=', first_date_of_year), ('date_maturity', '>=', from_date) + #, ('date_maturity', '<', to_date)], ['partner_id'], 'partner_id') + res = env['account.move.line'].read_group(domain + [('date_maturity', '>=', from_date), ('date_maturity', '<', to_date)], ['partner_id'], 'partner_id') + to_date = from_date + partner_ids = [x['partner_id'][0] for x in res] + env['res.partner'].browse(partner_ids).write({'semaphore': semaphore}) + all_partner_ids += partner_ids + +env['res.partner'].search([('id', 'not in', all_partner_ids), ('semaphore', '!=', False)]).write({'semaphore': False}) + + + 1 + days + -1 + + diff --git a/account_followup_trafficlight/models/__init__.py b/account_followup_trafficlight/models/__init__.py new file mode 100644 index 000000000..91fed54d4 --- /dev/null +++ b/account_followup_trafficlight/models/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/account_followup_trafficlight/models/res_partner.py b/account_followup_trafficlight/models/res_partner.py new file mode 100644 index 000000000..6bf88ba11 --- /dev/null +++ b/account_followup_trafficlight/models/res_partner.py @@ -0,0 +1,8 @@ +from odoo import models, fields, api, _ + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + semaphore = fields.Selection(string='Semáforo', selection=[('1', '1 Mes'), ('2', '2 Meses'), ('3', '3 Meses'), ('999', '>= 4 Meses')]) + diff --git a/account_followup_trafficlight/views/res_partner_views.xml b/account_followup_trafficlight/views/res_partner_views.xml new file mode 100644 index 000000000..92c731db6 --- /dev/null +++ b/account_followup_trafficlight/views/res_partner_views.xml @@ -0,0 +1,76 @@ + + + + customer.statements.tree.inherit + res.partner + 99 + + + + +