<commit_before># -*- encoding: utf-8 -*-
#################################################################################
#                                                                               #
#    sale_automatic_workflow for OpenERP                                        #
#    Copyright (C) 2011 <NAME> <<EMAIL>>   #
#                                                                               #
#    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/>.      #
#                                                                               #
#################################################################################


from openerp.osv.orm import Model
import netsvc
import logging
from tools.translate import _
from contextlib import contextmanager
#from base_external_referentials.decorator import commit_now

#Some comment about the implementation
#In order to validate the invoice the picking we have to use schedule action
#Indeed, if we directly jump the various step in the workflow of the invoice and the picking
#the sale order workflow will be broken
#The explication is "simple"
#Example with the invoice workflow
#When we are in the sale order at the step router
#a transiotion like a signal or condition will change the step of the workflow to the step 'invoice'
#the fact to enter in this step will launch the creation of the invoice
#if the invoice in directly validated and reconcilled with the payment
#the subworkflow will end and send a signal to the sale order workflow
#the problem is that the sale order workflow have not finish to apply the step invoice
#and so the signal of the subworkflow will be lost
#because the step invoice is still not finish
#The step invoice should be finish before receiving the signal
#this is meant that we can not directly validated every step of the workflow invoice_amount
#it the same with the picking workflow_method

#If my explication is not clear contact me by email and I will imporve it: <EMAIL>


@contextmanager
def commit_now(cr, logger, raise_error=None):
    try:
        yield cr
    except Exception, e:
        cr.rollback()
        logger.exception(e)
        if raise_error:
            raise<commit_msg>[IMP] sale_automatic_workflow : add doc string for commit_now and set to False params raise_error as it's a boolean<commit_after># -*- encoding: utf-8 -*-
#################################################################################
#                                                                               #
#    sale_automatic_workflow for OpenERP                                        #
#    Copyright (C) 2011 <NAME> <<EMAIL>>   #
#                                                                               #
#    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/>.      #
#                                                                               #
#################################################################################


from openerp.osv.orm import Model
import netsvc
import logging
from tools.translate import _
from contextlib import contextmanager

#Some comment about the implementation
#In order to validate the invoice the picking we have to use schedule action
#Indeed, if we directly jump the various step in the workflow of the invoice and the picking
#the sale order workflow will be broken
#The explication is "simple"
#Example with the invoice workflow
#When we are in the sale order at the step router
#a transiotion like a signal or condition will change the step of the workflow to the step 'invoice'
#the fact to enter in this step will launch the creation of the invoice
#if the invoice in directly validated and reconcilled with the payment
#the subworkflow will end and send a signal to the sale order workflow
#the problem is that the sale order workflow have not finish to apply the step invoice
#and so the signal of the subworkflow will be lost
#because the step invoice is still not finish
#The step invoice should be finish before receiving the signal
#this is meant that we can not directly validated every step of the workflow invoice_amount
#it the same with the picking workflow_method

#If my explication is not clear contact me by email and I will imporve it: <EMAIL>


@contextmanager
def commit_now(cr, logger, raise_error=False):
    """
    Context Manager to use in order to commit into a cursor
    correctly with a try/except method and a rollback if necessary
    :param cr cursor: cursor to commit
    :param logger logger: logger use for loging message
    :param raise_error boolean: Set to true only if you want
             to stop the process if an error occure
    """
    try:
        yield cr
    except Exception, e:
        cr.rollback()
        logger.exception(e)
        if raise_error:
            raise
{'fraction_non_alphanumeric': 0.08874491487117674, 'fraction_numerical': 0.0018080458038270302, 'mean_word_length': 1.9873987398739874, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5038028', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1356, 'n_words': 762}