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

from openerp.osv import fields, orm
from openerp import netsvc
from openerp.tools.translate import _
from openerp import SUPERUSER_ID


class PurchaseOrder(orm.Model):
    _inherit = "purchase.order"

    STATE_SELECTION = [
        ('draft', 'Draft RFQ'),
        ('sent', 'RFQ Sent'),
        ('draftbid', 'Draft Bid'),  # added
        ('bid', 'Bid Encoded'),  # Bid Received renamed into Bid Encoded
        ('bid_selected', 'Bid selected'), # added
        ('draftpo', 'Draft PO'),  # added
        ('confirmed', 'Waiting Approval'),
        ('approved', 'Purchase Confirmed'),
        ('except_picking', 'Shipping Exception'),
        ('except_invoice', 'Invoice Exception'),
        ('done', 'Done'),
        ('cancel', 'Canceled')
    ]
    TYPE_SELECTION = [
        ('rfq', 'Request for Quotation'),
        ('bid', 'Bid'),
        ('purchase', 'Purchase Order')
    ]

    _columns = {
        'state': fields.selection(STATE_SELECTION, 'Status', readonly=True, select=True,
            help="The status of the purchase order or the quotation request. A "
                 "quotation is a purchase order in a 'Draft' status. Then the order "
                 "has to be confirmed by the user, the status switch to 'Confirmed'. "
                 "Then the supplier must confirm the order to change the status to "
                 "'Approved'. When the purchase order is paid and received, the "
                 "status becomes 'Done'. If a cancel action occurs in the invoice or "
                 "in the reception of goods, the status becomes in exception."),
        'type': fields.selection(TYPE_SELECTION, 'Type', required=True, readonly=True),
        'consignee_id': fields.many2one('res.partner', 'Consignee', help="the person to whom the shipment is to be delivered"),
        'incoterm_address': fields.char(
            'Incoterms Place',
            help="Incoterms Place of Delivery. "
                 "International Commercial Terms are a series of "
                 "predefined commercial terms used in "
                 "international transactions."),
        'cancel_reason_id': fields.many2one('purchase.cancelreason', 'Reason for Cancellation', readonly=True),
    }
    _defaults = {
        'state': lambda self, cr, uid, context: 'draftpo' if context.get('draft_po')
                                          else 'draftbid' if context.get('draft_bid')
                                          else 'draft',
        'type': lambda self, cr, uid, context: 'purchase' if context.get('draft_po')
                                          else 'bid' if context.get('draft_bid')
                                          else 'rfq',
    }

    def create(self, cr, uid, vals, context=None):
        # Document can be created as Draft RFQ or Draft PO. We need to log the right message.
        if context is None:
            context = {}
        description = self._description
        if context.get('draft_bid'):
            self._description = 'Draft Bid'
        elif not context.get('draft_po'):
            self._description = 'Request for Quotation'
        id = super(PurchaseOrder, self).create(cr, uid, vals, context=context)
        self._description = description
        if context.get('draft_bid'):
            wf_service = netsvc.LocalService("workflow")
            wf_service.trg_validate(uid, 'purchase.order', id, 'draft_bid', cr)
        if context.get('draft_po'):
            wf_service = netsvc.LocalService("workflow")
            wf_service.trg_validate(uid, 'purchase.order', id, 'draft_po', cr)
        return id

    def copy(self, cr, uid, id, default=None, context=None):
        newid = super(PurchaseOrder, self).copy(cr, uid, id, default=default, context=context)
        po = self.read(cr, SUPERUSER_ID, newid, ['type', 'order_line'], context=context, load='_classic_write')
        if po['type'] == 'rfq' and po['order_line']:
            self.pool.get('purchase.order.line').write(cr, SUPERUSER_ID, po['order_line'], {'price_unit': 0}, context=context)
        return newid

    def wkf_draft_po(self, cr, uid, ids, context=None):
        self.message_post(cr, uid, ids, body=_("Converted to draft Purchase Order"), subtype="mail.mt_comment", context=context)
        return self.write(cr, uid, ids, {'state': 'draftpo', 'type': 'purchase'}, context=context)

    def action_cancel(self, cr, uid, ids, context=None):
        """ Ask a cancel reason
        """
        if context is None:
            context = {}
        context['action'] = 'action_cancel_ok'
        view_id = self.pool.get('ir.model.data').get_object_reference(cr, SUPERUSER_ID, 'purchase_extended', 'action_modal_cancel_reason')[1]
        #TODO: filter based on po type
        return {
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'purchase.action_modal_cancelreason',
            'view_id': view_id,
            'views': [(view_id, 'form')],
            'target': 'new',
            'context': context,
        }

    def action_cancel_ok(self, cr, uid, ids, context=None):<commit_msg>[FIX] cancel of requisition did not cancel related PO<commit_after># -*- coding: utf-8 -*-

from openerp.osv import fields, orm
from openerp import netsvc
from openerp.tools.translate import _
from openerp import SUPERUSER_ID


class PurchaseOrder(orm.Model):
    _inherit = "purchase.order"

    STATE_SELECTION = [
        ('draft', 'Draft RFQ'),
        ('sent', 'RFQ Sent'),
        ('draftbid', 'Draft Bid'),  # added
        ('bid', 'Bid Encoded'),  # Bid Received renamed into Bid Encoded
        ('bid_selected', 'Bid selected'), # added
        ('draftpo', 'Draft PO'),  # added
        ('confirmed', 'Waiting Approval'),
        ('approved', 'Purchase Confirmed'),
        ('except_picking', 'Shipping Exception'),
        ('except_invoice', 'Invoice Exception'),
        ('done', 'Done'),
        ('cancel', 'Canceled')
    ]
    TYPE_SELECTION = [
        ('rfq', 'Request for Quotation'),
        ('bid', 'Bid'),
        ('purchase', 'Purchase Order')
    ]

    _columns = {
        'state': fields.selection(STATE_SELECTION, 'Status', readonly=True, select=True,
            help="The status of the purchase order or the quotation request. A "
                 "quotation is a purchase order in a 'Draft' status. Then the order "
                 "has to be confirmed by the user, the status switch to 'Confirmed'. "
                 "Then the supplier must confirm the order to change the status to "
                 "'Approved'. When the purchase order is paid and received, the "
                 "status becomes 'Done'. If a cancel action occurs in the invoice or "
                 "in the reception of goods, the status becomes in exception."),
        'type': fields.selection(TYPE_SELECTION, 'Type', required=True, readonly=True),
        'consignee_id': fields.many2one('res.partner', 'Consignee', help="the person to whom the shipment is to be delivered"),
        'incoterm_address': fields.char(
            'Incoterms Place',
            help="Incoterms Place of Delivery. "
                 "International Commercial Terms are a series of "
                 "predefined commercial terms used in "
                 "international transactions."),
        'cancel_reason_id': fields.many2one('purchase.cancelreason', 'Reason for Cancellation', readonly=True),
    }
    _defaults = {
        'state': lambda self, cr, uid, context: 'draftpo' if context.get('draft_po')
                                          else 'draftbid' if context.get('draft_bid')
                                          else 'draft',
        'type': lambda self, cr, uid, context: 'purchase' if context.get('draft_po')
                                          else 'bid' if context.get('draft_bid')
                                          else 'rfq',
    }

    def create(self, cr, uid, vals, context=None):
        # Document can be created as Draft RFQ or Draft PO. We need to log the right message.
        if context is None:
            context = {}
        description = self._description
        if context.get('draft_bid'):
            self._description = 'Draft Bid'
        elif not context.get('draft_po'):
            self._description = 'Request for Quotation'
        id = super(PurchaseOrder, self).create(cr, uid, vals, context=context)
        self._description = description
        if context.get('draft_bid'):
            wf_service = netsvc.LocalService("workflow")
            wf_service.trg_validate(uid, 'purchase.order', id, 'draft_bid', cr)
        if context.get('draft_po'):
            wf_service = netsvc.LocalService("workflow")
            wf_service.trg_validate(uid, 'purchase.order', id, 'draft_po', cr)
        return id

    def copy(self, cr, uid, id, default=None, context=None):
        newid = super(PurchaseOrder, self).copy(cr, uid, id, default=default, context=context)
        po = self.read(cr, SUPERUSER_ID, newid, ['type', 'order_line'], context=context, load='_classic_write')
        if po['type'] == 'rfq' and po['order_line']:
            self.pool.get('purchase.order.line').write(cr, SUPERUSER_ID, po['order_line'], {'price_unit': 0}, context=context)
        return newid

    def wkf_draft_po(self, cr, uid, ids, context=None):
        self.message_post(cr, uid, ids, body=_("Converted to draft Purchase Order"), subtype="mail.mt_comment", context=context)
        return self.write(cr, uid, ids, {'state': 'draftpo', 'type': 'purchase'}, context=context)

    def action_cancel(self, cr, uid, ids, context=None):
        """ Ask a cancel reason
        """
        if context is None:
            context = {}
        context['action'] = 'action_cancel_ok'
        view_id = self.pool.get('ir.model.data').get_object_reference(cr, SUPERUSER_ID, 'purchase_extended', 'action_modal_cancel_reason')[1]
        #TODO: filter based on po type
        return {
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'purchase.action_modal_cancelreason',
            'view_id': view_id,
            'views': [(view_id, 'form')],
            'target': 'new',
            'context': context,
        }

    def action_cancel_no_reason(self, cr, uid, ids, context=None):
        return super(PurchaseOrder, self).action_cancel(cr, uid, ids,
                                                        context=context)

    def action_cancel_ok(self, cr, uid, ids, context=None):
{'fraction_non_alphanumeric': 0.12600510831520198, 'fraction_numerical': 0.0009459842966606754, 'mean_word_length': 2.3508716323296355, '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': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3507943', 'n_tokens_mistral': 3033, 'n_tokens_neox': 2949, 'n_words': 861}