Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] supplier_bid_price : Implemented Supplier Bid Price Update via … #630

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions supplier_bid_price/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import controllers
23 changes: 23 additions & 0 deletions supplier_bid_price/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
'name': "Supplier Bid Price Update",
'version': '1.0',
'depends': ['purchase', 'website'],
'author': "djsh",
'category': 'Purchase',
'description': """
Supplier Bid Price Update from portal
""",
'data': [
'security/ir.model.access.csv',
'data/email_templates.xml',
'views/purchase_views.xml',
'views/portal_templates.xml'
],
'assets': {
'web.assets_frontend': [
'supplier_bid_price/static/src/js/update_bid.js',
],
},
'license': 'LGPL-3',
'application': True,
}
1 change: 1 addition & 0 deletions supplier_bid_price/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import portal
38 changes: 38 additions & 0 deletions supplier_bid_price/controllers/portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import http
from odoo.http import request, Response

class BidController(http.Controller):

@http.route('/update_bids', type='json', auth='user', methods=['POST'])
def update_bids(self, bids):
if not bids:
return {'success': False, 'message': 'No bid data received'}

mail_values = []
try:
for bid in bids:
order_id = int(bid.get("order_id"))
line_id = int(bid.get("line_id"))
bid_qty = float(bid.get("bid_qty", 0))
bid_price = float(bid.get("bid_price", 0))

order = request.env['purchase.order'].browse(order_id)
line = request.env['purchase.order.line'].browse(line_id)
if line.exists():
if line.bid_qty != bid_qty or line.bid_price != bid_price:
mail_values.append({
'product_id' : line.product_id.sudo().name,
'bid_qty' : bid_qty,
'bid_price' : bid_price
})
line.write({
'bid_qty': bid_qty,
'bid_price': bid_price,
})
order._send_bid_update_email(mail_values)
return {'success': True, 'message': 'Bids updated successfully'}

except Exception as e:
return {'success': False, 'message': str(e)}
25 changes: 25 additions & 0 deletions supplier_bid_price/data/email_templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="email_template_supplier_bid_update" model="mail.template">
<field name="name">Supplier Bid Update Notification</field>
<field name="model_id" ref="purchase.model_purchase_order"/>
<field name="subject">Supplier Updated Bid Price for RFQ {{ object.name or 'n/a' }}</field>
<field name="email_from">{{ object.company_id.email or '[email protected]' }}</field>
<field name="email_to">{{ object.user_id.email }}</field>
<field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
<p style="margin: 0px; padding: 0px; font-size: 13px;">
<ul>
<li><strong>Supplier: </strong><t t-out="object.partner_id.name"/></li>
<li><strong>RFQ Number: </strong><t t-out="object.name"/></li>
<t t-foreach="ctx.get('mail_values', [])" t-as="line">
<li><strong>New Bid Price for <t t-out="line.get('product_id')"/>: </strong>$<t t-out="line.get('bid_price')"/></li>
<li><strong>New Bid Quantity for <t t-out="line.get('product_id')"/>: </strong><t t-out="line.get('bid_qty')"/> Units</li>
</t>
</ul>
<p><strong>Action Required:</strong> Review the updated bid price in the system.</p>
</p>
</div>
</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions supplier_bid_price/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import product_order_line
from . import purchase_order
10 changes: 10 additions & 0 deletions supplier_bid_price/models/product_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models


class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'

bid_qty = fields.Float(string="Bid Quantity", readonly=False)
bid_price = fields.Float(string="Bid Price", readonly=False)
17 changes: 17 additions & 0 deletions supplier_bid_price/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models


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

def _send_bid_update_email(self,mail_values):
if not mail_values:
return
template = self.env.ref('supplier_bid_price.email_template_supplier_bid_update').sudo()
if template:
email_ctx = {
'mail_values' : mail_values
}
template.with_context(**email_ctx).send_mail(self.id, force_send=True)
3 changes: 3 additions & 0 deletions supplier_bid_price/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_purchase_order_line_supplier,purchase.order.line,model_purchase_order_line,base.group_portal,1,1,0,0
access_purchase_order_line_user,purchase.order.line,model_purchase_order_line,base.group_user,1,0,0,0
43 changes: 43 additions & 0 deletions supplier_bid_price/static/src/js/update_bid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/** @odoo-module **/
import { rpc } from "@web/core/network/rpc";

async function update_all_bids() {
const bid_data = [...document.querySelectorAll(".bid-qty")]
.map(input => {
const line_id = input.dataset.lineId;
return {
order_id: input.dataset.orderId,
line_id: line_id,
bid_qty: parseFloat(input.value) || 0,
bid_price: parseFloat(
document.querySelector(`.bid-price[data-line-id="${line_id}"]`)?.value || "0"
)
};
})
.filter(bid => bid.bid_qty > 0 || bid.bid_price > 0);

if (bid_data.length === 0) {
alert("No valid bids to update!");
return;
}
try {
const response = await rpc("/update_bids", { bids: bid_data });
if (response.success) {
alert("Bids updated successfully!");
location.reload();
} else {
alert("Error updating bids.");
}
} catch (error) {
alert("Failed to update bids.");
}
}

function onClick() {
const button = document.getElementById("update_all_bids");
if (button) {
button.addEventListener("click", update_all_bids);
}
}

onClick();
38 changes: 38 additions & 0 deletions supplier_bid_price/views/portal_templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="purchase_order_portal_content_inherit" inherit_id="purchase.purchase_order_portal_content">
<xpath expr="//thead[hasclass('bg-100')]/tr/th[contains(text(), 'Products')]" position="inside">
<th class="text-end">Bid Quantity</th>
<th class="text-end">Bid Price</th>
</xpath>

<xpath expr="//td[@id='product_name']" position="after">
<input type="hidden" class="order_id" t-att-id="order_id" t-att-name="order_id" t-att-value="order.id"/>
<td class="text-end">
<t t-if="not order.mail_reception_confirmed and not order.mail_reception_declined and request.env.user.partner_id == order.partner_id">
<input type="number" class="form-control bid-qty" t-att-data-order-id="order.id" t-att-data-line-id="line.id" t-att-value="line.bid_qty or ''"/>
</t>
<t t-else="">
<span t-field="line.bid_qty"/>
</t>
</td>

<td class="text-end">
<t t-if="not order.mail_reception_confirmed and not order.mail_reception_declined and request.env.user.partner_id == order.partner_id">
<input type="number" class="form-control bid-price" t-att-data-order-id="order.id" t-att-data-line-id="line.id" t-att-value="line.bid_price or ''"/>
</t>
<t t-else="">
<span t-field="line.bid_price"/>
</t>
</td>
</xpath>

<xpath expr="//div[hasclass('col-lg-6')]" position="after">
<t t-if="not order.mail_reception_confirmed and not order.mail_reception_declined and request.env.user.partner_id == order.partner_id">
<button type="button" class="btn btn-primary col-lg-4 mt-auto" id="update_all_bids">
Update Bid Quantity and Price
</button>
</t>
</xpath>
</template>
</odoo>
14 changes: 14 additions & 0 deletions supplier_bid_price/views/purchase_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="purchase_order_form_inherit" model="ir.ui.view">
<field name="name">purchase.order.form.inherit</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<field name="product_id" position="after">
<field name="bid_qty" readonly="1"/>
<field name="bid_price" readonly="1"/>
</field>
</field>
</record>
</odoo>