| 1 |
|
| 2 |
|
| 3 |
from odoo import fields, models |
| 4 |
|
| 5 |
|
| 6 |
class Website(models.Model): |
| 7 |
_inherit = 'website' |
| 8 |
|
| 9 |
in_store_dm_id = fields.Many2one( |
| 10 |
string="In-store Delivery Method", |
| 11 |
comodel_name='delivery.carrier', |
| 12 |
compute='_compute_in_store_dm_id', |
| 13 |
) |
| 14 |
|
| 15 |
def _compute_in_store_dm_id(self): |
| 16 |
in_store_delivery_methods = self.env['delivery.carrier'].search( |
| 17 |
[('delivery_type', '=', 'in_store'), ('is_published', '=', True)] |
| 18 |
) |
| 19 |
for website in self: |
| 20 |
website.in_store_dm_id = in_store_delivery_methods.filtered_domain([ |
| 21 |
'|', ('website_id', '=', False), ('website_id', '=', website.id), |
| 22 |
'|', ('company_id', '=', False), ('company_id', '=', website.company_id.id), |
| 23 |
])[:1] |
| 24 |
|
| 25 |
def _get_product_available_qty(self, product, **kwargs): |
| 26 |
""" Override of `website_sale_stock` to include free quantities of the product in warehouses |
| 27 |
of in-store delivery method and return maximum possible for one order. Needed only if a |
| 28 |
warehouse is set on website, otherwise free quantity is already calculated from all |
| 29 |
warehouses.""" |
| 30 |
free_qty = super()._get_product_available_qty(product, **kwargs) |
| 31 |
if self.warehouse_id and self.sudo().in_store_dm_id: |
| 32 |
|
| 33 |
free_qty = max(free_qty, self._get_max_in_store_product_available_qty(product)) |
| 34 |
return free_qty |
| 35 |
|
| 36 |
def _get_max_in_store_product_available_qty(self, product): |
| 37 |
""" Return maximum amount of product available to deliver with in store delivery method. """ |
| 38 |
return max([ |
| 39 |
product.with_context(warehouse_id=wh.id).free_qty |
| 40 |
for wh in self.sudo().in_store_dm_id.warehouse_ids |
| 41 |
], default=0) |