mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[MIG] sale_planner: to 16
This commit is contained in:
@@ -358,7 +358,7 @@ class TestPlanner(common.TransactionCase):
|
||||
self.assertTrue(planner.planning_option_ids.sub_options)
|
||||
|
||||
sub_options = json_decode(planner.planning_option_ids.sub_options)
|
||||
_logger.error(sub_options)
|
||||
_logger.warning(sub_options)
|
||||
wh_1_ids = sorted([self.product_both.id, self.product_1.id, self.product_12.id])
|
||||
wh_2_ids = sorted([self.product_2.id, self.product_22.id])
|
||||
self.assertEqual(sorted(sub_options[str(self.warehouse_1.id)]['product_ids']), wh_1_ids)
|
||||
@@ -407,7 +407,7 @@ class TestPlanner(common.TransactionCase):
|
||||
self.assertTrue(planner.planning_option_ids.sub_options)
|
||||
|
||||
sub_options = json_decode(planner.planning_option_ids.sub_options)
|
||||
_logger.error(sub_options)
|
||||
_logger.warning(sub_options)
|
||||
wh_1_ids = sorted([self.product_1.id, self.product_12.id])
|
||||
wh_2_ids = sorted([self.product_both.id, self.product_2.id, self.product_22.id])
|
||||
self.assertEqual(sorted(sub_options[str(self.warehouse_1.id)]['product_ids']), wh_1_ids)
|
||||
@@ -457,7 +457,7 @@ class TestPlanner(common.TransactionCase):
|
||||
self.assertTrue(planner.planning_option_ids.sub_options)
|
||||
|
||||
sub_options = json_decode(planner.planning_option_ids.sub_options)
|
||||
_logger.error(sub_options)
|
||||
_logger.warning(sub_options)
|
||||
wh_1_ids = sorted([self.product_1.id, self.product_12.id])
|
||||
wh_2_ids = sorted([self.product_both.id, self.product_2.id, self.product_22.id])
|
||||
self.assertEqual(sorted(sub_options[str(self.warehouse_1.id)]['product_ids']), wh_1_ids)
|
||||
|
||||
@@ -399,9 +399,9 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
#order_fake.warehouse_id = warehouse
|
||||
return {'warehouse_id': warehouse.id, 'date_planned': date_planned}
|
||||
|
||||
_logger.error(' partial_candidates: ' + str(partial_candidates))
|
||||
_logger.warning(' partial_candidates: ' + str(partial_candidates))
|
||||
if partial_candidates:
|
||||
_logger.error(' using...')
|
||||
_logger.warning(' using...')
|
||||
if len(partial_candidates) == 1:
|
||||
warehouse = warehouses.filtered(lambda wh: wh.id in partial_candidates)
|
||||
#order_fake.warehouse_id = warehouse
|
||||
@@ -409,17 +409,17 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
|
||||
sorted_warehouses = self._sort_warehouses_by_partner(
|
||||
warehouses.filtered(lambda wh: wh.id in partial_candidates), order_fake.partner_shipping_id)
|
||||
_logger.error(' sorted_warehouses: ' + str(sorted_warehouses) + ' warehouses: ' + str(warehouses))
|
||||
_logger.warning(' sorted_warehouses: ' + str(sorted_warehouses) + ' warehouses: ' + str(warehouses))
|
||||
primary_wh = sorted_warehouses[0] # partial_candidates means there is at least one warehouse
|
||||
primary_wh_date_planned = self._next_warehouse_shipping_date(primary_wh)
|
||||
wh_date_planning[primary_wh.id] = primary_wh_date_planned
|
||||
for wh in sorted_warehouses:
|
||||
_logger.error(' wh: ' + str(wh) + ' buy_qty: ' + str(policy_group['buy_qty']))
|
||||
_logger.warning(' wh: ' + str(wh) + ' buy_qty: ' + str(policy_group['buy_qty']))
|
||||
if not policy_group['buy_qty']:
|
||||
continue
|
||||
stock = product_stock[wh.id]
|
||||
for p_id, p_vals in stock.items():
|
||||
_logger.error(' p_id: ' + str(p_id) + ' p_vals: ' + str(p_vals))
|
||||
_logger.warning(' p_id: ' + str(p_id) + ' p_vals: ' + str(p_vals))
|
||||
if p_id in policy_group['buy_qty'] and self._is_in_stock(p_vals, policy_group['buy_qty'][p_id]):
|
||||
if wh.id not in sub_options:
|
||||
sub_options[wh.id] = {
|
||||
@@ -429,7 +429,7 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
}
|
||||
sub_options[wh.id]['product_ids'].append(p_id)
|
||||
sub_options[wh.id]['product_skus'].append(p_vals['sku'])
|
||||
_logger.error(' removing: ' + str(p_id))
|
||||
_logger.warning(' removing: ' + str(p_id))
|
||||
del policy_group['buy_qty'][p_id]
|
||||
|
||||
if not policy_group['buy_qty']:
|
||||
@@ -448,7 +448,7 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
return {'warehouse_id': primary_wh.id}
|
||||
|
||||
def generate_base_option(self, order_fake):
|
||||
_logger.error('generate_base_option:')
|
||||
_logger.warning('generate_base_option:')
|
||||
__start_date = datetime.now() - timedelta(days=30)
|
||||
product_lines = list(filter(lambda line: line.product_id.type == 'product', order_fake.order_line))
|
||||
if not product_lines:
|
||||
@@ -483,7 +483,7 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
option_policy_groups = defaultdict(lambda: {'products': self.env['product.product'].browse(), 'policies': self.env['sale.order.planning.policy'].browse(), 'date_planned': __start_date, 'sub_options': [],})
|
||||
for policy_id, policy_group in policy_groups.items():
|
||||
base_option = policy_group['base_option']
|
||||
_logger.error(' base_option: ' + str(base_option))
|
||||
_logger.warning(' base_option: ' + str(base_option))
|
||||
b_wh_id = base_option['warehouse_id']
|
||||
if 'policy' in policy_group:
|
||||
option_policy_groups[b_wh_id]['policies'] += policy_group['policy']
|
||||
@@ -529,8 +529,8 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
# Collapse warehouse options.
|
||||
base_option = {'date_planned': __start_date, 'products': self.env['product.product'].browse()}
|
||||
for wh_id, intermediate_option in option_policy_groups.items():
|
||||
_logger.error(' base_option: ' + str(base_option))
|
||||
_logger.error(' intermediate_option: ' + str(intermediate_option))
|
||||
_logger.warning(' base_option: ' + str(base_option))
|
||||
_logger.warning(' intermediate_option: ' + str(intermediate_option))
|
||||
if 'warehouse_id' not in base_option:
|
||||
base_option['warehouse_id'] = wh_id
|
||||
b_wh_id = base_option['warehouse_id']
|
||||
@@ -628,7 +628,7 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
base_option['sub_options'][o_wh_id]['date_planned'] = intermediate_option['date_planned']
|
||||
|
||||
del base_option['products']
|
||||
_logger.error(' returning: ' + str(base_option))
|
||||
_logger.warning(' returning: ' + str(base_option))
|
||||
order_fake.warehouse_id = self.get_warehouses(warehouse_id=base_option['warehouse_id'])
|
||||
return base_option
|
||||
|
||||
@@ -666,7 +666,7 @@ class SaleOrderMakePlan(models.TransientModel):
|
||||
def _fetch_product_stock(self, warehouses, products):
|
||||
output = {}
|
||||
for wh in warehouses:
|
||||
products.invalidate_cache(fnames=['qty_available', 'virtual_available', 'incoming_qty', 'outgoing_qty'],
|
||||
products._invalidate_cache(fnames=['qty_available', 'virtual_available', 'incoming_qty', 'outgoing_qty'],
|
||||
ids=products.ids)
|
||||
products = products.with_context({'location': wh.lot_stock_id.id})
|
||||
output[wh.id] = {
|
||||
|
||||
Reference in New Issue
Block a user