Skip to content

Commit

Permalink
[Hari] | Add. Custom Modules for Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Hari committed Nov 23, 2023
1 parent 425d413 commit f7a8d6c
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bahmni_account/views/account_invoice_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
<field name="discount" style="width:100% !important" context="{'readonly_by_pass': True}"
attrs="{'readonly': [('discount_type', '=', 'percentage')]}"/>
</div>
<!--
<div class="col-xs-6 footer_label"
attrs="{'invisible': [('discount_type', '=', 'none')]}">
<label for="disc_acc_id" name="remove_display_prop"/>
Expand All @@ -198,6 +199,7 @@
<field name="disc_acc_id"
attrs="{'required': [('discount_type', 'in', ('fixed', 'percentage'))]}"/>
</div>
-->
<group style="width: 100%; border-top: 1px solid #cacaca;
font-weight: bold; white-space:nowrap;">
<div class="col-xs-6 oe_right footer_label">
Expand Down
2 changes: 2 additions & 0 deletions bahmni_api_feed/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from . import api_event_worker
from . import event_records
from . import reference_data_service
from . import product_uom_service
from . import drug_data_service
from . import res_company
from . import res_users
Expand Down
16 changes: 16 additions & 0 deletions bahmni_api_feed/models/event_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api


class EventRecords(models.Model):
_name = 'event.records'
_table = 'event_records'
_description = 'Class for publishing events for changes done in odoo '\
'and needs to be synced with bahmni'

uuid = fields.Char(string="UUID", translate=True, required=True)
title = fields.Char(string="Title", translate=True, required=True)
category = fields.Char(string="Category", translate=True, required=True)
timestamp = fields.Datetime(string="Timestamp", required=True)
uri = fields.Char(string="URI", translate=True)
object = fields.Text(string="SerializedContents", required=True)
67 changes: 67 additions & 0 deletions bahmni_api_feed/models/product_uom_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
import json
import logging

from odoo import models, fields, api

_logger = logging.getLogger(__name__)


class ProductUomService(models.Model):
_name = 'product.uom.service'
_auto = False

@api.model
def _fill_product_uom(self, product_uom_from_feed):
product_uom = {}
category = product_uom_from_feed.get("category")
category_from_db = self.env["product.uom.categ"].search([('uuid', '=', category["id"])],
limit=1)

product_uom["name"] = product_uom_from_feed.get("name")
product_uom["uuid"] = product_uom_from_feed.get("id")
product_uom["active"] = product_uom_from_feed.get("isActive")
ratio = float(product_uom_from_feed.get("ratio"))
product_uom["factor"] = 1/ratio
product_uom["category_id"] = category_from_db.id if category_from_db else False

uom_type = "reference"
if ratio > 1:
uom_type = "bigger"
elif ratio < 1:
uom_type = "smaller"

product_uom["uom_type"] = uom_type
return product_uom

@api.model
def create_or_update_product_uom(self, vals):
product_uom = json.loads(vals.get("product_uom"))
object_ids = self.env["product.uom"].with_context({"active_test": False}).search([('uuid', '=', product_uom.get("id"))], limit=1)
uom = self._fill_product_uom(product_uom)

if object_ids:
return object_ids.write(uom)

_logger.info("\ninserted : uom :\n")
_logger.info(object_ids)
_logger.info(uom)
return self.env['product.uom'].create(uom)

@api.model
def create_or_update_product_uom_category(self, vals):
product_uom_categ = json.loads(vals.get("product_uom_category"))
uom_categ = {}
uom_categ["name"] = product_uom_categ.get("name")
uom_categ["uuid"] = product_uom_categ.get("id")
object_ids = self.env["product.uom.categ"].search([('uuid', '=', uom_categ["uuid"])],
limit=1)

if object_ids:
_logger.info("\nupdated : uom_categ:\n")
_logger.info(uom_categ)
return object_ids.write(uom_categ)

_logger.info("\ninserted : uom_categ:\n")
_logger.info(uom_categ)
return self.env['product.uom.categ'].create(uom_categ)

0 comments on commit f7a8d6c

Please sign in to comment.