Skip to content

Commit

Permalink
Cherry pick of 224a545
Browse files Browse the repository at this point in the history
closes #1121

Signed-off-by: matiasperalta1 <[email protected]>
Signed-off-by: Franco Leyes <[email protected]>
  • Loading branch information
lef-adhoc committed Feb 6, 2025
1 parent 61f13dc commit 2eddcf6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 64 deletions.
76 changes: 32 additions & 44 deletions sale_order_type_automation/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
import logging

from odoo import _, models
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)


class SaleOrder(models.Model):
_inherit = "sale.order"
Expand Down Expand Up @@ -48,61 +44,53 @@ def run_invoicing_atomation(self):
invoices.message_post(body=message)
rec.message_post(body=message)

def run_picking_atomation(self):
def run_picking_automation(self):
# If there products are the type 'service' equals the
# delivered qyt to order qty for this sale order line
for order_lines in self.mapped("order_line").filtered(
for order_line in self.mapped("order_line").filtered(
lambda x: x.order_id.type_id.picking_atomation != "none"
and x.product_id.type == "service"
and x.product_id.service_type == "manual"
and x.product_id.expense_policy == "no"
):
order_lines.qty_delivered = order_lines.product_uom_qty
order_line.qty_delivered = order_line.product_uom_qty
for rec in self.filtered(lambda x: x.type_id.picking_atomation != "none" and x.procurement_group_id):
jit_installed = self.env["ir.module.module"].search(
[("name", "=", "procurement_jit"), ("state", "=", "installed")], limit=1
)
stock_voucher_installed = self.env["ir.module.module"].search(
[("name", "=", "stock_voucher"), ("state", "=", "installed")], limit=1
)
# we add invalidate because on boggio we have add an option
# for tracking_disable and with that setup pickings where not seen
# rec.invalidate_cache()
pickings = rec.picking_ids.filtered(lambda x: x.state not in ("done", "cancel"))
if not jit_installed:
pickings.action_assign()
# ordenamos primeros los pickings asignados y luego el resto
assigned_pickings = pickings.filtered(lambda x: x.state == "assigned")
pickings = assigned_pickings + (pickings - assigned_pickings)
for pick in pickings:
if rec.type_id.picking_atomation == "validate":
# this method already call action_assign
pick.new_force_availability()
elif rec.type_id.picking_atomation == "validate_no_force":
products = []
for move in pick.mapped("move_ids"):
if move.state != "assigned":
products.append(move.product_id)
if products:
raise UserError(
_(
"The following products are not available, we "
"suggest to check stock or to use a sale type that"
"force availability.\nProducts:\n* %s\n"
)
% ("\n * ".join(x.name for x in products))
rec._process_pickings()
return True

def _process_pickings(self):
self.ensure_one()
pickings = self.picking_ids.filtered(lambda x: x.state not in ("done", "cancel"))
pickings.action_assign()
products = []
for pick in pickings:
if self.type_id.picking_atomation == "validate":
pick.new_force_availability()
elif self.type_id.picking_atomation == "validate_no_force":
products.extend(move.product_id for move in pick.move_ids if move.state != "assigned")
if products:
raise UserError(
_(
"The following products are not available, we "
"suggest to check stock or to use a sale type that"
"force availability.\nProducts:\n* %s\n"
)
for op in pick.mapped("move_line_ids"):
op.quantity = op.quantity_product_uom
if not stock_voucher_installed:
pick.button_validate()
% "\n* ".join(x.name for x in products)
)

for op in pick.move_line_ids:
op.quantity = op.quantity_product_uom

pick.button_validate()
if self.picking_ids.filtered(lambda x: x.state not in ("done", "cancel")):
self._process_pickings()

def action_confirm(self):
res = super().action_confirm()
# we use this because compatibility with sale exception module
if isinstance(res, bool) and res:
# because it's needed to return actions if exists
self.run_picking_atomation()
res = self.run_picking_automation()
self.sudo().run_invoicing_atomation()
if self.type_id.set_done_on_confirmation:
self.action_lock()
Expand Down
6 changes: 3 additions & 3 deletions sale_order_type_automation_stock_voucher/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

=================================================
Website Sale Hide All Prices Product Configurator
=================================================
========================================
Sale Order Type Automation Stock Voucher
========================================

This module integrate Sale Order Type Automation and Stock Voucher.

Expand Down
34 changes: 17 additions & 17 deletions sale_order_type_automation_stock_voucher/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
class SaleOrder(models.Model):
_inherit = "sale.order"

def assign_book_id(self):
for rec in self.filtered(lambda x: x.type_id.picking_atomation != "none" and x.procurement_group_id):
pickings = rec.picking_ids.filtered(lambda x: x.state not in ("done", "cancel"))
if rec.type_id.book_id:
pickings.write({"book_id": rec.type_id.book_id.id})
for pick in pickings:
pick.button_validate()
if pickings.filtered("book_required"):
return pickings.do_print_voucher()
else:
return True
def _process_pickings(self):
if self.type_id.book_id:
pickings = self.picking_ids.filtered(lambda x: x.state not in ("done", "cancel"))
pickings.write({"book_id": self.type_id.book_id.id})
super()._process_pickings()

def action_confirm(self):
res = super().action_confirm()
# we use this because compatibility with sale exception module
if isinstance(res, bool) and res:
# because it's needed to return actions if exists
res = self.assign_book_id()
def run_picking_automation(self):
res = super().run_picking_automation()
pickings_book_required = self.picking_ids.filtered("book_required")
if pickings_book_required:
actions = [pick.do_print_voucher() for pick in pickings_book_required]
return {
"type": "ir.actions.client",
"tag": "do_multi_print",
"params": {
"reports": actions,
},
}
return res

0 comments on commit 2eddcf6

Please sign in to comment.