diff --git a/bees_custom/__manifest__.py b/bees_custom/__manifest__.py index 184d81b7..d9127b45 100644 --- a/bees_custom/__manifest__.py +++ b/bees_custom/__manifest__.py @@ -5,6 +5,7 @@ "name": "BEES Customizations", "version": "12.0.1.0.1", "depends": [ + "mail", "beesdoo_account", "beesdoo_product_info_screen", "pos_mail_receipt", @@ -17,6 +18,7 @@ Specifics customizations for BEES coop. """, "data": [ + "data/mail_template.xml", "views/account_invoice.xml", "views/products.xml", ], diff --git a/bees_custom/data/mail_template.xml b/bees_custom/data/mail_template.xml new file mode 100644 index 00000000..351eefa9 --- /dev/null +++ b/bees_custom/data/mail_template.xml @@ -0,0 +1,52 @@ + + + + + + Incorrect Delivery + + ${ctx.get('company').email|safe} + + Incorrect Delivery (${object.name}) + ${ctx.get('company').email|safe} + + + ${ctx.get("lang")} + +
+

One or several products in ${object.name} were received in incorrect amounts.

+ + % if object.zero_received_move_ids: +

Zero received:

+
    + % for move in object.zero_received_move_ids: +
  • ${move.name} --- Received ${move.quantity_done} out of expected ${move.product_qty}
  • + % endfor +
+ % endif + + % if object.too_few_received_move_ids: +

Received too few:

+
    + % for move in object.too_few_received_move_ids: +
  • ${move.name} --- Received ${move.quantity_done} out of expected ${move.product_qty}
  • + % endfor +
+ % endif + + % if object.too_many_received_move_ids: +

Received too many:

+
    + % for move in object.too_many_received_move_ids: +
  • ${move.name} --- Received ${move.quantity_done} out of expected ${move.product_qty}
  • + % endfor +
+ % endif + +

Please follow up accordingly.

+
+
+
+
+
diff --git a/bees_custom/models/__init__.py b/bees_custom/models/__init__.py index 0aafc173..93f20f3d 100644 --- a/bees_custom/models/__init__.py +++ b/bees_custom/models/__init__.py @@ -1,3 +1,4 @@ from . import account_invoice from . import product_template from . import pos_order +from . import stock_picking diff --git a/bees_custom/models/stock_picking.py b/bees_custom/models/stock_picking.py new file mode 100644 index 00000000..6104dbb5 --- /dev/null +++ b/bees_custom/models/stock_picking.py @@ -0,0 +1,96 @@ +# Copyright 2021 Coop IT Easy SCRL fs +# Carmen Bianca Bakker +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class Picking(models.Model): + _inherit = "stock.picking" + + zero_received_move_ids = fields.One2many( + "stock.move", + string="Stock moves that were not received", + compute="_compute_zero_received", + ) + too_few_received_move_ids = fields.One2many( + "stock.move", + string="Stock moves of which too few were received", + compute="_compute_too_few_received", + ) + too_many_received_move_ids = fields.One2many( + "stock.move", + string="Stock moves of which too many were received", + compute="_compute_too_many_received", + ) + + form_view_url = fields.Char( + string="Form View URL", compute="_compute_form_view_url" + ) + + @api.multi + @api.depends("move_lines") + def _compute_zero_received(self): + for pick in self: + pick.zero_received_move_ids = pick._filtered_moves().filtered( + lambda move: move.quantity_done == 0 and move.product_qty + ) + + @api.multi + @api.depends("move_lines") + def _compute_too_few_received(self): + for pick in self: + pick.too_few_received_move_ids = pick._filtered_moves().filtered( + lambda move: move.quantity_done < move.product_qty + ) + + @api.multi + @api.depends("move_lines") + def _compute_too_many_received(self): + for pick in self: + pick.too_many_received_move_ids = pick._filtered_moves().filtered( + lambda move: move.quantity_done > move.product_qty + ) + + @api.multi + def _compute_form_view_url(self): + for pick in self: + pick.form_view_url = ( + "{}/web#id={}&model=stock.picking&view_type=form".format( + pick.env["ir.config_parameter"].sudo().get_param("web.base.url"), + pick.id, + ) + ) + + @api.multi + def action_done(self): + self._notify_incorrect_delivery() + + return super(Picking, self).action_done() + + @api.multi + def _notify_incorrect_delivery(self): + """Send a notification e-mail about the incorrect delivery.""" + for pick in self: + if not any( + ( + pick.zero_received_move_ids, + pick.too_few_received_move_ids, + pick.too_many_received_move_ids, + ) + ): + # TODO: Handle this case. + continue + + self.env.ref("bees_custom.mail_template_incorrect_delivery").send_mail( + pick.id + ) + + return True + + @api.multi + def _filtered_moves(self): + return self.mapped("move_lines").filtered( + lambda move: move.state + in ["draft", "waiting", "partially_available", "assigned", "confirmed"] + ) diff --git a/bees_custom/readme/CONTRIBUTORS.rst b/bees_custom/readme/CONTRIBUTORS.rst index e90159c0..43ee7c9d 100644 --- a/bees_custom/readme/CONTRIBUTORS.rst +++ b/bees_custom/readme/CONTRIBUTORS.rst @@ -1,2 +1,3 @@ * Robin Keunen * Houssine Bakkali +* Carmen Bianca Bakker