<commit_before># -*- coding: utf-8 -*-

from openerp.osv import fields, orm
from openerp import SUPERUSER_ID


class purchase_order(orm.Model):
    _inherit = 'purchase.order'
    _columns = {
        'bid_partial': fields.boolean(
            'Bid partially selected',
            readonly=True,
            help="True if the bid has been partially selected"),
        'tender_bid_receipt_mode': fields.function(
            lambda self, *args, **kwargs: self._get_tender(*args, **kwargs),
            multi="callforbids",
            readonly=True,
            type='selection',
            selection=[('open', 'Open'), ('sealed', 'Sealed')],
            string='Bid Receipt Mode'),
    }
    #TODO: lines should not be deleted or created if linked to a callforbids

    def _get_tender(self, cr, uid, ids, fields, args, context=None):
        # when _classic_write load is used, the many2one are only the
        # ids instead of the tuples (id, name_get)
        purch_req_obj = self.pool.get('purchase.requisition')
        orders = self.read(cr, uid, ids, ['requisition_id'],
                           context=context, load='_classic_write')
        req_ids = list(set(order['requisition_id'] for order in orders
                           if order['requisition_id']))
        # we'll read the fields without the 'tender_' prefix
        # and copy their value in the fields with the prefix
        read_fields = [x[len('tender_'):] for x in fields]
        requisitions = purch_req_obj.read(cr, uid,
                                          req_ids,
                                          read_fields,
                                          context=context,
                                          load='_classic_write')
        # copy the dict but rename the fields with 'tender_' prefix
        tender_reqs = {}
        for req in requisitions:
            tender_reqs[req['id']] = dict(('tender_' + field, value)
                                          for field, value
                                          in req.iteritems()
                                          if 'tender_' + field in fields)
        res = {}
        for po in orders:
            if po['requisition_id']:
                res[po['id']] = tender_reqs[po['requisition_id']]
            else:
                res[po['id']] = {}.fromkeys(fields, False)
        return res

    def _prepare_purchase_order(self, cr, uid, requisition, supplier, context=None):
        values = super(purchase_order, self)._prepare_purchase_order(
            cr, uid, requisition, supplier, context=context)
        values.update({
            'bid_validity': requisition.req_validity,
            'payment_term_id': requisition.req_payment_term_id,
            'incoterm_id': requisition.req_incoterm_id,
            'incoterm_address': requisition.req_incoterm_address,
            'transport_mode_id': requisition.req_transport_mode_id,
        })
        return values

    def copy(self, cr, uid, id, default=None, context=None):
        """ Need to set origin after copy because original copy clears origin """
        if default is None:
            default = {}
        initial_origin = default.get('origin')
        newid = super(purchase_order, self).copy(cr, uid, id, default=default,
                                                 context=context)
        if initial_origin:
            self.write(cr, SUPERUSER_ID, [newid], {'origin': origin}, context=context)
        return newid

<commit_msg>[IMP] Add a pricelist in tendering process<commit_after># -*- coding: utf-8 -*-

from openerp.osv import fields, orm
from openerp import SUPERUSER_ID


class purchase_order(orm.Model):
    _inherit = 'purchase.order'
    _columns = {
        'bid_partial': fields.boolean(
            'Bid partially selected',
            readonly=True,
            help="True if the bid has been partially selected"),
        'tender_bid_receipt_mode': fields.function(
            lambda self, *args, **kwargs: self._get_tender(*args, **kwargs),
            multi="callforbids",
            readonly=True,
            type='selection',
            selection=[('open', 'Open'), ('sealed', 'Sealed')],
            string='Bid Receipt Mode'),
    }
    #TODO: lines should not be deleted or created if linked to a callforbids

    def _get_tender(self, cr, uid, ids, fields, args, context=None):
        # when _classic_write load is used, the many2one are only the
        # ids instead of the tuples (id, name_get)
        purch_req_obj = self.pool.get('purchase.requisition')
        orders = self.read(cr, uid, ids, ['requisition_id'],
                           context=context, load='_classic_write')
        req_ids = list(set(order['requisition_id'] for order in orders
                           if order['requisition_id']))
        # we'll read the fields without the 'tender_' prefix
        # and copy their value in the fields with the prefix
        read_fields = [x[len('tender_'):] for x in fields]
        requisitions = purch_req_obj.read(cr, uid,
                                          req_ids,
                                          read_fields,
                                          context=context,
                                          load='_classic_write')
        # copy the dict but rename the fields with 'tender_' prefix
        tender_reqs = {}
        for req in requisitions:
            tender_reqs[req['id']] = dict(('tender_' + field, value)
                                          for field, value
                                          in req.iteritems()
                                          if 'tender_' + field in fields)
        res = {}
        for po in orders:
            if po['requisition_id']:
                res[po['id']] = tender_reqs[po['requisition_id']]
            else:
                res[po['id']] = {}.fromkeys(fields, False)
        return res

    def _prepare_purchase_order(self, cr, uid, requisition, supplier, context=None):
        values = super(purchase_order, self)._prepare_purchase_order(
            cr, uid, requisition, supplier, context=context)
        values.update({
            'bid_validity': requisition.req_validity,
            'payment_term_id': requisition.req_payment_term_id,
            'incoterm_id': requisition.req_incoterm_id,
            'incoterm_address': requisition.req_incoterm_address,
            'transport_mode_id': requisition.req_transport_mode_id,
        })
        if requisition.pricelist_id:
            values.update({'pricelist_id': requisition.pricelist_id.id})
        return values

    def copy(self, cr, uid, id, default=None, context=None):
        """ Need to set origin after copy because original copy clears origin """
        if default is None:
            default = {}
        initial_origin = default.get('origin')
        newid = super(purchase_order, self).copy(cr, uid, id, default=default,
                                                 context=context)
        if initial_origin:
            self.write(cr, SUPERUSER_ID, [newid], {'origin': origin}, context=context)
        return newid


{'fraction_non_alphanumeric': 0.09978917779339423, 'fraction_numerical': 0.0005621925509487, 'mean_word_length': 1.8521042084168338, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '822455', 'n_tokens_mistral': 1946, 'n_tokens_neox': 1885, 'n_words': 508}