<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution    
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
#    d$
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU 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 General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import os
import sys
import openerp 
import logging
import base64
from openerp.osv import osv, fields
from datetime import datetime
from openerp.tools import (DEFAULT_SERVER_DATETIME_FORMAT, 
    DEFAULT_SERVER_DATE_FORMAT)
from openerp import tools
from openerp.tools.translate import _


_logger = logging.getLogger(__name__)

# --------
# Utility:
# --------
# TODO eliminare le funzioni, non devono stare qui!
def _get_image(self, cr, uid, ids, name, args, context=None):
    ''' Read image from file
    '''
    result = dict.fromkeys(ids, False)
    for obj in self.browse(cr, uid, ids, context=context):
        result[obj.id] = tools.image_get_resized_images(
            obj.image, avoid_resize_medium=True)
    return result

def _set_image(self, cr, uid, item_id, name, value, args, context=None):
    ''' Store image from file
    '''
    return self.write(cr, uid, [item_id], {
        'image': tools.image_resize_image_big(value)}, context=context)

def get_temp_filename(filename):
    ''' Get temp path for copy and paste functions
    '''
    return os.path.join(
        openerp.__path__[0], 'addons', 'fashion', 'temp', filename)

class fashion_season(osv.osv):
    '''Table that manages the seasons
    '''
    _name = 'fashion.season'
    _description = 'Season'
    _order = 'sequence,name'

    def set_obsolete(self, cr, uid, ids, context=None):
        self.write(cr, uid, ids, {'obsolete': context.get('obsolete',True)})
        return True
        
    def set_not_obsolete(self, cr, uid, ids, context=None):
        self.set_obsolete(cr, uid, ids, {'obsolete':False})
        return True
        
    _columns = {
         'sequence': fields.integer('Sequence'),
         'code': fields.char('Cod', size=10, required=True, 
             help='Code used in fabric for join in the name'),
         'name': fields.char('Name', size=40, required=True),
         'note': fields.text('Note'),
         'obsolete':fields.boolean('Obsolete'),
         
         # Link di importazione:
         'access_id': fields.integer(
             'Access ID', help="ID Importazione che tiene il link"),
    }

class fashion_article(osv.osv):
    '''Table that manages the articles
    '''
    _name = 'fashion.article'
    _description = 'Article'
    _order = 'name'

    _columns = {
         'name': fields.char('Name', size=40, required=True),
         'note': fields.text('Note'),
         'code': fields.char('Code', size=1),
         #'measure_ids': fields.many2many(
         #    'fashion.form.measure', 'fashion_form_article_rel',
         #    'article_id', 'measure_id', 'Measures', readonly = False),
         
         # Link di importazione:
         'access_id': fields.integer(
             'Access ID', help="ID Importazione che tiene il link"),
    }

class fashion_form_characteristic(osv.osv):
    '''Table that manages the characteristic
    '''
    _name = 'fashion.form.characteristic'
    _description = 'Characteristic'
    _order = 'sequence,name'

    _columns = {
         'name': fields.char('Name', size = 40, required = True),
         'note': fields.text('Note'),
         'sequence': fields.integer('Sequence'),

         # Link di importazione:
         'access_id': fields.integer(
             'Access ID', help="ID Importazione che tiene il link"),
    }

class fashion_form_cost(osv.osv):
    '''Table that manages the cost
    '''
    _name = 'fashion.form.cost'
    _description = 'Cost'
    _order = 'sequence,name'

    _columns = {
        'name': fields.char('Name', size = 40, required=True),
        'note': fields.text('Note'),
        'sequence': fields.integer('Sequence'),
        'cost': fields.float('Cost', digits=(12, 4)),
        'default': fields.boolean('Default'),
    
         # Link di importazione:
         'access_id': fields.integer(
             'Access ID', help="ID Importazione che tiene il link"),
     }

    _defaults = {
        'default': False,
    }

class fashion_form_accessory(osv.osv):
    '''Table that manages the accessory
    '''
    _name = 'fashion.form.accessory'
    _description = 'Accessory'
    _order = 'sequence,name'

    _columns = {
         'name': fields.char('Name', size = 40, required = True),
         'gerber_char': fields.char('Gerber char', size = 1, required = False),
         'note': fields.text('Note'),
         'sequence': fields.integer('Sequence'),
         'type': fields.selection([
                ('t', 'Cut'),
                ('a', 'Accessory'),
                ], 'Type', select=True),

         # Link di importazione:
         'access_id': fields.integer('Access ID', help="ID Importazione che tiene il link"),
    }
    _defaults = {
        'sequence': lambda *x: 1000, # normal accessory have high number
    }

class fashion_form_accessory_pricelist(osv.osv):
    '''Table that manages the accessory pricelist
    '''
    _name = 'fashion.form.accessory.pricelist'
    _description = 'Accessory pricelist'
    _order = 'supplier_id,create_date desc'

    # ------------------
    # Override function:
    # ------------------
    def name_get(self, cr, uid, ids, context=None):
        ''' Add customer-fabric ID to name
        '''
        res = []
        for item in self.browse(cr, uid, ids, context = context):
            res.append((item.id, "%s %s" % (item.name or '', item.extra_info or '')))
        return res        

    _columns = {
        'name': fields.char('Article', size=70, required=False),
        'accessory_id':fields.many2one('fashion.form.accessory', 'Accessory', 
            required=False, ondelete='cascade'),
        'supplier_id':fields.many2one('res.partner', 'Supplier', 
            required=True, domain=[('supplier','=',True)]),
        'create_date': fields.datetime('Date', readonly=True),
        'um': fields.char('U.M.', size=5, required=False),
        'extra_info': fields.char('Extra info', size=40, required=False),
        'note': fields.text('Note'),
        'cost': fields.float('Cost', digits=(12, 4)),

        # Link di importazione:
        'access_id': fields.integer(
            'Access ID', help="ID Importazione che tiene il link"),<commit_msg>add procedure for update acccessory prices<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution    
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
#    d$
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU 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 General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import os
import sys
import openerp 
import logging
import base64
from openerp.osv import osv, fields
from datetime import datetime
from openerp.tools import (DEFAULT_SERVER_DATETIME_FORMAT, 
    DEFAULT_SERVER_DATE_FORMAT)
from openerp import tools
from openerp.tools.translate import _


_logger = logging.getLogger(__name__)

# --------
# Utility:
# --------
# TODO eliminare le funzioni, non devono stare qui!
def _get_image(self, cr, uid, ids, name, args, context=None):
    ''' Read image from file
    '''
    result = dict.fromkeys(ids, False)
    for obj in self.browse(cr, uid, ids, context=context):
        result[obj.id] = tools.image_get_resized_images(
            obj.image, avoid_resize_medium=True)
    return result

def _set_image(self, cr, uid, item_id, name, value, args, context=None):
    ''' Store image from file
    '''
    return self.write(cr, uid, [item_id], {
        'image': tools.image_resize_image_big(value)}, context=context)

def get_temp_filename(filename):
    ''' Get temp path for copy and paste functions
    '''
    return os.path.join(
        openerp.__path__[0], 'addons', 'fashion', 'temp', filename)

class fashion_season(osv.osv):
    '''Table that manages the seasons
    '''
    _name = 'fashion.season'
    _description = 'Season'
    _order = 'sequence,name'

    def set_obsolete(self, cr, uid, ids, context=None):
        self.write(cr, uid, ids, {'obsolete': context.get('obsolete',True)})
        return True
        
    def set_not_obsolete(self, cr, uid, ids, context=None):
        self.set_obsolete(cr, uid, ids, {'obsolete':False})
        return True
        
    _columns = {
         'sequence': fields.integer('Sequence'),
         'code': fields.char('Cod', size=10, required=True, 
             help='Code used in fabric for join in the name'),
         'name': fields.char('Name', size=40, required=True),
         'note': fields.text('Note'),
         'obsolete':fields.boolean('Obsolete'),
         
         # Link di importazione:
         'access_id': fields.integer(
             'Access ID', help="ID Importazione che tiene il link"),
    }

class fashion_article(osv.osv):
    '''Table that manages the articles
    '''
    _name = 'fashion.article'
    _description = 'Article'
    _order = 'name'

    _columns = {
         'name': fields.char('Name', size=40, required=True),
         'note': fields.text('Note'),
         'code': fields.char('Code', size=1),
         #'measure_ids': fields.many2many(
         #    'fashion.form.measure', 'fashion_form_article_rel',
         #    'article_id', 'measure_id', 'Measures', readonly = False),
         
         # Link di importazione:
         'access_id': fields.integer(
             'Access ID', help="ID Importazione che tiene il link"),
    }

class fashion_form_characteristic(osv.osv):
    '''Table that manages the characteristic
    '''
    _name = 'fashion.form.characteristic'
    _description = 'Characteristic'
    _order = 'sequence,name'

    _columns = {
         'name': fields.char('Name', size = 40, required = True),
         'note': fields.text('Note'),
         'sequence': fields.integer('Sequence'),

         # Link di importazione:
         'access_id': fields.integer(
             'Access ID', help="ID Importazione che tiene il link"),
    }

class fashion_form_cost(osv.osv):
    '''Table that manages the cost
    '''
    _name = 'fashion.form.cost'
    _description = 'Cost'
    _order = 'sequence,name'

    _columns = {
        'name': fields.char('Name', size = 40, required=True),
        'note': fields.text('Note'),
        'sequence': fields.integer('Sequence'),
        'cost': fields.float('Cost', digits=(12, 4)),
        'default': fields.boolean('Default'),
    
         # Link di importazione:
         'access_id': fields.integer(
             'Access ID', help="ID Importazione che tiene il link"),
     }

    _defaults = {
        'default': False,
    }

class fashion_form_accessory(osv.osv):
    '''Table that manages the accessory
    '''
    _name = 'fashion.form.accessory'
    _description = 'Accessory'
    _order = 'sequence,name'

    _columns = {
         'name': fields.char('Name', size = 40, required = True),
         'gerber_char': fields.char('Gerber char', size = 1, required = False),
         'note': fields.text('Note'),
         'sequence': fields.integer('Sequence'),
         'type': fields.selection([
                ('t', 'Cut'),
                ('a', 'Accessory'),
                ], 'Type', select=True),

         # Link di importazione:
         'access_id': fields.integer('Access ID', help="ID Importazione che tiene il link"),
    }
    _defaults = {
        'sequence': lambda *x: 1000, # normal accessory have high number
    }

class fashion_form_accessory_pricelist(osv.osv):
    '''Table that manages the accessory pricelist
    '''
    _name = 'fashion.form.accessory.pricelist'
    _description = 'Accessory pricelist'
    _order = 'supplier_id,create_date desc'

    def write(self, cr, uid, ids, vals, context=None):
        """ Update redord(s) comes in {ids}, with new value comes as {vals}
            return True on success, False otherwise
            @param cr: cursor to database
            @param uid: id of current user
            @param ids: list of record ids to be update
            @param vals: dict of new values to be set
            @param context: context arguments, like lang, time zone
            
            @return: True on success, False otherwise
        """
        res = super(fashion_form_accessory_pricelist, self).write(
            cr, uid, ids, vals, context=context)
        
        # Update cost in forms:
        cost = vals.get('cost', False)
        if not cost:
            return res
            
        # Update all cost with this pricelist_id:
        rel_pool = self.pool.get('fashion.form.accessory.rel')   
        rel_ids = rel_pool.search(cr, uid, [
            ('pricelist_id', '=', ids[0]),
            ], context=context)
        
        update_db = {}

        for rel in rel_pool.browse(cr, uid, rel_ids, context=context):
            res_rel = rel_pool.on_change_calcolate_cost(cr, uid, False, 
                rel.quantity, cost, context=context)
            update_db[rel.id] = res_rel.get('value', False)
            try:
                update_db[rel.id]['currency'] = cost
            except:
                _logger.warning('Error update record: %s' % rel.form_id.name)
                continue
        
        for item_id, data in update_db.iteritems():
            rel_pool.write(cr, uid, item_id, data, context=context)
        _logger.info('Update %s pricelist elements!' % len(rel_ids))    
        return res
    
    # ------------------
    # Override function:
    # ------------------
    def name_get(self, cr, uid, ids, context=None):
        ''' Add customer-fabric ID to name
        '''
        res = []
        for item in self.browse(cr, uid, ids, context = context):
            res.append((item.id, "%s %s" % (item.name or '', item.extra_info or '')))
        return res        

    _columns = {
        'name': fields.char('Article', size=70, required=False),
        'accessory_id':fields.many2one('fashion.form.accessory', 'Accessory', 
            required=False, ondelete='cascade'),
        'supplier_id':fields.many2one('res.partner', 'Supplier', 
            required=True, domain=[('supplier','=',True)]),
        'create_date': fields.datetime('Date', readonly=True),
        'um': fields.char('U.M.', size=5, required=False),
        'extra_info': fields.char('Extra info', size=40, required=False),
        'note': fields.text('Note'),
        'cost': fields.float('Cost', digits=(12, 4)),

        # Link di importazione:
        'access_id': fields.integer(
            'Access ID', help="ID Importazione che tiene il link"),
{'fraction_non_alphanumeric': 0.15337232453957192, 'fraction_numerical': 0.005662020905923345, 'mean_word_length': 2.6241262683201803, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3348168', 'n_tokens_mistral': 4801, 'n_tokens_neox': 4586, 'n_words': 1304}