Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] Added base_edi_exchange module #144

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base_edi_exchange/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
30 changes: 30 additions & 0 deletions base_edi_exchange/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
'name': "Base EDI Exchange",

'summary': """
Base Module for Exchange of EDI documents
""",
'author': "Callino, Odoo Community Association (OCA)",
'website': "http://callino.at",
'development_status': "Beta",
"license": "AGPL-3",
'category': 'Accounting',
'version': '12.0.1.0.0',

# any module necessary for this one to work correctly
'depends': ['base', 'sale', 'account', 'purchase'],

# always loaded
'data': [
'security/groups.xml',
'security/ir.model.access.csv',
'views/base_edi_exchange.xml',
'views/base_edi_transfer.xml',
'views/res_partner.xml',
'views/menu.xml',
'data/ir_cron_data.xml',
],
# only loaded in demonstration mode
'demo': [
],
}
17 changes: 17 additions & 0 deletions base_edi_exchange/data/ir_cron_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>

<record model="ir.cron" id="check_active_exchange">
<field name="name">Check active exchanges</field>
<field name="model_id" ref="base_edi_exchange.model_base_edi_exchange"/>
<field name="state">code</field>
<field name="code">model.check_active_exchanges()</field>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
</record>

</data>
</odoo>
6 changes: 6 additions & 0 deletions base_edi_exchange/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2019 Callino <wpichler@callino.at
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import base_edi_exchange
from . import base_edi_transfer
from . import res_partner
176 changes: 176 additions & 0 deletions base_edi_exchange/models/base_edi_exchange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Copyright 2019 Callino <wpichler@callino.at
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models, fields, api, _
from datetime import datetime, timedelta
import logging

_logger = logging.getLogger(__name__)


class BaseEDIExchange(models.Model):
_name = 'base.edi.exchange'
_description = 'Common methods to send and receive EDI files'

@api.multi
@api.depends('transfer_ids')
def _compute_transfer_counts(self):
for record in self:
record.pending_transfer_count = len(record.transfer_ids.filtered(
lambda r: r.state == 'pending')
)
record.sent_transfer_count = len(record.transfer_ids.filtered(
lambda r: r.state == 'sent')
)
record.processed_transfer_count = len(record.transfer_ids.filtered(
lambda r: r.state == 'processed')
)
record.error_transfer_count = len(record.transfer_ids.filtered(
lambda r: r.state == 'error')
)
record.manual_transfer_count = len(record.transfer_ids.filtered(
lambda r: r.state == 'manual')
)

name = fields.Char(string="Name")
active = fields.Boolean(string="Active",
default=True)
state = fields.Selection(selection=[
('disabled', 'Disabled'),
('enabled', 'Enabled')
],
string="State",
default='disabled')
type = fields.Selection(selection=[
('none', _('None'))
],
string="Type",
required=True)
interval = fields.Integer(string="Interval (min)",
default=15)
last_run = fields.Datetime(string="Last Run",
readonly=True)
transfer_ids = fields.One2many('base.edi.transfer',
'edi_exchange_id',
string="Transfers Inbound")
inbound_transfer_ids = fields.One2many('base.edi.transfer',
'edi_exchange_id',
string="Transfers Inbound",
domain=[
('direction', '=', 'inbound')
],
readonly=True)
outbound_transfer_ids = fields.One2many('base.edi.transfer',
'edi_exchange_id',
string="Transfers Outbound",
domain=[
('direction', '=', 'outbound')
],
readonly=True)
partner_ids = fields.Many2many('res.partner',
string="Partners")
pending_transfer_count = fields.Integer(string="Pending Transfers",
compute="_compute_transfer_counts")
sent_transfer_count = fields.Integer(string="Sent Transfers",
compute="_compute_transfer_counts")
processed_transfer_count = fields.Integer(string="Processed Transfers",
compute="_compute_transfer_counts")
error_transfer_count = fields.Integer(string="Error Transfers",
compute="_compute_transfer_counts")
manual_transfer_count = fields.Integer(string="Manual Transfers",
compute="_compute_transfer_counts")

@api.multi
def send(self, file, vals=None):
pass

@api.multi
def receive(self):
pass

@api.model
def check_active_exchanges(self):
"""
Will get called from cronjob to call the receive function
of all active exchanges
The time interval for each exchange can get set
:return:
"""
for exchange in self.env['base.edi.exchange'].search([
('state', '=', 'enabled')
]):
if not exchange.last_run or \
datetime.now() > \
(exchange.last_run + timedelta(minutes=exchange.interval)):
exchange.receive()
exchange.last_run = datetime.now()

@api.multi
def action_pending_transfers(self):
self.ensure_one()
return {
'name': _("Pending Transfers"),
'type': 'ir.actions.act_window',
'res_model': 'base.edi.transfer',
'view_mode': 'tree,form',
'view_type': 'form',
'domain': "[('state', '=', 'pending'), "
"('edi_exchange_id', '=', %s)]" % self.id,
'target': 'self',
}

@api.multi
def action_sent_transfers(self):
self.ensure_one()
return {
'name': _("Sent Transfers"),
'type': 'ir.actions.act_window',
'res_model': 'base.edi.transfer',
'view_mode': 'tree,form',
'view_type': 'form',
'domain': "[('state', '=', 'sent'), "
"('edi_exchange_id', '=', %s)]" % self.id,
'target': 'self',
}

@api.multi
def action_processed_transfers(self):
self.ensure_one()
return {
'name': _("Processed Transfers"),
'type': 'ir.actions.act_window',
'res_model': 'base.edi.transfer',
'view_mode': 'tree,form',
'view_type': 'form',
'domain': "[('state', '=', 'processed'), "
"('edi_exchange_id', '=', %s)]" % self.id,
'target': 'self',
}

@api.multi
def action_error_transfers(self):
self.ensure_one()
return {
'name': _("Error Transfers"),
'type': 'ir.actions.act_window',
'res_model': 'base.edi.transfer',
'view_mode': 'tree,form',
'view_type': 'form',
'domain': "[('state', '=', 'error'), "
"('edi_exchange_id', '=', %s)]" % self.id,
'target': 'self',
}

@api.multi
def action_manual_transfers(self):
self.ensure_one()
return {
'name': _("Manual Transfers"),
'type': 'ir.actions.act_window',
'res_model': 'base.edi.transfer',
'view_mode': 'tree,form',
'view_type': 'form',
'domain': "[('state', '=', 'manual'), "
"('edi_exchange_id', '=', %s)]" % self.id,
'target': 'self',
}
77 changes: 77 additions & 0 deletions base_edi_exchange/models/base_edi_transfer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright 2019 Callino <wpichler@callino.at
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models, fields, api, _
import logging

_logger = logging.getLogger(__name__)


class BaseEDITransfer(models.Model):
_name = 'base.edi.transfer'
_description = 'Model to Track EDI Transfers'

name = fields.Char(string="Name")
original_filename = fields.Char(string="Original Filename")
file_content = fields.Binary(string="File Content")
state = fields.Selection(selection=[
('pending', _('Pending')),
('sent', _('Sent')),
('accepted', _('Accepted')),
('processed', _('Processed')),
('error', _('Error')),
('manual', _('Manual'))
],
string="State",
default="pending")
error_text = fields.Text(string="Error")
ref = fields.Reference(string="Reference",
selection=[])
edi_exchange_id = fields.Many2one('base.edi.exchange',
string="EDI Exchange",
required=True,
readonly=True)
conversation_id = fields.Char('Conversation Id',
index=True)
message_id = fields.Char(string="Sent Filename",
index=True)
direction = fields.Selection(selection=[
('inbound', _('Inbound')),
('outbound', _('Outbound'))
],
required=True)
read_date = fields.Datetime(string="File read at")
sent_date = fields.Datetime(string="File sent at")
process_date = fields.Datetime(string="File processed at")
file_timestamp = fields.Datetime(string="File last modified")

_sql_constraints = [(
'message_id_exchange_id_unique',
'unique(message_id, edi_exchange_id)',
'MessageId must be unique per exchange'
)]

@api.model
def get_transfer(self, file):
# search for transfer via filename
transfer = self.search([('original_filename', '=', file)], limit=1)
if not transfer:
# no file with the same filename
# might still be imported under different name
return False
else:
return transfer

@api.multi
def identify_and_import_object(self):
# Base function - has to get overwritten by exchange specific function
self.state = "error"
self.error_text = "File could not be identified."
return False

@api.multi
def identify_and_update_object(self):
# Base function - has to get overwritten by exchange specific function
self.state = "error"
self.error_text = "File could not be identified."
return False
39 changes: 39 additions & 0 deletions base_edi_exchange/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2019 Callino <wpichler@callino.at
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models, fields, api, _
import logging

_logger = logging.getLogger(__name__)


class ResPartner(models.Model):
_inherit = 'res.partner'

@api.multi
@api.depends('available_exchange_ids')
def _get_edi_exchange_available(self):
for record in self:
record.edi_exchange_available = \
True if record.available_exchange_ids else False

available_exchange_ids = fields.Many2many(
comodel_name="base.edi.exchange",
relation="partner_exchange_rel",
column_1="partner_id",
column_2="exchange_id",
string="Available Exchanges"
)
edi_exchange_available = fields.Boolean(string="EDI Exchange Available",
compute=_get_edi_exchange_available,
store=True)


# Relation Model with Sequence to have an easily adjustable order
class PartnerExchangeRel(models.Model):
_name = 'partner.exchange.rel'
_order = 'sequence asc'

sequence = fields.Integer(string="Sequence", default=10)
partner_id = fields.Many2one('res.partner', string="Partner")
exchange_id = fields.Many2one('base.edi.exchange', string="Exchange")
1 change: 1 addition & 0 deletions base_edi_exchange/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Wolfgang Pichler <wpichler@callino.at> (https://www.callino.at/)
3 changes: 3 additions & 0 deletions base_edi_exchange/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development of this module has been financially supported by:

* eWINGZ GmbH
3 changes: 3 additions & 0 deletions base_edi_exchange/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is the base module to implement automatic exchanges for edi messages.
It does provide the basic models and functions, which will then get implemented by
the specific sub modules.
3 changes: 3 additions & 0 deletions base_edi_exchange/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
To use this module, you need to:

#. Install one of the sub modules to be able to create an edi exchange
18 changes: 18 additions & 0 deletions base_edi_exchange/security/groups.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>

<record id="ir_module_category_edi_exchange" model="ir.module.category">
<field name="name">EDI Exchange</field>
</record>

<record id="res_groups_edi_exchange_manager" model="res.groups">
<field name="name">EDI Exchange Manager</field>
<field name="category_id" ref="ir_module_category_edi_exchange"/>
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
<field name="comment">
Configure EDI Exchanges
</field>
</record>
</data>
</odoo>
4 changes: 4 additions & 0 deletions base_edi_exchange/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_base_edi_exchange_sales_manager,access_base_edi_exchange_sales_manager,model_base_edi_exchange,base_edi_exchange.res_groups_edi_exchange_manager,1,1,1,1
access_base_edi_transfer_sales_manager,access_base_edi_transfer_sales_manager,model_base_edi_transfer,base_edi_exchange.res_groups_edi_exchange_manager,1,1,1,1
access_partner_exchange_rel_sales_manager,access_partner_exchange_rel_sales_manager,model_partner_exchange_rel,base_edi_exchange.res_groups_edi_exchange_manager,1,1,1,1
Binary file added base_edi_exchange/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading