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. 52
      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", 'name': "Beescoop Crelan Import module",
@ -13,10 +16,8 @@
'website': "https://github.com/beescoop/Obeesdoo", 'website': "https://github.com/beescoop/Obeesdoo",
'category': 'Accounting & Finance', 'category': 'Accounting & Finance',
'version': '0.1',
'version': '12.0.1.0.0',
'depends': ['account_bank_statement_import'], '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

52
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 csv
import datetime import datetime
import md5
from openerp import models, _
import hashlib
from odoo import models, _
ACCOUNT = "Compte donneur d'ordre" ACCOUNT = "Compte donneur d'ordre"
CURRENCY = "Devise" CURRENCY = "Devise"
@ -18,7 +11,7 @@ AMOUNT = "Montant"
COUNTERPART_NUMBER = "Compte contrepartie" COUNTERPART_NUMBER = "Compte contrepartie"
COUNTERPART_NAME = "Contrepartie" COUNTERPART_NAME = "Contrepartie"
COMMUNICATION = "Communication" COMMUNICATION = "Communication"
TRANSACTION_TYPE = "Type d'op\xc3\xa9ration"
TRANSACTION_TYPE = "Type d'opération"
class CodaBankStatementImport(models.TransientModel): class CodaBankStatementImport(models.TransientModel):
_inherit = 'account.bank.statement.import' _inherit = 'account.bank.statement.import'
@ -29,7 +22,8 @@ class CodaBankStatementImport(models.TransientModel):
_csv_delimiter = ";" _csv_delimiter = ";"
_csv_quote = '"' _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): def _generate_note_crelan(self, move):
@ -45,28 +39,29 @@ class CodaBankStatementImport(models.TransientModel):
'note': self._generate_note_crelan(move), 'note': self._generate_note_crelan(move),
'date': self._to_iso_date(move[DATE]), 'date': self._to_iso_date(move[DATE]),
'amount': float(move[AMOUNT]), '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], '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 return move_data
def _get_statement_data_crelan(self, balance_start, balance_end, begin_date, end_date): def _get_statement_data_crelan(self, balance_start, balance_end, begin_date, end_date):
statement_data = { 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' : [] 'transactions' : []
} }
return statement_data return statement_data
def _get_acc_number_crelan(self, acc_number): 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)]) 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 acc_number
return journal.bank_acc_number return journal.bank_acc_number
@ -76,13 +71,14 @@ class CodaBankStatementImport(models.TransientModel):
return self.init_balance return self.init_balance
journal = self.env['account.journal'].search([('bank_acc_number', '=like', '%' + 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
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 self.init_balance = 0.0
else: else:
lang = self._context.get('lang', 'en_US') lang = self._context.get('lang', 'en_US')
l = self.env['res.lang'].search([('code', '=', lang)]) l = self.env['res.lang'].search([('code', '=', lang)])
balance = journal.get_journal_dashboard_datas()['last_balance'][:-1] 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 return self.init_balance
def _to_iso_date(self, orig_date): def _to_iso_date(self, orig_date):
@ -92,7 +88,7 @@ class CodaBankStatementImport(models.TransientModel):
def _parse_file(self, data_file): def _parse_file(self, data_file):
try: 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) data = csv.DictReader(csv_file, delimiter=self._csv_delimiter, quotechar=self._csv_quote)
if not data.fieldnames == self._header: if not data.fieldnames == self._header:
raise ValueError() raise ValueError()
@ -107,16 +103,16 @@ class CodaBankStatementImport(models.TransientModel):
transactions = [] transactions = []
i = 1 i = 1
sum_transaction = 0
sum_transaction = 0
for statement in data: for statement in data:
begin_date = begin_date or statement[DATE] begin_date = begin_date or statement[DATE]
end_date = statement[DATE] end_date = statement[DATE]
account_number = statement[ACCOUNT]
account_number = statement[ACCOUNT]
balance = self._get_acc_balance_crelan(account_number) balance = self._get_acc_balance_crelan(account_number)
currency_code = statement[CURRENCY] currency_code = statement[CURRENCY]
transactions.append(self._get_move_value_crelan(statement, i)) transactions.append(self._get_move_value_crelan(statement, i))
sum_transaction += float(statement[AMOUNT]) sum_transaction += float(statement[AMOUNT])
i += 1 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 stmt['transactions'] = transactions
return currency_code, self._get_acc_number_crelan(account_number), [stmt] return currency_code, self._get_acc_number_crelan(account_number), [stmt]
Loading…
Cancel
Save