Skip to content

Commit

Permalink
BAH-3762 | Show a warning pop up when the expiry of drugs is within 3…
Browse files Browse the repository at this point in the history
…0 days (#184)

* BAH-3762 | Add. Computed field to store whether the batch involved in stock_move_line is expiring soon

* BAH-3762 | Add. Show warning button and notification for move_lines with lot's expiry less than 30 days

* BAH-3762 | Refactor. Remove warning button from individual moves

* BAH-3852 | Add. Show warning button for near expiry stock moves in validation screen

* BAH-3852 | Add. Apply decoration warning only for moves which are not done

* BAH-3762 | Fix. Calculation of Unit Price for Markup rules
  • Loading branch information
mohan-13 authored Aug 7, 2024
1 parent ced9e0a commit 58a8236
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
35 changes: 32 additions & 3 deletions bahmni_stock/models/stock_move_line.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import datetime
from collections import defaultdict
from odoo import models, fields, api
from odoo import models, fields, api, _
from odoo.exceptions import UserError, ValidationError, AccessError, RedirectWarning


Expand All @@ -15,6 +15,8 @@ class StockMoveLine(models.Model):
existing_lot_id = fields.Many2one(
'stock.lot', 'Lot/Serial Number',
domain="[('product_id', '=', product_id), ('company_id', '=', company_id)]", check_company=True)
is_move_line_lot_expiring_soon = fields.Boolean(string="Is Lot Expiring Soon", readonly=True,
compute='is_lot_expiring_soon', default=False)

@api.onchange('product_id','qty_done')
def _onchange_balance_qty(self):
Expand Down Expand Up @@ -50,9 +52,10 @@ def default_get(self, fields):
move_ids = self.env['stock.move'].search([('picking_id', '=', res.get('picking_id')),('product_id', '=', res.get('product_id'))],limit=1)
associated_purchase_line = move_ids.purchase_line_id
if associated_purchase_line:
res.update({'mrp': associated_purchase_line.product_uom._compute_price(associated_purchase_line.mrp, self.product_uom_id)})
product_default_uom=self.env['product.product'].search([('id', '=', res.get('product_id'))],limit=1).product_tmpl_id.uom_id
res.update({'mrp': associated_purchase_line.product_uom._compute_price(associated_purchase_line.mrp, product_default_uom)})
total_cost_value = associated_purchase_line.price_unit + (associated_purchase_line.price_tax / associated_purchase_line.product_qty)
cost_value_per_unit = associated_purchase_line.product_uom._compute_price(total_cost_value, self.product_uom_id)
cost_value_per_unit = associated_purchase_line.product_uom._compute_price(total_cost_value, product_default_uom)
if cost_value_per_unit > 0.00:
res.update({'cost_price': cost_value_per_unit,
'sale_price': self.env['price.markup.table'].calculate_price_with_markup(cost_value_per_unit)
Expand All @@ -71,3 +74,29 @@ def _get_value_production_lot(self):
'mrp': self.mrp
})
return res

# Customisations to show warning when expiry of lot is within 30 days
@api.depends('expiration_date')
def is_lot_expiring_soon(self):
for line in self:
if line.expiration_date and self._compute_days_for_expiry(line.expiration_date) < 30:
line.is_move_line_lot_expiring_soon = True
else:
line.is_move_line_lot_expiring_soon = False

def _compute_days_for_expiry(self, expiration_date):
return (expiration_date.date() - fields.Date.context_today(self)).days

def move_line_warning(self):
notification = {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': _('Lot Expiry Warning'),
'type': 'warning',
'message': "Lot %s for %s expires in %s days" % (self.lot_id.name if self.lot_id else self.lot_name,
self.product_id.name,
self._compute_days_for_expiry(self.expiration_date))
}
}
return notification
14 changes: 14 additions & 0 deletions bahmni_stock/views/stock_pick_lot_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
<field name="sale_price" invisible="not context.get('show_lots_text')"/>
<field name="mrp" invisible="not context.get('show_lots_text')"/>
</xpath>
<xpath expr="//tree" position="inside">
<field name="is_move_line_lot_expiring_soon" invisible="1"/>
</xpath>
<xpath expr="//tree" position="attributes">
<attribute name="decoration-danger">False</attribute>
<attribute name="decoration-warning">is_move_line_lot_expiring_soon and state != 'done'</attribute>
</xpath>
</field>
</record>

Expand All @@ -42,6 +49,13 @@
<xpath expr="//tree/field[@name='location_dest_id'][2]" position="attributes">
<attribute name="attrs">{'column_invisible': [['parent.picking_type_code', 'in', ['incoming','internal']]]}</attribute>
</xpath>
<xpath expr="//tree" position="inside">
<field name="is_move_line_lot_expiring_soon" invisible="1"/>
</xpath>
<xpath expr="//tree" position="attributes">
<attribute name="decoration-danger">False</attribute>
<attribute name="decoration-warning">is_move_line_lot_expiring_soon and state != 'done'</attribute>
</xpath>
</field>
</record>

Expand Down
5 changes: 4 additions & 1 deletion bahmni_stock/wizard/stock_picking_validate_wizard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</div>
<br/>
<field name="move_lines">
<tree string="Stock Move Lines">
<tree string="Stock Move Lines" decoration-warning="is_move_line_lot_expiring_soon">
<field name="product_id"/>
<field name="qty_done" string="Quantity"/>
<field name="balance" string="Balance Quantity"
Expand All @@ -36,6 +36,9 @@
<field name="sale_price"
attrs="{'column_invisible': [['parent.picking_code', '!=', 'incoming']]}"/>
<field name="mrp" attrs="{'column_invisible': [['parent.picking_code', '!=', 'incoming']]}"/>
<field name="is_move_line_lot_expiring_soon" invisible="1"/>
<button class="fa fa-exclamation-circle text-warning" type="object" name="move_line_warning"
attrs="{'invisible': [('is_move_line_lot_expiring_soon', '=', False)]}"/>
</tree>
</field>
<footer>
Expand Down

0 comments on commit 58a8236

Please sign in to comment.