Skip to content

Commit

Permalink
[Karthi] | Live-Stopper | Refactor. Sale Order and Internal Transfer …
Browse files Browse the repository at this point in the history
…Batch number listed location based has been restriction done. (#141)
  • Loading branch information
karthikeyansp91 authored Apr 3, 2024
1 parent 6f9c87d commit 23b6dfa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
8 changes: 4 additions & 4 deletions bahmni_sale/views/sale_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
widget='monetary'
options="{'currency_field': 'currency_id'}"/>

<field name="prev_outstanding_balance" widget='monetary'
<field name="prev_outstanding_balance" widget='monetary' attrs="{'readonly': [('state', 'not in', ['draft', 'sent'])]}"
options="{'currency_field': 'currency_id'}"/>


Expand All @@ -85,16 +85,16 @@


<xpath expr="//field[@name='order_line']/tree/field[@name='qty_delivered']" position="after">
<field name="lot_id" domain="['|',('expiration_date','&gt;', datetime.datetime.combine(context_today(), datetime.time(23,59,59))),('expiration_date','=',False),('product_qty','>' ,0),('product_id','=',product_id)]"/>
<field name="lot_id" context = "{'parent_shop_id':parent.shop_id}" domain="['|',('expiration_date','&gt;', datetime.datetime.combine(context_today(), datetime.time(23,59,59))),('expiration_date','=',False),('product_qty','>' ,0),('product_id','=',product_id)]"/>
<field name="expiry_date" force_save="1" readonly="1"/>
</xpath>
<xpath expr="//field[@name='order_line']/form/group/group/field[@name='price_unit']" position="after">
<field name="lot_id" domain="['|',('expiration_date','&gt;', datetime.datetime.combine(context_today(), datetime.time(23,59,59))),('expiration_date','=',False),('product_qty','>' ,0),('product_id','=',product_id)]"/>
<field name="lot_id" context = "{'parent_shop_id':parent.shop_id}" domain="['|',('expiration_date','&gt;', datetime.datetime.combine(context_today(), datetime.time(23,59,59))),('expiration_date','=',False),('product_qty','>' ,0),('product_id','=',product_id)]"/>
<field name="expiry_date" readonly="1"/>
</xpath>
<xpath expr="//field[@name='order_line']/tree/field[@name='product_id']" position="replace">
<field name="product_id"
context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom, 'company_id': parent.company_id}"/><!--attrs="{'readonly': ['|', ('qty_invoiced', '&gt;', 0), ('procurement_ids', '!=', [])]}"-->
context="{'parent_shop_id':parent.shop_id,'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom, 'company_id': parent.company_id}"/><!--attrs="{'readonly': ['|', ('qty_invoiced', '&gt;', 0), ('procurement_ids', '!=', [])]}"-->
</xpath>
<xpath expr="//field[@name='order_line']/tree/field[@name='qty_delivered']" position="replace">
<field name="qty_delivered" invisible="context.get('hide_sale')"/>
Expand Down
53 changes: 38 additions & 15 deletions bahmni_stock/models/stock_production_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,45 @@ class StockProductionLot(models.Model):

def name_get(self):
'''name_get method is overridden to view expiry date in many2one field of lot'''
if self._context is None:
context = {}
else:
context = self._context.copy()
res = []
res = []
for record in self:
name = record.name
if(record.expiration_date):
if len(str(record.expiration_date)) > 20:
expiry_date = datetime.strptime(str(record.expiration_date), "%Y-%m-%d %H:%M:%S.%f")
else:
expiry_date = datetime.strptime(str(record.expiration_date), "%Y-%m-%d %H:%M:%S")
expiry = expiry_date.strftime("%b %d,%Y")
name = "%s [%s]" % (name, expiry)
if(context.get('show_future_forcast', False)):
name = "%s %s" % (name, record.future_stock_forecast)
name = ''
if self.env.context.get('parent_shop_id'):
shop_id = self.env['sale.shop'].search([('id', '=', self.env.context.get('parent_shop_id'))])
stock_quant_lot = self.env['stock.quant'].search([
('product_id','=', record.product_id.id),('lot_id','=', record.id),
('location_id', '=', shop_id.location_id.id),('quantity', '>' , 0)])
if stock_quant_lot:
if(record.expiration_date):
if len(str(record.expiration_date)) > 20:
expiry_date = datetime.strptime(str(record.expiration_date), "%Y-%m-%d %H:%M:%S.%f")
else:
expiry_date = datetime.strptime(str(record.expiration_date), "%Y-%m-%d %H:%M:%S")
expiry = expiry_date.strftime("%b %d,%Y")
name = record.name
name = "%s [%s], %s" % (name, expiry,stock_quant_lot.quantity)
elif self.env.context.get('default_internal_location_id'):
stock_quant_lot = self.env['stock.quant'].search([
('product_id','=', record.product_id.id),('lot_id','=', record.id),
('location_id', '=', self.env.context.get('default_internal_location_id')),('quantity', '>' , 0)])
if stock_quant_lot:
if(record.expiration_date):
if len(str(record.expiration_date)) > 20:
expiry_date = datetime.strptime(str(record.expiration_date), "%Y-%m-%d %H:%M:%S.%f")
else:
expiry_date = datetime.strptime(str(record.expiration_date), "%Y-%m-%d %H:%M:%S")
expiry = expiry_date.strftime("%b %d,%Y")
name = record.name
name = "%s [%s], %s" % (name, expiry,stock_quant_lot.quantity)
else:
name = record.name
if(record.expiration_date):
if len(str(record.expiration_date)) > 20:
expiry_date = datetime.strptime(str(record.expiration_date), "%Y-%m-%d %H:%M:%S.%f")
else:
expiry_date = datetime.strptime(str(record.expiration_date), "%Y-%m-%d %H:%M:%S")
expiry = expiry_date.strftime("%b %d,%Y")
name = "%s [%s]" % (name, expiry)
res.append((record.id, name))
return res

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
/>
<field name="arch" type="xml">
<field name="lot_id" position="attributes">
<attribute
name="context"
>{'default_internal_location_id': location_id}</attribute>
<attribute
name="domain"
>[('product_id','=', product_id), ('company_id', '=', company_id), ('location_ids', 'child_of', location_id)]</attribute>
Expand Down

0 comments on commit 23b6dfa

Please sign in to comment.