Browse Source

[MIG] pos_require_product_quantity: v9 to v12

pull/151/head
Manuel Claeys Bouuaert 5 years ago
parent
commit
5deabce60d
  1. 4
      beesdoo_crelan_csv/__init__.py
  2. 11
      beesdoo_crelan_csv/__manifest__.py
  3. 1
      beesdoo_crelan_csv/models/__init__.py
  4. 10
      beesdoo_crelan_csv/models/account_journal.py
  5. 7
      beesdoo_crelan_csv/wizard/__init__.py
  6. 48
      beesdoo_crelan_csv/wizard/import_crelan_csv.py

4
beesdoo_crelan_csv/__init__.py

@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
import wizard
from . import models
from . import wizard

11
beesdoo_crelan_csv/__openerp__.py → beesdoo_crelan_csv/__manifest__.py

@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2016 - 2020 BEES coop SCRLfs
# - Thibault Francois (thibault@françois.be)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': "Beescoop Crelan Import module",
@ -13,10 +16,8 @@
'website': "https://github.com/beescoop/Obeesdoo",
'category': 'Accounting & Finance',
'version': '0.1',
'version': '12.0.1.0.0',
'depends': ['account_bank_statement_import'],
'data': [
],
'installable': True,
}

1
beesdoo_crelan_csv/models/__init__.py

@ -0,0 +1 @@
from . import account_journal

10
beesdoo_crelan_csv/models/account_journal.py

@ -0,0 +1,10 @@
from odoo import models
class AccountJournal(models.Model):
_inherit = "account.journal"
def _get_bank_statements_available_import_formats(self):
formats_list = super()._get_bank_statements_available_import_formats()
formats_list.append('Crelan')
return formats_list

7
beesdoo_crelan_csv/wizard/__init__.py

@ -1,6 +1 @@
'''
Created on 09 octobre 2016
@author: Thibault Francois
'''
import import_crelan_csv
from . import import_crelan_csv

48
beesdoo_crelan_csv/wizard/import_crelan_csv.py

@ -1,15 +1,8 @@
# -*- coding: utf-8 -*-
'''
Created on 09 Octobre 2016
@author: Thibault Francois (thibault@françois.be)
'''
from StringIO import StringIO
from io import StringIO
import csv
import datetime
import md5
from openerp import models, _
import hashlib
from odoo import models, _
ACCOUNT = "Compte donneur d'ordre"
CURRENCY = "Devise"
@ -18,7 +11,7 @@ AMOUNT = "Montant"
COUNTERPART_NUMBER = "Compte contrepartie"
COUNTERPART_NAME = "Contrepartie"
COMMUNICATION = "Communication"
TRANSACTION_TYPE = "Type d'op\xc3\xa9ration"
TRANSACTION_TYPE = "Type d'opération"
class CodaBankStatementImport(models.TransientModel):
_inherit = 'account.bank.statement.import'
@ -29,7 +22,8 @@ class CodaBankStatementImport(models.TransientModel):
_csv_delimiter = ";"
_csv_quote = '"'
_header = ['Date', 'Montant', 'Devise', 'Contrepartie', 'Compte contrepartie', "Type d'op\xc3\xa9ration", 'Communication', "Compte donneur d'ordre"]
_header = ['Date', 'Montant', 'Devise', 'Contrepartie', 'Compte contrepartie', "Type d'opération",
'Communication', "Compte donneur d'ordre"]
def _generate_note_crelan(self, move):
@ -45,28 +39,29 @@ class CodaBankStatementImport(models.TransientModel):
'note': self._generate_note_crelan(move),
'date': self._to_iso_date(move[DATE]),
'amount': float(move[AMOUNT]),
'account_number': move[COUNTERPART_NUMBER], #ok
'partner_name': move[COUNTERPART_NAME], #ok
'account_number': move[COUNTERPART_NUMBER], # Ok
'partner_name': move[COUNTERPART_NAME], # Ok
'ref': move[DATE] + '-' + move[AMOUNT] + '-' + move[COUNTERPART_NUMBER] + '-' + move[COUNTERPART_NAME],
'sequence': sequence, #ok
'unique_import_id' : move[DATE] + '-' + move[AMOUNT] + '-' + move[COUNTERPART_NUMBER] + '-' + move[COUNTERPART_NAME] + '-' + md5.new(move[COMMUNICATION]).hexdigest()
'sequence': sequence, # Ok
'unique_import_id': move[DATE] + '-' + move[AMOUNT] + '-' + move[COUNTERPART_NUMBER] + '-' +
move[COUNTERPART_NAME] + '-' + hashlib.new('md5', move[COMMUNICATION].encode()).hexdigest()
}
return move_data
def _get_statement_data_crelan(self, balance_start, balance_end, begin_date, end_date):
statement_data = {
'name' : _("Bank Statement from %s to %s") % (begin_date, end_date),
'date' : self._to_iso_date(end_date),
'balance_start': balance_start, #ok
'balance_end_real' : balance_end, #ok
'name': _("Bank Statement from %s to %s") % (begin_date, end_date),
'date': self._to_iso_date(end_date),
'balance_start': balance_start, # Ok
'balance_end_real' : balance_end, # Ok
'transactions' : []
}
return statement_data
def _get_acc_number_crelan(self, acc_number):
#Check if we match the exact acc_number or the end of an acc number
# Check if we match the exact acc_number or the end of an acc number
journal = self.env['account.journal'].search([('bank_acc_number', '=like', '%' + acc_number)])
if not journal or len(journal) > 1: #if not found or ambiguious
if not journal or len(journal) > 1: # If not found or ambiguious
return acc_number
return journal.bank_acc_number
@ -76,13 +71,14 @@ class CodaBankStatementImport(models.TransientModel):
return self.init_balance
journal = self.env['account.journal'].search([('bank_acc_number', '=like', '%' + acc_number)])
if not journal or len(journal) > 1: #if not found or ambiguious
currency = journal.currency_id or journal.company_id.currency_id
if not journal or len(journal) > 1: # If not found or ambiguious
self.init_balance = 0.0
else:
lang = self._context.get('lang', 'en_US')
l = self.env['res.lang'].search([('code', '=', lang)])
balance = journal.get_journal_dashboard_datas()['last_balance'][:-1]
self.init_balance = float(balance.strip().replace(l.thousands_sep, '').replace(l.decimal_point, '.'))
self.init_balance = float(balance.replace(currency.symbol, '').strip().replace(l.thousands_sep, '').replace(l.decimal_point, '.'))
return self.init_balance
def _to_iso_date(self, orig_date):
@ -92,7 +88,7 @@ class CodaBankStatementImport(models.TransientModel):
def _parse_file(self, data_file):
try:
csv_file = StringIO(data_file)
csv_file = StringIO(data_file.decode())
data = csv.DictReader(csv_file, delimiter=self._csv_delimiter, quotechar=self._csv_quote)
if not data.fieldnames == self._header:
raise ValueError()
@ -117,6 +113,6 @@ class CodaBankStatementImport(models.TransientModel):
transactions.append(self._get_move_value_crelan(statement, i))
sum_transaction += float(statement[AMOUNT])
i += 1
stmt = self._get_statement_data_crelan(balance, balance+ sum_transaction, begin_date, end_date)
stmt = self._get_statement_data_crelan(balance, balance + sum_transaction, begin_date, end_date)
stmt['transactions'] = transactions
return currency_code, self._get_acc_number_crelan(account_number), [stmt]
Loading…
Cancel
Save