Skip to content

Commit

Permalink
temp rebasing PR 427 (31c2d30)
Browse files Browse the repository at this point in the history
  • Loading branch information
roboadhoc committed Jan 29, 2024
2 parents 5619825 + 31c2d30 commit cd902cb
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 87 deletions.
41 changes: 24 additions & 17 deletions stock_orderpoint_manual_update/models/stock_orderpoint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import models, fields
from odoo import models, fields, api


class StockWarehouseOrderpoint(models.Model):
Expand All @@ -9,33 +9,40 @@ class StockWarehouseOrderpoint(models.Model):
string="Previsión",
)

def _get_orderpoint_action(self):
action = super()._get_orderpoint_action()
self.update_qty_forecast()
return action
def update_qty_forecast(self):
for rec in self:
rec.qty_forecast_stored = rec.qty_forecast

def _get_orderpoint_products(self):
domain = [('type', '=', 'product'), ('stock_move_ids', '!=', False)]

# Filter by suppliers
suppliers_ids = self._context.get('suppliers')
suppliers = self.env['product.supplierinfo'].browse(suppliers_ids)
if suppliers:
domain += ['|', ('product_tmpl_id', 'in', suppliers.product_tmpl_id.ids), ('id', 'in', suppliers.product_id.ids)]
suppliers_ids = self._context.get('filter_suppliers')
if suppliers_ids:
domain.append(('seller_ids.partner_id', 'in', suppliers_ids))

# Filter by product categories
category_ids = self._context.get('categories')
category_ids = self._context.get('filter_categories')
if category_ids:
domain += [('categ_id', 'in', category_ids)]
domain.append(('categ_id', 'in', category_ids))

# Filter by products
product_ids = self._context.get('products')
product_ids = self._context.get('filter_products')
if product_ids:
domain += [('id', 'in', product_ids)]
domain.append(('id', 'in', product_ids))

return self.env['product.product'].search(domain)

def update_qty_forecast(self):
orderpoints = self.with_context(active_test=False).search([])
for rec in orderpoints:
rec.qty_forecast_stored = rec.qty_forecast


class StockLocation(models.Model):
_inherit = "stock.location"

# Heredamos método search para filtrar las ubicaciones que se usan en _get_orderpoint_action().
# TODO: mejorar si Odoo mezcla PR: https://github.com/odoo/odoo/pull/150256
@api.model
def search(self, domain, offset=0, limit=None, order=None, count=False):
location_ids = self._context.get('filter_locations')
if location_ids:
domain.append(('id', 'in', location_ids))
return super().search(domain, offset=offset, limit=limit, order=order, count=count)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,6 @@ patch(StockOrderpointListController.prototype, "order patch", {
if (action) {
await this.actionService.doAction(action);
}
return this.actionService.doAction('stock.action_orderpoint_replenish', {
stackPosition: 'replaceCurrentAction',
});
}
});

patch(StockOrderpointListController.prototype, "recompute patch", {
async onClickRecomputeOrderpoint() {
return this.actionService.doAction('stock_orderpoint_manual_update.action_stock_warehouse_orderpoint_wizard');
}
});

patch(StockOrderpointListController.prototype, "forecast patch", {
async onClickUpdateForecast() {
const resIds = await this.getSelectedResIds();
await this.model.orm.call(this.props.resModel, "update_qty_forecast", [resIds], {
context: this.props.context,
});
return this.actionService.doAction('stock.action_orderpoint_replenish', {
stackPosition: 'replaceCurrentAction',
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@
</field>
</record>

<record id="stock.action_orderpoint_replenish" model="ir.actions.act_window">
<field name="context">{'search_default_filter_to_reorder': 1, 'search_default_filter_not_snoozed': 1}</field>
</record>

<menuitem
id="stock.menu_reordering_rules_replenish"
action="stock_orderpoint_manual_update.action_stock_warehouse_orderpoint_wizard"
name="Replenishment" parent="stock.menu_stock_warehouse_mgmt" sequence="5"
groups="stock.group_stock_manager"/>

</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,35 @@ class StockWarehouseOrderpointWizard(models.TransientModel):
_description = 'Stock Warehouse Orderpoint Wizard'

company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company)
partner_ids = fields.Many2many('res.partner', string='Vendor', check_company=True)
category_ids = fields.Many2many('product.category', string='Product Category')
product_ids = fields.Many2many('product.product', string='Product')
category_ids = fields.Many2many('product.category', string='Product Category')
supplier_ids = fields.Many2many('res.partner', string='Vendor', check_company=True)
location_ids = fields.Many2many('stock.location', string="Location")

def action_confirm(self):
ctx = self._context.copy()
suppliers = self.env['product.supplierinfo'].search([('partner_id', 'in', self.partner_ids.ids)])
ctx.update({
'suppliers': suppliers.ids,
'categories': self.category_ids.ids,
'products': self.product_ids.ids,
'filter_products': self.product_ids.ids,
'filter_categories': self.category_ids.ids,
'filter_suppliers': self.supplier_ids.ids,
'filter_locations': self.location_ids.ids,
})
self = self.with_context(ctx)
action = self.env['stock.warehouse.orderpoint']._get_orderpoint_action()
action = self.with_context(ctx).env['stock.warehouse.orderpoint']._get_orderpoint_action()
orderpoint_domain = self._get_orderpoint_domain()
orderpoints = self.env['stock.warehouse.orderpoint'].search(orderpoint_domain)
orderpoints._compute_qty_to_order()
orderpoints.update_qty_forecast()
action['domain'] = orderpoint_domain
return action

def _get_orderpoint_domain(self):
orderpoint_domain = []
if self.product_ids:
orderpoint_domain.append(('product_id', 'in', self.product_ids.ids))
if self.category_ids:
orderpoint_domain.append(('product_category_id', 'in', self.category_ids.ids))
if self.supplier_ids:
orderpoint_domain.append(('product_id.seller_ids.partner_id', 'in', self.supplier_ids.ids))
if self.location_ids:
orderpoint_domain.append(('location_id', 'in', self.location_ids.ids))
return orderpoint_domain
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
<field name="model">stock.warehouse.orderpoint.wizard</field>
<field name="arch" type="xml">
<form string="Replenishment Filter Wizard">
<div colspan="2" class="alert alert-info" role="status" attrs="{'invisible': [('partner_ids','=', []), ('category_ids','=', []), ('product_ids','=', [])]}">
<div colspan="2" class="alert alert-info" role="status" attrs="{'invisible': [('category_ids','=', []), ('product_ids','=', []), ('supplier_ids','=', []), ('location_ids','=', [])]}">
<p><i class="fa fa-info-circle"/>This action will create replenishment lines for products that matches this criteria.</p>
</div>
<group>
<group col="2">
<field name="company_id" invisible="1"/>
<field name="partner_ids" widget="many2many_tags" context="{'res_partner_search_mode': 'supplier'}"></field>
<field name="category_ids" widget="many2many_tags"/>
<field name="product_ids" widget="many2many_tags"/>
</group>
<group col="2">
<field name="category_ids" widget="many2many_tags"/>
<field name="supplier_ids" widget="many2many_tags" context="{'res_partner_search_mode': 'supplier'}"></field>
<field name="location_ids" widget="many2many_tags"/>
</group>
</group>
<footer>
<button string="Send" name="action_confirm" type="object" class="btn-primary" data-hotkey="q"/>
<button string="Confirm" name="action_confirm" type="object" class="btn-primary" data-hotkey="q"/>
<button string="Cancel" class="btn-secondary" special="cancel" data-hotkey="z"/>
</footer>
</form>
Expand All @@ -37,25 +38,4 @@
<field name="target">new</field>
</record>

<record id="cron_create_orderpoints" model="ir.cron">
<field name="name">Replenishment: create new lines</field>
<field name="model_id" ref="stock.model_stock_warehouse_orderpoint"/>
<field name="state">code</field>
<field name="code">model._get_orderpoint_action()</field>
<field name="active" eval="True"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
</record>

<record id="stock.action_orderpoint_replenish" model="ir.actions.act_window">
<field name="context">{'search_default_filter_to_reorder': 1, 'search_default_filter_not_snoozed': 1}</field>
</record>

<menuitem
id="stock.menu_reordering_rules_replenish"
action="stock.action_orderpoint_replenish"
name="Replenishment" parent="stock.menu_stock_warehouse_mgmt" sequence="5"
groups="stock.group_stock_manager"/>

</odoo>

0 comments on commit cd902cb

Please sign in to comment.