<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#  licence AGPL version 3 or later
#  see licence in __openerp__.py or http://www.gnu.org/licenses/agpl-3.0.txt
#  Copyright (C) 2014 Akretion (http://www.akretion.com).
#  @author <NAME> <<EMAIL>>
#
##############################################################################

from openerp.osv import orm
from openerp.tools.translate import _
from openerp.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT as serv_date_format
from datetime import datetime
import unicodecsv
from cStringIO import StringIO
from csv import Dialect
from _csv import QUOTE_MINIMAL, register_dialect
import base64
from openerp.tools import misc

# This code is used by Colissimo and So Colissimo
# TODO this code is not fully updated for So Colissimo
# coorection will be firstly defined in v7 branch


class LaposteDialect(Dialect):
    """Describe the usual properties of Excel-generated CSV files."""
    delimiter = ';'
    quotechar = '"'
    escapechar = '\\'
    doublequote = False
    skipinitialspace = False
    lineterminator = '\r\n'
    quoting = QUOTE_MINIMAL
register_dialect("laposte_dialect", LaposteDialect)


class DepositSlip(orm.Model):
    _inherit = "deposit.slip"

    def create_header_vals(self, cr, uid, deposit, context=None):
        company = deposit.picking_ids[0].company_id
        create_date = datetime.strptime(deposit.create_date,
                                        misc.DEFAULT_SERVER_DATETIME_FORMAT)
        create_date_format = datetime.strftime(create_date, "%Y%m%d%H%M")
        validate_date = datetime.strftime(datetime.now(), "%Y%m%d%H%M")
        vals = {
            "Type d'enregistrement": "BBB001",
            "Identifiant du bordereau": deposit.name,
            "Identifiant du client": company.colipostefr_account,
            "Date expédition": create_date_format,
            # Important : cette date doit
            # correspondre à la date réelle de dépôt physique des colis sur
            # le site d’entrée du trafic et à la date d’émission du fich EDI.
            "Date d'émission du bordereau": validate_date,
            "Version Format Fichier": "02.00",
            "Site Prise en charge": (company.colipostefr_support_city_code
                                     or ''),
            "Nom commercial": company.name,
        }
        return vals

    def _coliposte_default_phone(self, cr, uid, phone, mobile, context=None):
        "You can inherit to customize"
        return (phone, mobile)

    def _coliposte_default_mail(self, cr, uid, mail, context=None):
        "You can inherit to customize"
        return mail

    def phone_number_formating(self, cr, uid, number, context=None):
        if number:
            format_number = number.replace(".", "").replace(" ", "")
            if "+" in format_number:
                format_number = "0" + format_number[3:]
            return format_number
        else:
            return ''

    def create_edi_lines(self, cr, uid, deposit, context=None):
        lines = []
        for picking in deposit.picking_ids:
            if picking.carrier_code not in ['EI', 'AI']:
                address = picking.partner_id
                # TODO So Colissimo see correction in V7 branch
                # dropoff_site = picking.dropoff_site_id
                non_machi = "N"
                # TODO
                # if picking.non_machinable:
                #     non_machi = "O"
                dropoff_code = None
                # TODO So Colissimo see correction in V7 branch
                # if picking.to_dropoff_site:
                    # dropoff_code = dropoff_site.code
                AR = "N"
                if picking.carrier_code == "6C":
                    AR = "O"
                name = address.name.replace(' ', '`')
                if address.title:
                    name = address.title.shortcut.replace('.', '') + "`" + name
                else:
                    name = "M`" + name
                phone = self.phone_number_formating(
                    cr, uid, address.phone, context=context)
                mobile = self.phone_number_formating(
                    cr, uid, address.mobile, context=context)
                phone, mobile = self._coliposte_default_phone(
                    cr, uid, phone, mobile, context=context)
                if not phone and not mobile and not address.email:
                    raise orm.except_orm(
                        'Information manquante',
                        "L'un des champs suivant ne doit pas être vide:\n"
                        "mobile, phone, email\n"
                        "(sous peine de surtaxation de La Poste)")
                country_code = ''
                if address.country_id:<commit_msg>[FIX] unicode raise in deposit_slip<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#  licence AGPL version 3 or later
#  see licence in __openerp__.py or http://www.gnu.org/licenses/agpl-3.0.txt
#  Copyright (C) 2014 Akretion (http://www.akretion.com).
#  @author <NAME> <<EMAIL>>
#
##############################################################################

from openerp.osv import orm
from openerp.tools.translate import _
from openerp.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT as serv_date_format
from datetime import datetime
import unicodecsv
from cStringIO import StringIO
from csv import Dialect
from _csv import QUOTE_MINIMAL, register_dialect
import base64
from openerp.tools import misc

# This code is used by Colissimo and So Colissimo
# TODO this code is not fully updated for So Colissimo
# coorection will be firstly defined in v7 branch


class LaposteDialect(Dialect):
    """Describe the usual properties of Excel-generated CSV files."""
    delimiter = ';'
    quotechar = '"'
    escapechar = '\\'
    doublequote = False
    skipinitialspace = False
    lineterminator = '\r\n'
    quoting = QUOTE_MINIMAL
register_dialect("laposte_dialect", LaposteDialect)


class DepositSlip(orm.Model):
    _inherit = "deposit.slip"

    def create_header_vals(self, cr, uid, deposit, context=None):
        company = deposit.picking_ids[0].company_id
        create_date = datetime.strptime(deposit.create_date,
                                        misc.DEFAULT_SERVER_DATETIME_FORMAT)
        create_date_format = datetime.strftime(create_date, "%Y%m%d%H%M")
        validate_date = datetime.strftime(datetime.now(), "%Y%m%d%H%M")
        vals = {
            "Type d'enregistrement": "BBB001",
            "Identifiant du bordereau": deposit.name,
            "Identifiant du client": company.colipostefr_account,
            "Date expédition": create_date_format,
            # Important : cette date doit
            # correspondre à la date réelle de dépôt physique des colis sur
            # le site d’entrée du trafic et à la date d’émission du fich EDI.
            "Date d'émission du bordereau": validate_date,
            "Version Format Fichier": "02.00",
            "Site Prise en charge": (company.colipostefr_support_city_code
                                     or ''),
            "Nom commercial": company.name,
        }
        return vals

    def _coliposte_default_phone(self, cr, uid, phone, mobile, context=None):
        "You can inherit to customize"
        return (phone, mobile)

    def _coliposte_default_mail(self, cr, uid, mail, context=None):
        "You can inherit to customize"
        return mail

    def phone_number_formating(self, cr, uid, number, context=None):
        if number:
            format_number = number.replace(".", "").replace(" ", "")
            if "+" in format_number:
                format_number = "0" + format_number[3:]
            return format_number
        else:
            return ''

    def create_edi_lines(self, cr, uid, deposit, context=None):
        lines = []
        for picking in deposit.picking_ids:
            if picking.carrier_code not in ['EI', 'AI']:
                address = picking.partner_id
                # TODO So Colissimo see correction in V7 branch
                # dropoff_site = picking.dropoff_site_id
                non_machi = "N"
                # TODO
                # if picking.non_machinable:
                #     non_machi = "O"
                dropoff_code = None
                # TODO So Colissimo see correction in V7 branch
                # if picking.to_dropoff_site:
                    # dropoff_code = dropoff_site.code
                AR = "N"
                if picking.carrier_code == "6C":
                    AR = "O"
                name = address.name.replace(' ', '`')
                if address.title:
                    name = address.title.shortcut.replace('.', '') + "`" + name
                else:
                    name = "M`" + name
                phone = self.phone_number_formating(
                    cr, uid, address.phone, context=context)
                mobile = self.phone_number_formating(
                    cr, uid, address.mobile, context=context)
                phone, mobile = self._coliposte_default_phone(
                    cr, uid, phone, mobile, context=context)
                if not phone and not mobile and not address.email:
                    raise orm.except_orm(
                        u'Information manquante sur %s' % picking.name,
                        u"L'un des champs suivant ne doit pas être vide:\n"
                        u"mobile, phone, email\n"
                        u"(sous peine de surtaxation de La Poste)")
                country_code = ''
                if address.country_id:
{'fraction_non_alphanumeric': 0.11920461570162785, 'fraction_numerical': 0.00494539460127756, 'mean_word_length': 2.0391358797745776, 'pattern_counts': {'":': 18, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2263543', 'n_tokens_mistral': 2838, 'n_tokens_neox': 2640, 'n_words': 740}