Skip to content

Commit

Permalink
[Karthi] | BAH-3619 | Refactor. Batch number is visible in the delive…
Browse files Browse the repository at this point in the history
…ry order. (#72)
  • Loading branch information
karthikeyansp91 authored Mar 5, 2024
1 parent 7a9a760 commit 7c1d113
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 38 deletions.
1 change: 1 addition & 0 deletions bahmni_sale/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from . import pos
from . import account_invoice
from . import shop
from . import stock_move
50 changes: 12 additions & 38 deletions bahmni_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,45 +239,19 @@ def _prepare_invoice(self):
#By Pass the Invoice wizard while we press the "Create Invoice" button in sale order afer confirmation.
#So Once we Confirm the sale order it will create the invoice and ask for the register payment.
def action_confirm(self):
res = super(SaleOrder,self).action_confirm()
for line in self.order_line:
if line.product_id.tracking == 'lot' and not line.lot_id:
raise UserError("Kindly choose batch no for %s to proceed further."%(line.product_id.name))

if 1 < self.order_line.search_count([('lot_id', '=', line.lot_id.id),('order_id', '=', self.id)]) and line.lot_id:
raise UserError("%s Duplicate batch no is not allowed. Kindly change the batch no to proceed further."%(line.lot_id.name))
if line.product_uom_qty > line.lot_id.product_qty and line.lot_id:
raise UserError("Insufficient batch(%s) quantity for %s and available quantity is %s"\
%(line.lot_id.name, line.product_id.name, line.lot_id.product_qty))
res = super(SaleOrder, self.with_context(default_immediate_transfer=True)).action_confirm()
self.validate_delivery()
#here we need to set condition for if the its enabled then can continuw owise return True in else condition
if self.env.user.has_group('bahmni_sale.group_skip_invoice_options'):
for order in self:
inv_data = order._prepare_invoice()
created_invoice = self.env['account.invoice'].create(inv_data)

for line in order.order_line:
line.invoice_line_create(created_invoice.id, line.product_uom_qty)

# Use additional field helper function (for account extensions)
for line in created_invoice.invoice_line_ids:
line._set_additional_fields(created_invoice)

# Necessary to force computation of taxes. In account_invoice, they are triggered
# by onchanges, which are not triggered when doing a create.
created_invoice.compute_taxes()
created_invoice.message_post_with_view('mail.message_origin_link',
values={'self': created_invoice, 'origin': order},
subtype_id=self.env.ref('mail.mt_note').id)
created_invoice.action_invoice_open()#Validate Invoice
ctx = dict(
default_invoice_ids = [(4, created_invoice.id, None)]
)
reg_pay_form = self.env.ref('account.view_account_payment_invoice_form')
return {
'name': _('Register Payment'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'account.payment',
'views': [(reg_pay_form.id, 'form')],
'view_id': reg_pay_form.id,
'target': 'new',
'context': ctx,
}
else:
return res

return res


#This method will be called when validation is happens from the Bahmni side
Expand Down
23 changes: 23 additions & 0 deletions bahmni_sale/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from odoo import models


class StockMove(models.Model):
_inherit = 'stock.move'

def _update_reserved_quantity(self, need, available_quantity,
location_id, lot_id=None,
package_id=None, owner_id=None,
strict=True):
if self.sale_line_id.lot_id:
lot_id = self.sale_line_id.lot_id
return super()._update_reserved_quantity(
need, available_quantity, location_id, lot_id=lot_id,
package_id=package_id, owner_id=owner_id, strict=strict)

def _prepare_move_line_vals(self, quantity=None, reserved_quant=None):
vals = super()._prepare_move_line_vals(
quantity=quantity, reserved_quant=reserved_quant)
lot = self.sale_line_id.lot_id
if reserved_quant and lot:
vals['lot_id'] = lot.id
return vals

0 comments on commit 7c1d113

Please sign in to comment.