@ -0,0 +1,48 @@ |
|||||
|
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg |
||||
|
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html |
||||
|
:alt: License: AGPL-3 |
||||
|
|
||||
|
Website Product Reservation |
||||
|
=========================== |
||||
|
This module helps you to reserve products from the website. |
||||
|
|
||||
|
Configuration |
||||
|
============= |
||||
|
* No additional configurations needed |
||||
|
|
||||
|
Company |
||||
|
------- |
||||
|
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
||||
|
|
||||
|
License |
||||
|
------- |
||||
|
Gnu Affero General Public License, Version 3 (AGPL v3). |
||||
|
(https://www.gnu.org/licenses/agpl-3.0-standalone.html) |
||||
|
|
||||
|
Credits |
||||
|
------- |
||||
|
* Developers : (V16) Muhsina V, |
||||
|
(V17) Fathima Mazlin AM, |
||||
|
Contact : odoo@cybrosys.com |
||||
|
|
||||
|
Contacts |
||||
|
-------- |
||||
|
* Mail Contact : odoo@cybrosys.com |
||||
|
* Website : https://cybrosys.com |
||||
|
|
||||
|
Bug Tracker |
||||
|
----------- |
||||
|
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. |
||||
|
|
||||
|
Maintainer |
||||
|
========== |
||||
|
.. image:: https://cybrosys.com/images/logo.png |
||||
|
:target: https://cybrosys.com |
||||
|
|
||||
|
This module is maintained by Cybrosys Technologies. |
||||
|
|
||||
|
For support and more information, please visit `Our Website <https://cybrosys.com/>`__ |
||||
|
|
||||
|
Further information |
||||
|
=================== |
||||
|
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# 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 (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from . import controllers |
||||
|
from . import models |
@ -0,0 +1,51 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# 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 (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
{ |
||||
|
'name': 'Website Product Reservation', |
||||
|
'version': '18.0.1.0.0', |
||||
|
'category': 'Website', |
||||
|
'summary': 'Enable product reservation functionality on your website', |
||||
|
'description': "This module extends the website functionality by enabling " |
||||
|
"product reservation. Allow your customers to reserve " |
||||
|
"products directly from your website, and manage these " |
||||
|
"reservations seamlessly within the Odoo environment. " |
||||
|
"Enhance the shopping experience by providing a reservation" |
||||
|
" feature for in-demand products.", |
||||
|
'author': 'Cybrosys Techno Solutions', |
||||
|
'company': 'Cybrosys Techno Solutions', |
||||
|
'maintainer': 'Cybrosys Techno Solutions', |
||||
|
'website': 'https://www.cybrosys.com', |
||||
|
'depends': ['website_sale', 'stock'], |
||||
|
'data': [ |
||||
|
'data/website_menu.xml', |
||||
|
'views/product_template_views.xml', |
||||
|
'views/res_cofig_settings_views.xml', |
||||
|
'views/sale_order_views.xml', |
||||
|
'views/website_templates.xml', |
||||
|
'views/portal_templates.xml', |
||||
|
], |
||||
|
'images': ['static/description/banner.jpg'], |
||||
|
'license': 'AGPL-3', |
||||
|
'installable': True, |
||||
|
'auto_install': False, |
||||
|
'application': False, |
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# 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 (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from . import portal |
||||
|
from . import website_product_reservation |
@ -0,0 +1,97 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# 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 (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from odoo import http |
||||
|
from odoo.http import request |
||||
|
from odoo.addons.portal.controllers import portal |
||||
|
|
||||
|
|
||||
|
class ReservationCustomerPortal(portal.CustomerPortal): |
||||
|
|
||||
|
def _get_reservation_domain(self): |
||||
|
"""It returns the login person""" |
||||
|
return [('partner_id', '=', request.env.user.partner_id.id)] |
||||
|
|
||||
|
@http.route('/my/reservation/requests', |
||||
|
type='http', auth='user', website=True) |
||||
|
def portal_my_reservation_orders(self): |
||||
|
"""List out the reservation Order""" |
||||
|
domain = self._get_reservation_domain() |
||||
|
domain.append(('is_reservation_order', '=', 'True')) |
||||
|
values = { |
||||
|
'reservation_request': request.env['sale.order'].sudo().search( |
||||
|
domain), |
||||
|
} |
||||
|
return request.render( |
||||
|
"website_product_reservation.portal_my_reservation_requests_tree", |
||||
|
values) |
||||
|
|
||||
|
@http.route(['/my/reservation/requests/form/<int:reservation_id>'], |
||||
|
type='http', |
||||
|
auth="user", website=True) |
||||
|
def get_my_reservation_request_form(self, reservation_id): |
||||
|
"""Form view of reservation from website""" |
||||
|
return request.render( |
||||
|
"website_product_reservation.portal_my_reservation_requests_form", |
||||
|
{'record_reservation_requests': request.env[ |
||||
|
'sale.order'].sudo().browse(reservation_id)}) |
||||
|
|
||||
|
@http.route(['/my/reservation/requests/form/id=<int:reservation_id>'], |
||||
|
type='http', |
||||
|
auth="user", website=True) |
||||
|
def get_my_reservation_request_form_cancel(self, reservation_id): |
||||
|
""" Cancel the reservation from website""" |
||||
|
cancel = request.env[ |
||||
|
'sale.order'].sudo().browse(reservation_id) |
||||
|
cancel.action_cancel_reservation() |
||||
|
return request.render( |
||||
|
"website_product_reservation.portal_my_reservation_requests_form", |
||||
|
{'record_reservation_requests': request.env[ |
||||
|
'sale.order'].sudo().browse(reservation_id)}) |
||||
|
|
||||
|
@http.route(['/my/reservation/requests/form/confirm=<int:reservation_id>'], |
||||
|
type='http', |
||||
|
auth="user", website=True) |
||||
|
def get_my_reservation_request_form_confirm(self, reservation_id): |
||||
|
"""Confirm the reservation from website""" |
||||
|
confirm = request.env[ |
||||
|
'sale.order'].sudo().browse(reservation_id) |
||||
|
confirm.action_make_draft() |
||||
|
confirm.action_confirm() |
||||
|
return request.render( |
||||
|
"website_product_reservation.portal_my_reservation_requests_form", |
||||
|
{'record_reservation_requests': request.env[ |
||||
|
'sale.order'].sudo().browse(reservation_id)}) |
||||
|
|
||||
|
|
||||
|
class Return(portal.CustomerPortal): |
||||
|
"""This will take the count of total courier requests""" |
||||
|
|
||||
|
def _prepare_home_portal_values(self, counters): |
||||
|
"""This will return the certificates count""" |
||||
|
values = super(Return, self)._prepare_home_portal_values(counters) |
||||
|
values.update({ |
||||
|
'reservation_count': request.env[ |
||||
|
'sale.order'].sudo().search_count( |
||||
|
[('partner_id', '=', request.env.user.partner_id.id), |
||||
|
('is_reservation_order', '=', 'True')]) |
||||
|
}) |
||||
|
return values |
@ -0,0 +1,114 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# 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 (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
import json |
||||
|
from odoo import http |
||||
|
from odoo.http import request |
||||
|
from odoo.addons.website_sale.controllers.main import WebsiteSale |
||||
|
|
||||
|
|
||||
|
class WebsiteSaleReservation(WebsiteSale): |
||||
|
"""Custom controller for handling reservation-related functionality on |
||||
|
the website.""" |
||||
|
|
||||
|
@http.route( |
||||
|
["/reservation", "/reservation/page/<int:page>"], |
||||
|
type="http", |
||||
|
auth="public", |
||||
|
website=True, |
||||
|
) |
||||
|
def reservation(self, page=1, **kw): |
||||
|
"""Display a page with products available for reservation. |
||||
|
:param page: Page number for pagination. |
||||
|
:param kw: Additional keyword arguments. |
||||
|
:return: HTTP response rendering the reservation page.""" |
||||
|
domain = [("reserve_products", "=", True), ("website_published", "=", True)] |
||||
|
product_obj = request.env["product.template"] |
||||
|
product_count = product_obj.search_count(domain) |
||||
|
pager = request.website.pager( |
||||
|
url="/reservation", total=product_count, page=page, step=12 |
||||
|
) |
||||
|
products = product_obj.search(domain, limit=12, offset=pager["offset"]) |
||||
|
values = { |
||||
|
"products": products, |
||||
|
"page_name": "Reserve Products", |
||||
|
"pager": pager, |
||||
|
"default_url": "/reservation", |
||||
|
} |
||||
|
self.clear_cart() |
||||
|
return request.render("website_product_reservation.reservation_page", values) |
||||
|
|
||||
|
@http.route( |
||||
|
["/reservation/reserve"], |
||||
|
type="http", |
||||
|
auth="public", |
||||
|
methods=["POST"], |
||||
|
website=True, |
||||
|
csrf=False, |
||||
|
) |
||||
|
def reservation_update(self, product_id, add_qty=1, set_qty=0, **kw): |
||||
|
"""Update the reservation order based on user input. |
||||
|
:param product_id: ID of the product being reserved. |
||||
|
:param add_qty: Quantity to add to the reservation. |
||||
|
:param set_qty: Quantity to set for the reservation. |
||||
|
:param kw: Additional keyword arguments. |
||||
|
:return: HTTP response redirecting to the shopping cart.""" |
||||
|
product_custom_attribute_values = None |
||||
|
if kw.get("product_custom_attribute_values"): |
||||
|
product_custom_attribute_values = json.loads( |
||||
|
kw.get("product_custom_attribute_values") |
||||
|
) |
||||
|
request.website.sale_get_order(force_create=1)._cart_update( |
||||
|
product_id=int(product_id), |
||||
|
add_qty=float(add_qty), |
||||
|
set_qty=float(set_qty), |
||||
|
product_custom_attribute_values=product_custom_attribute_values, |
||||
|
) |
||||
|
if kw.get("type_name") == "Reservation": |
||||
|
request.website.sale_get_order().is_reservation_order = True |
||||
|
return request.redirect("/shop/cart") |
||||
|
|
||||
|
@http.route( |
||||
|
["/reservation/confirm_reserve_order"], type="http", auth="public", website=True |
||||
|
) |
||||
|
def confirm_reserve_order(self, **post): |
||||
|
"""Confirm and finalize the reservation order. |
||||
|
:param post: POST data from the request. |
||||
|
:return: HTTP response rendering the confirmation or error page.""" |
||||
|
order = request.website.sale_get_order() |
||||
|
is_reservation = all( |
||||
|
order.website_order_line.mapped("product_id").mapped("reserve_products") |
||||
|
) |
||||
|
if is_reservation: |
||||
|
order.state = "reserve" |
||||
|
request.website.sale_reset() |
||||
|
for line in order.order_line.filtered( |
||||
|
lambda line: line.product_id.type == "product" |
||||
|
): |
||||
|
line.sudo().create_reservation_stock() |
||||
|
self.clear_cart() |
||||
|
return request.render( |
||||
|
"website_product_reservation.reservation_thankyou", {"order": order} |
||||
|
) |
||||
|
else: |
||||
|
return request.render( |
||||
|
"website_product_reservation.not_allowed_to_reserve_page", {} |
||||
|
) |
@ -0,0 +1,10 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<!-- Define a menu item for the "Reservation" section on the website --> |
||||
|
<record id="menu_reservation" model="website.menu"> |
||||
|
<field name="name">Reservation</field> |
||||
|
<field name="url">/reservation</field> |
||||
|
<field name="parent_id" ref="website.main_menu"/> |
||||
|
<field name="sequence">55</field> |
||||
|
</record> |
||||
|
</odoo> |
@ -0,0 +1,6 @@ |
|||||
|
## Module <website_product_reservation> |
||||
|
|
||||
|
#### 13.11.2024 |
||||
|
#### Version 18.0.1.0.0 |
||||
|
##### ADD |
||||
|
- Initial Commit for Website Product Reservation |
@ -0,0 +1,24 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# 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 (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from . import product_template |
||||
|
from . import sale_order |
||||
|
from . import sale_order_line |
@ -0,0 +1,31 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# 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 (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from odoo import fields, models |
||||
|
|
||||
|
|
||||
|
class ProductTemplate(models.Model): |
||||
|
""" This class extends the 'product.template' model in Odoo. |
||||
|
It adds custom field to choose the reservation product.""" |
||||
|
_inherit = "product.template" |
||||
|
|
||||
|
reserve_products = fields.Boolean(string='Reserve Products', |
||||
|
help="enable to reserve this product") |
@ -0,0 +1,83 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# 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 (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from odoo import fields, models |
||||
|
|
||||
|
|
||||
|
class SaleOrder(models.Model): |
||||
|
""" This class extends the 'sale.order' model in Odoo. |
||||
|
It adds a new state ('reserve') and introduces a boolean field |
||||
|
('is_reservation_order') to identify reservation orders. |
||||
|
Methods: |
||||
|
- action_make_draft: Sets the order state to 'draft' and cancels |
||||
|
reservation stock for product lines. |
||||
|
- action_cancel_reservation: Cancels reservation stock for product |
||||
|
lines and sets the order state to 'cancel'.""" |
||||
|
_inherit = 'sale.order' |
||||
|
|
||||
|
state = fields.Selection(selection_add=[('reserve', 'Reserve')], |
||||
|
string='Order State', |
||||
|
help='The state of the sale order') |
||||
|
is_reservation_order = fields.Boolean(string='Reservation Order', |
||||
|
help='Check if the order is a ' |
||||
|
'reservation order') |
||||
|
|
||||
|
def action_make_draft(self): |
||||
|
""" Action method to set the order state to 'draft' and cancel |
||||
|
reservation stock for product lines.""" |
||||
|
self.state = 'draft' |
||||
|
for line in self.order_line.filtered( |
||||
|
lambda line: line.product_id.type == 'product'): |
||||
|
line.cancel_reservation_stock(line.picking_id) |
||||
|
|
||||
|
def action_cancel_reservation(self): |
||||
|
""" Action method to cancel reservation stock for product lines and set |
||||
|
the order state to 'cancel'.""" |
||||
|
for line in self.order_line.filtered( |
||||
|
lambda line: line.product_id.type == 'product'): |
||||
|
line.cancel_reservation_stock(line.picking_id) |
||||
|
self.state = 'cancel' |
||||
|
|
||||
|
|
||||
|
class Company(models.Model): |
||||
|
""" This class extends the 'res.company' model in Odoo. |
||||
|
It adds a new field ('destination_location_id') to store the destination |
||||
|
location.""" |
||||
|
_inherit = 'res.company' |
||||
|
|
||||
|
destination_location_id = fields.Many2one( |
||||
|
'stock.location', |
||||
|
string='Destination Location', |
||||
|
help='The destination location for products.') |
||||
|
|
||||
|
|
||||
|
class AccountConfig(models.TransientModel): |
||||
|
""" This class extends the 'res.config.settings' model in Odoo. |
||||
|
It adds a related field ('destination_location_id') to configure the |
||||
|
destination location.""" |
||||
|
_inherit = "res.config.settings" |
||||
|
|
||||
|
destination_location_id = fields.Many2one( |
||||
|
'stock.location', |
||||
|
string='Destination Location', |
||||
|
related='company_id.destination_location_id', |
||||
|
readonly=False, |
||||
|
help='The destination location for products.') |
@ -0,0 +1,155 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Gayathri V (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# 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 (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from datetime import datetime |
||||
|
from odoo import fields, models |
||||
|
from odoo.tools import float_round |
||||
|
|
||||
|
|
||||
|
class SaleOrderLine(models.Model): |
||||
|
""" This class extends the 'sale.order.line' model in Odoo. |
||||
|
It adds functionality related to reservation stock for sale order lines.""" |
||||
|
_inherit = 'sale.order.line' |
||||
|
|
||||
|
picking_id = fields.Many2one('stock.picking', string='Picking', |
||||
|
help='The associated picking for the order ' |
||||
|
'line') |
||||
|
|
||||
|
def create_reservation_stock(self): |
||||
|
""" Create reservation stock for the product line.""" |
||||
|
picking_obj = self.env['stock.picking'] |
||||
|
destination_location_id = self.env.user.company_id.destination_location_id |
||||
|
if not destination_location_id: |
||||
|
destination_location_id = self.env['stock.location'].search( |
||||
|
[('usage', '=', 'internal'), |
||||
|
('company_id', '=', self.env.user.company_id.id)], limit=1) |
||||
|
warehouse_id = self.order_id.warehouse_id |
||||
|
location_id = warehouse_id.lot_stock_id |
||||
|
if self._context.get('product_id'): |
||||
|
product_id = self._context.get('product_id') |
||||
|
product_uom = product_id.uom_id |
||||
|
else: |
||||
|
product_id = self.product_id |
||||
|
product_uom = self.product_uom |
||||
|
if self._context.get('new_qty'): |
||||
|
product_uom_qty = self._context.get('new_qty') |
||||
|
else: |
||||
|
product_uom_qty = self.product_uom_qty |
||||
|
move_lines = [] |
||||
|
move_lines.append((0, 0, { |
||||
|
'name': product_id.name, |
||||
|
'product_id': product_id.id, |
||||
|
'product_uom_qty': product_uom_qty, |
||||
|
'quantity': product_uom_qty, |
||||
|
'product_uom': product_uom.id, |
||||
|
'location_id': location_id and location_id.id, |
||||
|
'location_dest_id': destination_location_id and destination_location_id.id, |
||||
|
})) |
||||
|
values = { |
||||
|
'partner_id': self.order_id.partner_id.id, |
||||
|
'location_id': location_id and location_id.id, |
||||
|
'location_dest_id': destination_location_id and destination_location_id.id, |
||||
|
'scheduled_date': datetime.now(), |
||||
|
'date_done': datetime.now(), |
||||
|
'origin': self.order_id.name, |
||||
|
'owner_id': self.order_id.partner_id.id, |
||||
|
'picking_type_id': self.env.ref('stock.picking_type_out').id, |
||||
|
'move_ids_without_package': move_lines, |
||||
|
} |
||||
|
picking = picking_obj.sudo().create(values) |
||||
|
picking.sudo().action_confirm() |
||||
|
picking.sudo().action_assign() |
||||
|
picking.sudo().button_validate() |
||||
|
sms = self.env['confirm.stock.sms'].sudo().search([]) |
||||
|
for rec in sms: |
||||
|
for pick in rec.pick_ids: |
||||
|
if pick.id == picking.id: |
||||
|
rec.send_sms() |
||||
|
picking.sudo().button_validate() |
||||
|
|
||||
|
self.write({ |
||||
|
'picking_id': picking.id |
||||
|
}) |
||||
|
|
||||
|
def cancel_reservation_stock(self, picking_ids): |
||||
|
""" Cancel reservation stock for the given picking IDs.""" |
||||
|
product_return_moves = [] |
||||
|
for picking in picking_ids: |
||||
|
if picking.products_availability_state == "late": |
||||
|
return picking.action_cancel() |
||||
|
else: |
||||
|
for move in picking.move_ids: |
||||
|
if move.move_dest_ids: |
||||
|
quantity = move.product_qty - sum( |
||||
|
move.sudo().filtered( |
||||
|
lambda m: m.state in [ |
||||
|
'partially_available', 'assigned', |
||||
|
'done']).mapped('move_line_ids').mapped( |
||||
|
'qty_done')) |
||||
|
else: |
||||
|
quantity = move.product_qty |
||||
|
quantity = float_round(quantity, |
||||
|
precision_rounding=move.product_uom.rounding) |
||||
|
product_return_moves.append((0, 0, { |
||||
|
'product_id': move.product_id.id, |
||||
|
'quantity': quantity, |
||||
|
'move_id': move.id, |
||||
|
'uom_id': move.product_id.uom_id.id, |
||||
|
'to_refund': True, |
||||
|
})) |
||||
|
location_id = picking.location_id.id |
||||
|
if picking.picking_type_id.return_picking_type_id\ |
||||
|
.default_location_dest_id.return_location: |
||||
|
location_id = picking.picking_type_id\ |
||||
|
.return_picking_type_id.default_location_dest_id.id |
||||
|
stock_return = self.env['stock.return.picking'].sudo().create({ |
||||
|
'product_return_moves': product_return_moves, |
||||
|
'picking_id': picking.id, |
||||
|
'original_location_id': picking.location_id.id, |
||||
|
'parent_location_id': picking.picking_type_id.warehouse_id and picking.picking_type_id.warehouse_id.view_location_id.id or picking.location_id.location_id.id, |
||||
|
'location_id': location_id |
||||
|
}) |
||||
|
if stock_return: |
||||
|
new_picking_id, pick_type_id = stock_return.sudo()._create_returns() |
||||
|
new_picking = self.env['stock.picking'].sudo().browse( |
||||
|
new_picking_id) |
||||
|
if new_picking.mapped('move_line_ids').filtered( |
||||
|
lambda move: move.state in ['confirmed', |
||||
|
'waiting']): |
||||
|
new_picking.sudo().action_confirm() |
||||
|
new_picking.sudo().action_assign() |
||||
|
# new_picking.sudo().action_set_quantities_to_reservation() |
||||
|
new_picking.sudo().button_validate() |
||||
|
else: |
||||
|
new_picking.sudo().action_confirm() |
||||
|
new_picking.sudo().action_assign() |
||||
|
# new_picking.sudo().action_set_quantities_to_reservation() |
||||
|
new_picking.sudo().button_validate() |
||||
|
|
||||
|
def unlink(self): |
||||
|
""" Override unlink method to cancel reservation stock when deleting |
||||
|
product lines in draft reservation orders.""" |
||||
|
for line in self: |
||||
|
order_id = line.order_id |
||||
|
if order_id.state == 'draft' and order_id.type_name == 'Reservation': |
||||
|
if line.picking_id: |
||||
|
line.sudo().cancel_reservation_stock(line.picking_id) |
||||
|
return super(SaleOrderLine, self).unlink() |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 628 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 495 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 624 B |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 195 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 600 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 926 B |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 80 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 589 B |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 565 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 967 B |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 43 KiB |