Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] pos_stock_available_online: stock move updates #1250

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pos_stock_available_online/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from . import pos_config
from . import pos_session
from . import res_config_settings
from . import stock_notifier_pos_mixin
from . import stock_quant
from . import stock_warehouse
from . import stock_move
30 changes: 30 additions & 0 deletions pos_stock_available_online/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from odoo import models


class StockMove(models.Model):
_name = "stock.move"
_inherit = ["stock.move", "stock.notifier.pos.mixin"]

def write(self, vals):
states_dict = {line.id: line.state for line in self} if "state" in vals else {}
res = super().write(vals)

Check warning on line 10 in pos_stock_available_online/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_move.py#L10

Added line #L10 was not covered by tests
if not states_dict:
return res

Check warning on line 12 in pos_stock_available_online/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_move.py#L12

Added line #L12 was not covered by tests
for line in self:
if states_dict.get(line.id) != line.state:
line._notify_pos()
return res

Check warning on line 16 in pos_stock_available_online/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_move.py#L15-L16

Added lines #L15 - L16 were not covered by tests

def _action_done(self, cancel_backorder=False):
# As stock will be updated once move has updated its state, skip
# notification from quant
return super(

Check warning on line 21 in pos_stock_available_online/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_move.py#L21

Added line #L21 was not covered by tests
StockMove, self.with_context(skip_quant_notify_pos=True)
)._action_done(cancel_backorder=cancel_backorder)

def _get_warehouses_to_notify(self):
warehouses = super()._get_warehouses_to_notify()
warehouses |= self.warehouse_id
warehouses |= self.location_id.warehouse_id
warehouses |= self.location_dest_id.warehouse_id
return warehouses

Check warning on line 30 in pos_stock_available_online/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_move.py#L26-L30

Added lines #L26 - L30 were not covered by tests
51 changes: 51 additions & 0 deletions pos_stock_available_online/models/stock_notifier_pos_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from odoo import models


class StockNotifierPosMixin(models.AbstractModel):
_name = "stock.notifier.pos.mixin"
_description = "Stock Notifier POS Mixin"

def _prepare_pos_message(self):
"""
Return prepared message to send to POS
"""
self.ensure_one()
return self.warehouse_id._prepare_vals_for_pos(self.product_id)

Check warning on line 13 in pos_stock_available_online/models/stock_notifier_pos_mixin.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_notifier_pos_mixin.py#L12-L13

Added lines #L12 - L13 were not covered by tests

def _skip_notify_pos(self):
"""
Skip notification to POS
"""
return False

Check warning on line 19 in pos_stock_available_online/models/stock_notifier_pos_mixin.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_notifier_pos_mixin.py#L19

Added line #L19 was not covered by tests

def _get_warehouses_to_notify(self):
self.ensure_one()
return self.env["stock.warehouse"]

Check warning on line 23 in pos_stock_available_online/models/stock_notifier_pos_mixin.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_notifier_pos_mixin.py#L22-L23

Added lines #L22 - L23 were not covered by tests

def _notify_pos(self):
"""
Send notification to POS
"""
pos_session_obj = self.env["pos.session"]

Check warning on line 29 in pos_stock_available_online/models/stock_notifier_pos_mixin.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_notifier_pos_mixin.py#L29

Added line #L29 was not covered by tests
for record in self:
if record._skip_notify_pos():
continue

Check warning on line 32 in pos_stock_available_online/models/stock_notifier_pos_mixin.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_notifier_pos_mixin.py#L32

Added line #L32 was not covered by tests
for warehouse in self._get_warehouses_to_notify():
configs = pos_session_obj.search(

Check warning on line 34 in pos_stock_available_online/models/stock_notifier_pos_mixin.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_notifier_pos_mixin.py#L34

Added line #L34 was not covered by tests
[
("state", "=", "opened"),
("config_id.display_product_quantity", "=", True),
"|",
("config_id.additional_warehouse_ids", "in", [warehouse.id]),
("config_id.main_warehouse_id", "=", warehouse.id),
"|",
("config_id.iface_available_categ_ids", "=", False),
(
"config_id.iface_available_categ_ids",
"in",
[record.product_id.pos_categ_id.id],
),
],
).mapped("config_id")
if configs:
configs._notify_available_quantity(record._prepare_pos_message())

Check warning on line 51 in pos_stock_available_online/models/stock_notifier_pos_mixin.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_notifier_pos_mixin.py#L51

Added line #L51 was not covered by tests
52 changes: 14 additions & 38 deletions pos_stock_available_online/models/stock_quant.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,23 @@
import logging

from odoo import models

_logger = logging.getLogger(__name__)


class StockQuant(models.Model):
_inherit = "stock.quant"

def _prepare_pos_message(self):
"""
Return prepared message to send to POS
"""
self.ensure_one()
return self.warehouse_id._prepare_vals_for_pos(self.product_id)

def _notify_pos(self):
"""
Send notification to POS
"""
pos_session_obj = self.env["pos.session"]
for quant in self:
warehouse_id = quant.warehouse_id.id
configs = pos_session_obj.search(
[
("state", "=", "opened"),
("config_id.display_product_quantity", "=", True),
"|",
("config_id.additional_warehouse_ids", "in", [warehouse_id]),
("config_id.main_warehouse_id", "=", warehouse_id),
"|",
("config_id.iface_available_categ_ids", "=", False),
(
"config_id.iface_available_categ_ids",
"in",
[quant.product_id.pos_categ_id.id],
),
],
).mapped("config_id")
if configs:
configs._notify_available_quantity(quant._prepare_pos_message())
_name = "stock.quant"
_inherit = ["stock.quant", "stock.notifier.pos.mixin"]

def write(self, vals):
res = super().write(vals)
self._notify_pos()
return res

def _skip_notify_pos(self):
self.ensure_one()
return (

Check warning on line 15 in pos_stock_available_online/models/stock_quant.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_quant.py#L14-L15

Added lines #L14 - L15 were not covered by tests
self.env.context.get("skip_quant_notify_pos", False)
or super()._skip_notify_pos()
)

def _get_warehouses_to_notify(self):
warehouses = super()._get_warehouses_to_notify()
warehouses |= self.warehouse_id
return warehouses

Check warning on line 23 in pos_stock_available_online/models/stock_quant.py

View check run for this annotation

Codecov / codecov/patch

pos_stock_available_online/models/stock_quant.py#L21-L23

Added lines #L21 - L23 were not covered by tests
Loading