def send_request(self): # license_type = frappe.scrub(self.get("reference_document")) license_type = "room" client = get_metrc(license_type) response = client.post(self.endpoint, data=json.loads(self.request_body)) self.response_body = response.text self.response_code = response.status_code
# -*- coding: utf-8 -*- # Copyright (c) 2018, Neil Lasrado and contributors # For license information, please see license.txt from __future__ import unicode_literals import frappe from frappe.model.document import Document from frappe_metrc.utils import get_metrc metrc = get_metrc("plant_batch") class PlantBatch(Document): def validate(self): # self.create_or_update_plant_batch() self.check_plant_batch() def after_rename(self, old, new, merge=False): self.create_or_update_plant_batch() def create_or_update_plant_batch(self): data = [{ "Name": self.batch_name, "Type": self.type, "Count": self.count, "Strain": self.strain, "ActualDate": self.actual_date }] if not self.batch_id:
# -*- coding: utf-8 -*- # Copyright (c) 2018, Neil Lasrado and contributors # For license information, please see license.txt from __future__ import unicode_literals import frappe import requests from frappe.model.document import Document from frappe_metrc.utils import get_metrc metrc = get_metrc("lab_test") class LabTest(Document): def on_submit(self): results = [] for result in self.results: results.append({ "LabTestTypeName": result.lab_test_type, "Quantity": result.quantity, "Passed": result.passed, "Notes": result.notes }) data = [{ "Label": self.label, "ResultDate": self.result_date, "Results": results }]
# -*- coding: utf-8 -*- # Copyright (c) 2018, Neil Lasrado and contributors # For license information, please see license.txt from __future__ import unicode_literals import frappe import requests from frappe.model.document import Document from frappe_metrc.utils import get_metrc metrc = get_metrc("room") class Room(Document): def validate(self): self.create_or_update_room() self.check_room() def after_rename(self, old, new, merge=False): self.create_or_update_room() def create_or_update_room(self): data = [{"Name": self.room_name}] if not self.room_id: # Create Room in Metrc and assign ID metrc.post("/rooms/v1/create", data) else: # use the update API to update the object if room id exists data[0].update({"Id": self.room_id})
# -*- coding: utf-8 -*- # Copyright (c) 2018, Neil Lasrado and contributors # For license information, please see license.txt from __future__ import unicode_literals import frappe from frappe.model.document import Document from frappe_metrc.utils import get_metrc import random metrc = get_metrc("plant") class Plant(Document): def validate(self): # self.update_plant() self.check_plant() # self.move_plant() def move_plant(self): if self.room != frappe.db.get_value("Plant", self.name, "room"): data = [{ "Label": self.label, "Room": self.room, "ActualDate": frappe.utils.today() }] metrc.post("/plants/v1/moveplants", data) def manicure(self): data = [{ "Plant": self.label,
# -*- coding: utf-8 -*- # Copyright (c) 2018, Neil Lasrado and contributors # For license information, please see license.txt from __future__ import unicode_literals import frappe from frappe.model.document import Document from frappe_metrc.utils import get_metrc import random metrc = get_metrc("package") class Package(Document): def validate(self): self.update_package() def update_package(self): package = metrc.get("/packages/v1/{}".format(self.label)) if not package: return self.id = package.get("Id") self.package_type = package.get("PackageType") self.source_harvest = package.get("SourceHarvestNames") self.quantity = package.get("Quantity") self.uom = package.get("UnitOfMeasureName") harvest_doc = frappe.new_doc("Harvest") rooms = [room.get("name") for room in frappe.get_all("Room")] harvest_doc.harvest_name = package.get("SourceHarvestNames")
# -*- coding: utf-8 -*- # Copyright (c) 2018, Neil Lasrado and contributors # For license information, please see license.txt from __future__ import unicode_literals import frappe import requests from frappe import _ from frappe.model.document import Document from frappe_metrc.utils import get_metrc metrc = get_metrc("strain") class Strain(Document): def validate(self): pass # self.create_or_update_strain() # self.check_strain() def after_rename(self, old, new, merge=False): self.create_or_update_strain() def create_or_update_strain(self): if self.indica_percentage and self.sativa_percentage: if not self.indica_percentage + self.sativa_percentage == 100: frappe.throw( _("Indica Percentage and Sativa Percentage combined must be 100%." ))