Skip to content

Commit

Permalink
[NEW] account_followup_trafficlight: new module
Browse files Browse the repository at this point in the history
task 33784
  • Loading branch information
ica-adhoc committed Dec 6, 2023
1 parent 16f2348 commit 94fa5df
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 0 deletions.
66 changes: 66 additions & 0 deletions account_followup_trafficlight/README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/ingadhoc/account-financial-tools/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.
1 change: 1 addition & 0 deletions account_followup_trafficlight/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions account_followup_trafficlight/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
35 changes: 35 additions & 0 deletions account_followup_trafficlight/data/ir_cron_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version='1.0' encoding='UTF-8'?>
<odoo>
<record id="account_followup_trafficlight.calcular_semaforo" model="ir.cron">
<field name="name">Calcular Semaforo</field>
<field ref="base.model_res_partner" name="model_id"/>
<field name="state">code</field>
<field name="binding_type">action</field>
<field name="code">
domain = [('account_id.internal_type', '=', 'receivable'), ('full_reconcile_id', '=', False), ('amount_residual','>', 0), ('parent_state','!=','cancel')]
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', '&gt;=', first_date_of_year), ('date_maturity', '&gt;=', from_date)
#, ('date_maturity', '&lt;', to_date)], ['partner_id'], 'partner_id')
res = env['account.move.line'].read_group(domain + [('date_maturity', '&gt;=', from_date), ('date_maturity', '&lt;', 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})

</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions account_followup_trafficlight/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_partner
8 changes: 8 additions & 0 deletions account_followup_trafficlight/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -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')])

76 changes: 76 additions & 0 deletions account_followup_trafficlight/views/res_partner_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version='1.0' encoding='UTF-8'?>
<odoo>
<record id="customer_statements_tree_view_inherit" model="ir.ui.view">
<field name="name">customer.statements.tree.inherit</field>
<field name="model">res.partner</field>
<field name="priority">99</field>
<field ref="account_followup.customer_statements_tree_view" name="inherit_id"/>
<field name="arch" type="xml">
<field name="followup_status" position="after">
<field name="semaphore"/>
<button type="object" icon="fa-pencil-square-o" name="open_partner_ledger" context="{'default_partner_id': active_id}"/>
</field>
<tree position="attributes">
<attribute name="decoration-success">not semaphore</attribute>
<attribute name="decoration-warning">semaphore == '1'</attribute>
<attribute name="decoration-muted">semaphore == '2'</attribute>
<attribute name="decoration-danger">semaphore == '3'</attribute>
<attribute name="decoration-bf">semaphore == '999'</attribute>
</tree>
<field name="followup_status" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="total_overdue" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="followup_level" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>

<record id="customer_statements_search_view" model="ir.ui.view">
<field name="name">customer.statements.search.inherit</field>
<field name="model">res.partner</field>
<field name="priority">99</field>
<field ref="account_followup.customer_statements_search_view" name="inherit_id"/>
<field name="arch" type="xml">
<field name="followup_status" position="before">
<field name="semaphore"/>
</field>
<group>
<separator />
<filter string="Semáforo" name="groupby_semaphore" domain="[]" context="{'group_by': 'semaphore'}"/>
<separator />
</group>
<filter name="inactive" position="before">
<separator />
<filter string="Semáforo 1 mes"
name="filter_semaphore_1_month"
domain="[('semaphore', '=', '1')]"/>
<filter string="Semáforo 2 meses"
name="filter_semaphore_2_month"
domain="[('semaphore', '=', '2')]"/>
<filter string="Semáforo 3 meses"
name="filter_semaphore_3_month"
domain="[('semaphore', '=', '3')]"/>
<filter string="Semáforo >= 4 Meses"
name="filter_semaphore_4_month"
domain="[('semaphore', '=', '999')]"/>
<separator />
</filter>
</field>
</record>

<record model="ir.ui.view" id="res_partner_view_form">
<field name="name">res.partner.view.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="website" position="after">
<field name="semaphore" string="Atraso de deuda" readonly="1"/>
</field>
</field>
</record>

</odoo>

0 comments on commit 94fa5df

Please sign in to comment.