<commit_before># -*- coding: utf-8 -*-
###############################################################################
#
# ODOO, Open Source Management Solution
# Copyright (C) 2001-2015 <NAME>. (<http://www.micronaet.it>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

import os
import sys
import logging
import openerp
import openerp.netsvc as netsvc
import openerp.addons.decimal_precision as dp
from openerp.osv import fields, osv, expression, orm
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from openerp import SUPERUSER_ID, api
from openerp import tools
from openerp.tools.translate import _
from openerp.tools.float_utils import float_round as round
from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT,
    DEFAULT_SERVER_DATETIME_FORMAT,
    DATETIME_FORMATS_MAP,
    float_compare)
from utility import *


_logger = logging.getLogger(__name__)

class SaleOrderSql(orm.Model):
    """Update basic object for import accounting elements
       NOTE: in this procedure there's some fields that are created
             from another module, TODO correct for keep module "modular"
    """
    _inherit = 'sale.order'

    # -----------------
    # Utility function:
    # -----------------
    def get_uom(self, cr, uid, name, context=None):
        uom_id = self.pool.get('product.uom').search(cr, uid, [
            ('name', '=', name), ])
        if uom_id:
            return uom_id[0] # take the first
        else:
            return False
    
    # =========================================================================
    #                               SCHEDULED ACTION
    # =========================================================================
    def schedule_etl_sale_order(self, cr, uid, update=False, delete=False,
             context=None):
        """ Import OC and create sale.order
            self: instance
            cr: database cursor
            uid: user ID
            update: if False create only new record, True try a sync wiht key
            delete: if True delete order no more present
        """
        import pdb; pdb.set_trace()
        _logger.info('Start import OC header mode: "%s"' % (
            'update' if update else 'new only'))
            
        query_pool = self.pool.get('micronaet.accounting')
        empty_date = query_pool.get_empty_date()
        log_info = ''

        # --------
        # Utility:
        # --------
        def get_oc_key(record):
            """ Compose and return key for OC
            """
            return (record['CSG_DOC'].strip(), record['NGB_SR_DOC'],
                record['NGL_DOC'])

        # ---------------------------------------------------------------------
        #                               IMPORT HEADER
        # ---------------------------------------------------------------------
        # Operation for manage deletion:
        if delete:
            order_ids = self.search(cr, uid, [
                ('accounting_order', '=', True),
                ('accounting_state', 'not in', ('close')), # TODO used??
                ], context=context)
        if update:        
            updated_ids = []

        # Start importation from SQL (NOTE: no comment!!):
        cr_oc = query_pool.get_oc_header(cr, uid, context=context)
        if not cr_oc:
            _logger.error('Cannot connect to MSSQL OC_TESTATE')
            return

        # Converter 
        oc_header = {} # (ref, type, number): ODOO ID
        for oc in cr_oc:
            try:
                name = "MX-%s/%s" % (
                    oc['NGL_DOC'],
                    oc['DTT_DOC'].strftime("%Y"),
                    )
                oc_ids = self.search(cr, uid, [
                    ('name', '=', name),
                    ('accounting_order', '=', True)
                    ], context=context)
                if update and oc_ids:
                    # --------------------
                    # Update header order:
                    # --------------------
                    oc_id = oc_ids[0]
                    if oc_id not in updated_ids:
                        updated_ids.append(oc_id)

                    oc_proxy = self.browse(cr, uid, oc_id, context=context)
<commit_msg>End first test of order import<commit_after># -*- coding: utf-8 -*-
###############################################################################
#
# ODOO, Open Source Management Solution
# Copyright (C) 2001-2015 Micronaet S.r.l. (<http://www.micronaet.it>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

import os
import sys
import logging
import openerp
import openerp.netsvc as netsvc
import openerp.addons.decimal_precision as dp
from openerp.osv import fields, osv, expression, orm
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from openerp import SUPERUSER_ID, api
from openerp import tools
from openerp.tools.translate import _
from openerp.tools.float_utils import float_round as round
from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT,
    DEFAULT_SERVER_DATETIME_FORMAT,
    DATETIME_FORMATS_MAP,
    float_compare)
from utility import *


_logger = logging.getLogger(__name__)

class SaleOrderSql(orm.Model):
    """Update basic object for import accounting elements
       NOTE: in this procedure there's some fields that are created
             from another module, TODO correct for keep module "modular"
    """
    _inherit = 'sale.order'

    # -----------------
    # Utility function:
    # -----------------
    def get_uom(self, cr, uid, name, context=None):
        uom_id = self.pool.get('product.uom').search(cr, uid, [
            ('name', '=', name), ])
        if uom_id:
            return uom_id[0] # take the first
        else:
            return False
    
    # =========================================================================
    #                               SCHEDULED ACTION
    # =========================================================================
    def schedule_etl_sale_order(self, cr, uid, update=False, delete=False,
             context=None):
        """ Import OC and create sale.order
            self: instance
            cr: database cursor
            uid: user ID
            update: if False create only new record, True try a sync wiht key
            delete: if True delete order no more present
        """
        _logger.info('Start import OC header mode: "%s"' % (
            'update' if update else 'new only'))
            
        query_pool = self.pool.get('micronaet.accounting')
        empty_date = query_pool.get_empty_date()
        log_info = ''

        # --------
        # Utility:
        # --------
        def get_oc_key(record):
            """ Compose and return key for OC
            """
            return (record['CSG_DOC'].strip(), record['NGB_SR_DOC'],
                record['NGL_DOC'])

        # ---------------------------------------------------------------------
        #                               IMPORT HEADER
        # ---------------------------------------------------------------------
        # Operation for manage deletion:
        if delete:
            order_ids = self.search(cr, uid, [
                ('accounting_order', '=', True),
                ('accounting_state', 'not in', ('close')), # TODO used??
                ], context=context)
        if update:        
            updated_ids = []

        # Start importation from SQL (NOTE: no comment!!):
        cr_oc = query_pool.get_oc_header(cr, uid, context=context)
        if not cr_oc:
            _logger.error('Cannot connect to MSSQL OC_TESTATE')
            return

        # Converter 
        oc_header = {} # (ref, type, number): ODOO ID
        for oc in cr_oc:
            try:
                name = "MX-%s/%s" % (
                    oc['NGL_DOC'],
                    oc['DTT_DOC'].strftime("%Y"),
                    )
                oc_ids = self.search(cr, uid, [
                    ('name', '=', name),
                    ('accounting_order', '=', True)
                    ], context=context)
                    
                oc_id = False    
                if update and oc_ids:
                    # --------------------
                    # Update header order:
                    # --------------------
                    oc_id = oc_ids[0]
                    if oc_id not in updated_ids:
                        updated_ids.append(oc_id)

                    oc_proxy = self.browse(cr, uid, oc_id, context=context)

{'fraction_non_alphanumeric': 0.18793503480278423, 'fraction_numerical': 0.0024210632502774136, 'mean_word_length': 1.8108874397504962, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '82704', 'n_tokens_mistral': 2602, 'n_tokens_neox': 2419, 'n_words': 791}