Step-1 Install the Framework_agreement module.
Step-2 Framework_agreement->Model->Purchases.py
Step-3 After that custmozie purchases.py(Python file) file:
In below example, I have custmozied purchases.py file. You can directly copy the below python code in your purchases.py file.
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',
domain="[('supplier_id', '=', partner_id)]",
)
@api.onchange('pricelist_id')
def update_currency_from_pricelist(self):
"""Reproduce the old_api onchange_pricelist from the purchase module.
We need new-style onchanges to be able to modify agreements on order
lines, and we cannot have new-style and old-style onchanges at the same
time.
"""
self.currency_id = self.pricelist_id.currency_id
@api.onchange('portfolio_id', 'pricelist_id', 'date_order', 'incoterm_id')
def update_agreements_in_lines(self):
Agreement = self.env['framework.agreement']
if self.portfolio_id:
for line in self.order_line:
ag_domain = Agreement.get_agreement_domain(
line.product_id.id,
line.product_qty,
self.portfolio_id.id,
self.date_order,
self.incoterm_id.id,
)
good_agreements = Agreement.search(ag_domain).filtered(
lambda a: a.has_currency(self.currency_id))
if line.framework_agreement_id in good_agreements:
pass # it's good! let's keep it!
else:
if len(good_agreements) == 1:
line.framework_agreement_id = good_agreements
else:
line.framework_agreement_id = Agreement
if line.framework_agreement_id:
line.price_unit = line.framework_agreement_id.get_price(
line.product_qty, self.currency_id)
else:
self.order_line.write({'framework_agreement_id': False})
@api.multi
def onchange_partner_id(self, partner_id):
"""Prevent changes to the supplier if the portfolio is set.
We use web_context_tunnel in order to keep the original signature.
"""
res = super(PurchaseOrder, self).onchange_partner_id(partner_id)
if self.env.context.get('portfolio_id'):
raise exceptions.Warning(
_('You cannot change the supplier: '
'the PO is linked to an agreement portfolio.')
)
return res
class PurchaseOrderLine(models.Model):
"""Add on change on price to raise a warning if line is subject to
an agreement.
"""
0 Comment(s)