<commit_before># -*- coding: utf-8 -*-
#    Author: <NAME>, <NAME>
#    Copyright 2013-2015 Camptocamp SA
#
#    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 import models, fields, api
from openerp import exceptions, _


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

    portfolio_id = fields.Many2one(
        'framework.agreement.portfolio',
        'Portfolio'
    )


class PurchaseOrderLine(models.Model):
    """Add on change on price to raise a warning if line is subject to
    an agreement.
    """

    _inherit = "purchase.order.line"

    framework_agreement_id = fields.Many2one(
        'framework.agreement',
        'Agreement',
    )

    @api.onchange('price_unit')
    def onchange_price_unit(self):
        agreement_price = self.framework_agreement_id.get_price(
            self.product_qty,
            currency=self.order_id.pricelist_id.currency_id)
        if agreement_price != self.price_unit:
            msg = _(
                "You have set the price to %s \n"
                " but there is a running agreement"
                " with price %s") % (
                    self.price_unit, agreement_price
            )
            raise exceptions.Warning(msg)
        return {}

    @api.multi<commit_msg>portfolio and agreement on order line<commit_after># -*- coding: utf-8 -*-
#    Author: <NAME>, <NAME>
#    Copyright 2013-2015 Camptocamp SA
#
#    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 import models, fields, api
from openerp import exceptions, _


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

    portfolio_id = fields.Many2one(
        'framework.agreement.portfolio',
        'Portfolio'
    )


class PurchaseOrderLine(models.Model):
    """Add on change on price to raise a warning if line is subject to
    an agreement.
    """

    _inherit = "purchase.order.line"

    framework_agreement_id = fields.Many2one(
        'framework.agreement',
        'Agreement',
        domain=[('portfolio_id', '=', 'order_id.portfolio_id')],
    )

    portfolio_id = fields.Many2one(
        'framework.agreement.portfolio',
        'Portfolio',
        readonly=True,
        related='order_id.portfolio_id',
    )

    @api.onchange('price_unit')
    def onchange_price_unit(self):
        agreement_price = self.framework_agreement_id.get_price(
            self.product_qty,
            currency=self.order_id.pricelist_id.currency_id)
        if agreement_price != self.price_unit:
            msg = _(
                "You have set the price to %s \n"
                " but there is a running agreement"
                " with price %s") % (
                    self.price_unit, agreement_price
            )
            raise exceptions.Warning(msg)
        return {}

    @api.multi
{'fraction_non_alphanumeric': 0.08419243986254296, 'fraction_numerical': 0.006136475208640157, 'mean_word_length': 2.5220397579948144, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6597107', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1105, 'n_words': 388}