From 9e00ab81ed12ed08cb87f8eaf356b69ab466c77a Mon Sep 17 00:00:00 2001 From: AjmalCybro Date: Wed, 5 Mar 2025 12:00:07 +0530 Subject: [PATCH] Mar 5 [UPDT] : Updated 'dental_clinical_management' --- dental_clinical_management/__manifest__.py | 2 +- .../doc/RELEASE_NOTES.md | 5 ++ .../models/dental_prescription.py | 54 +++++++++++++++---- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/dental_clinical_management/__manifest__.py b/dental_clinical_management/__manifest__.py index 13765aa27..95c4a1b8c 100644 --- a/dental_clinical_management/__manifest__.py +++ b/dental_clinical_management/__manifest__.py @@ -21,7 +21,7 @@ ################################################################################ { 'name': 'Dental Clinic Management', - 'version': '17.0.1.0.0', + 'version': '17.0.1.0.1', 'category': 'Services', 'summary': """Dental Clinic Management is to manage the entire dental clinic.""", 'description': """Dental Clinic Management software, dental clinics can diff --git a/dental_clinical_management/doc/RELEASE_NOTES.md b/dental_clinical_management/doc/RELEASE_NOTES.md index 5fe53a530..6a1f03763 100644 --- a/dental_clinical_management/doc/RELEASE_NOTES.md +++ b/dental_clinical_management/doc/RELEASE_NOTES.md @@ -4,3 +4,8 @@ #### Version 17.0.1.0.0 #### ADD Initial commit for Dental Clinic Management + +#### 03.03.2025 +#### Version 17.0.1.0.1 +#### BugFix +Fixed the issue of stock management of medicines diff --git a/dental_clinical_management/models/dental_prescription.py b/dental_clinical_management/models/dental_prescription.py index 49be1a9a1..501e3a5fc 100644 --- a/dental_clinical_management/models/dental_prescription.py +++ b/dental_clinical_management/models/dental_prescription.py @@ -20,6 +20,7 @@ # ################################################################################ from odoo import api, fields, models, _ +from odoo.exceptions import UserError class DentalPrescription(models.Model): @@ -112,8 +113,18 @@ class DentalPrescription(models.Model): self.appointment_id.state = 'done' def create_invoice(self): - """Create an invoice based on the patient invoice.""" + """Create an invoice based on the patient invoice and manage stock moves for medicines.""" self.ensure_one() + medicine_moves = [] + for rec in self.medicine_ids: + product_id = self.env['product.product'].search([ + ('product_tmpl_id', '=', rec.medicament_id.id)], limit=1) + if product_id and product_id.type == 'product': # Only stockable products + medicine_moves.append({ + 'product_id': product_id, + 'quantity': rec.quantity, + }) + invoice_vals = { 'move_type': 'out_invoice', 'partner_id': self.patient_id.id, @@ -126,18 +137,43 @@ class DentalPrescription(models.Model): ] } invoice = self.env['account.move'].create(invoice_vals) + for rec in self.medicine_ids: product_id = self.env['product.product'].search([ - ('product_tmpl_id', '=', rec.medicament_id.id)]) - invoice['invoice_line_ids'] = [(0, 0, { - 'product_id': product_id.id, - 'name': rec.display_name, - 'quantity': rec.quantity, - 'price_unit': rec.price, - })] - self.invoice_data_id = invoice.id + ('product_tmpl_id', '=', rec.medicament_id.id)], limit=1) + if product_id: + invoice.write({ + 'invoice_line_ids': [(0, 0, { + 'product_id': product_id.id, + 'name': rec.display_name, + 'quantity': rec.quantity, + 'price_unit': rec.price, + })] + }) invoice.action_post() + + if medicine_moves: + warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) + if not warehouse: + raise UserError(_('No warehouse found for the company. Please configure a warehouse.')) + source_location = warehouse.lot_stock_id # Clinic's stock location + customer_location = self.env.ref('stock.stock_location_customers') # Customer location + + for move in medicine_moves: + self.env['stock.move'].create({ + 'name': f'Prescription {self.sequence_no}', + 'product_id': move['product_id'].id, + 'product_uom_qty': move['quantity'], + 'quantity': move['quantity'], + 'product_uom': move['product_id'].uom_id.id, + 'location_id': source_location.id, + 'location_dest_id': customer_location.id, + 'state': 'done', + }) + + self.invoice_data_id = invoice.id self.state = 'invoiced' + return { 'name': _('Customer Invoice'), 'view_mode': 'form',