Skip to content
Closed
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 bees_custom/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"name": "BEES Customizations",
"version": "12.0.1.0.1",
"depends": [
"mail",
"beesdoo_account",
"beesdoo_product_info_screen",
"pos_mail_receipt",
Expand All @@ -17,6 +18,7 @@
Specifics customizations for BEES coop.
""",
"data": [
"data/mail_template.xml",
"views/account_invoice.xml",
"views/products.xml",
],
Expand Down
52 changes: 52 additions & 0 deletions bees_custom/data/mail_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Mail template are declared in a NOUPDATE block
so users can freely customize/delete them -->
<data noupdate="0">
<record id="mail_template_incorrect_delivery" model="mail.template">
<field name="name">Incorrect Delivery</field>
<field name="email_from">
${ctx.get('company').email|safe}
</field>
<field name="subject">Incorrect Delivery (${object.name})</field>
<field name="partner_to">${ctx.get('company').email|safe}</field>
<field name="model_id" ref="model_stock_picking" />
<field name="auto_delete" eval="True" />
<field name="lang">${ctx.get("lang")}</field>
<field name="body_html" type="html">
<div>
<p>One or several products in <a href="${object.form_view_url}">${object.name}</a> were received in incorrect amounts.</p>

% if object.zero_received_move_ids:
<p>Zero received:</p>
<ul>
% for move in object.zero_received_move_ids:
<li>${move.name} --- Received ${move.quantity_done} out of expected ${move.product_qty}</li>
% endfor
</ul>
% endif

% if object.too_few_received_move_ids:
<p>Received too few:</p>
<ul>
% for move in object.too_few_received_move_ids:
<li>${move.name} --- Received ${move.quantity_done} out of expected ${move.product_qty}</li>
% endfor
</ul>
% endif

% if object.too_many_received_move_ids:
<p>Received too many:</p>
<ul>
% for move in object.too_many_received_move_ids:
<li>${move.name} --- Received ${move.quantity_done} out of expected ${move.product_qty}</li>
% endfor
</ul>
% endif

<p>Please follow up accordingly.</p>
</div>
</field>
</record>
</data>
</odoo>
1 change: 1 addition & 0 deletions bees_custom/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import account_invoice
from . import product_template
from . import pos_order
from . import stock_picking
96 changes: 96 additions & 0 deletions bees_custom/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright 2021 Coop IT Easy SCRL fs
# Carmen Bianca Bakker <[email protected]>
# 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"]
)
1 change: 1 addition & 0 deletions bees_custom/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* Robin Keunen <[email protected]>
* Houssine Bakkali <[email protected]>
* Carmen Bianca Bakker <[email protected]>