Initial commit: Sale packages

This commit is contained in:
Ernad Husremovic 2025-08-29 15:20:49 +02:00
commit 14e3d26998
6469 changed files with 2479670 additions and 0 deletions

View file

@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import website
from . import res_config_settings
from . import payment_provider
from . import delivery_carrier

View file

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields, _, api
from odoo.exceptions import ValidationError
class DeliveryCarrier(models.Model):
_inherit = 'delivery.carrier'
# Onsite delivery means the client comes to a physical store to get the products himself.
delivery_type = fields.Selection(selection_add=[
('onsite', 'Pickup in store')
], ondelete={'onsite': 'set default'})
# If set, the sales order shipping address will take this warehouse's address.
warehouse_id = fields.Many2one('stock.warehouse', 'Warehouse')
@api.constrains('warehouse_id', 'company_id')
def _check_warehouse_company(self):
for carrier in self:
if carrier.warehouse_id.company_id and carrier.company_id and carrier.company_id != carrier.warehouse_id.company_id:
raise ValidationError(_("The picking site and warehouse must share the same company"))
def onsite_rate_shipment(self, order):
"""
Required to show the price on the checkout page for the onsite delivery type
"""
return {
'success': True,
'price': self.product_id.list_price,
'error_message': False,
'warning_message': False
}
def onsite_send_shipping(self, pickings):
return [{
'exact_price': p.carrier_id.fixed_price,
'tracking_number': False
} for p in pickings]
def onsite_cancel_shipment(self, pickings):
pass # No need to communicate to an external service, however the method must exist so that cancel_shipment() works.

View file

@ -0,0 +1,44 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class PaymentProvider(models.Model):
_inherit = 'payment.provider'
custom_mode = fields.Selection(
selection_add=[('onsite', "On Site")]
)
@api.model
def _get_compatible_providers(self, *args, sale_order_id=None, website_id=None, **kwargs):
""" Override of payment to exclude onsite providers if the delivery doesn't match.
:param int sale_order_id: The sale order to be paid, if any, as a `sale.order` id
:param int website_id: The provided website, as a `website` id
:return: The compatible providers
:rtype: recordset of `payment.provider`
"""
compatible_providers = super()._get_compatible_providers(
*args, sale_order_id=sale_order_id, website_id=website_id, **kwargs)
# Show on site picking only if delivery carriers onsite exists
onsite_carriers = self.env['delivery.carrier'].search([
('website_published', '=', True),
('delivery_type', '=', 'onsite'),
'|',
('website_id', '=?', website_id),
('website_id', '=', False)
])
order = self.env['sale.order'].browse(sale_order_id).exists()
# Show onsite providers only if onsite carriers exists
# and the order contains physical products
if not onsite_carriers or not any(
product.type in ('consu', 'product')
for product in order.order_line.product_id
):
compatible_providers = compatible_providers.filtered(
lambda p: p.code != 'custom' or p.custom_mode != 'onsite'
)
return compatible_providers

View file

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
picking_site_ids = fields.Many2many(
'delivery.carrier',
related='website_id.picking_site_ids',
readonly=False,
)

View file

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class Website(models.Model):
_inherit = 'website'
picking_site_ids = fields.Many2many('delivery.carrier', string='Picking sites',
compute='_compute_picking_sites')
def _compute_picking_sites(self):
delivery_carriers = self.env['delivery.carrier'].search([('delivery_type', '=', 'onsite')])
for website in self:
website.picking_site_ids = delivery_carriers.filtered_domain([('website_id.id', '=', website.id)])