def cancel_build(self, user, **kwargs): """ Mark the Build as CANCELLED - Delete any pending BuildItem objects (but do not remove items from stock) - Set build status to CANCELLED - Save the Build object """ remove_allocated_stock = kwargs.get('remove_allocated_stock', False) remove_incomplete_outputs = kwargs.get('remove_incomplete_outputs', False) # Handle stock allocations for build_item in self.allocated_stock.all(): if remove_allocated_stock: build_item.complete_allocation(user) build_item.delete() # Remove incomplete outputs (if required) if remove_incomplete_outputs: outputs = self.build_outputs.filter(is_building=True) for output in outputs: output.delete() # Date of 'completion' is the date the build was cancelled self.completion_date = datetime.now().date() self.completed_by = user self.status = BuildStatus.CANCELLED self.save() trigger_event('build.cancelled', id=self.pk)
def notify_overdue_build_order(bo: build.models.Build): """Notify appropriate users that a Build has just become 'overdue'""" targets = [] if bo.issued_by: targets.append(bo.issued_by) if bo.responsible: targets.append(bo.responsible) name = _('Overdue Build Order') context = { 'order': bo, 'name': name, 'message': _(f"Build order {bo} is now overdue"), 'link': InvenTree.helpers.construct_absolute_url(bo.get_absolute_url(), ), 'template': { 'html': 'email/overdue_build_order.html', 'subject': name, } } event_name = 'build.overdue_build_order' # Send a notification to the appropriate users common.notifications.trigger_notification(bo, event_name, targets=targets, context=context) # Register a matching event to the plugin system trigger_event(event_name, build_order=bo.pk)
def cancel_order(self): """ Marks the PurchaseOrder as CANCELLED. """ if self.can_cancel(): self.status = PurchaseOrderStatus.CANCELLED self.save() trigger_event('purchaseorder.cancelled', id=self.pk)
def complete_order(self): """ Marks the PurchaseOrder as COMPLETE. Order must be currently PLACED. """ if self.status == PurchaseOrderStatus.PLACED: self.status = PurchaseOrderStatus.COMPLETE self.complete_date = datetime.now().date() self.save() trigger_event('purchaseorder.completed', id=self.pk)
def place_order(self): """ Marks the PurchaseOrder as PLACED. Order must be currently PENDING. """ if self.status == PurchaseOrderStatus.PENDING: self.status = PurchaseOrderStatus.PLACED self.issue_date = datetime.now().date() self.save() trigger_event('purchaseorder.placed', id=self.pk)
def complete_order(self, user): """ Mark this order as "complete" """ if not self.can_complete(): return False self.status = SalesOrderStatus.SHIPPED self.shipped_by = user self.shipment_date = datetime.now() self.save() trigger_event('salesorder.completed', id=self.pk) return True
def complete_shipment(self, user, **kwargs): """ Complete this particular shipment: 1. Update any stock items associated with this shipment 2. Update the "shipped" quantity of all associated line items 3. Set the "shipment_date" to now """ # Check if the shipment can be completed (throw error if not) self.check_can_complete() allocations = self.allocations.all() # Iterate through each stock item assigned to this shipment for allocation in allocations: # Mark the allocation as "complete" allocation.complete_allocation(user) # Update the "shipment" date self.shipment_date = kwargs.get('shipment_date', datetime.now()) self.shipped_by = user # Was a tracking number provided? tracking_number = kwargs.get('tracking_number', None) if tracking_number is not None: self.tracking_number = tracking_number # Was an invoice number provided? invoice_number = kwargs.get('invoice_number', None) if invoice_number is not None: self.invoice_number = invoice_number # Was a link provided? link = kwargs.get('link', None) if link is not None: self.link = link self.save() trigger_event('salesordershipment.completed', id=self.pk)
def notify_overdue_sales_order(so: order.models.SalesOrder): """Notify appropriate users that a SalesOrder has just become 'overdue'""" targets = [] if so.created_by: targets.append(so.created_by) if so.responsible: targets.append(so.responsible) name = _('Overdue Sales Order') context = { 'order': so, 'name': name, 'message': _(f"Sales order {so} is now overdue"), 'link': InvenTree.helpers.construct_absolute_url( so.get_absolute_url(), ), 'template': { 'html': 'email/overdue_sales_order.html', 'subject': name, } } event_name = 'order.overdue_sales_order' # Send a notification to the appropriate users common.notifications.trigger_notification( so, event_name, targets=targets, context=context, ) # Register a matching event to the plugin system trigger_event( event_name, sales_order=so.pk, )
def cancel_order(self): """ Cancel this order (only if it is "pending") - Mark the order as 'cancelled' - Delete any StockItems which have been allocated """ if not self.can_cancel(): return False self.status = SalesOrderStatus.CANCELLED self.save() for line in self.lines.all(): for allocation in line.allocations.all(): allocation.delete() trigger_event('salesorder.cancelled', id=self.pk) return True
def complete_build(self, user): """ Mark this build as complete """ if self.incomplete_count > 0: return self.completion_date = datetime.now().date() self.completed_by = user self.status = BuildStatus.COMPLETE self.save() # Remove untracked allocated stock self.subtract_allocated_stock(user) # Ensure that there are no longer any BuildItem objects # which point to thisFcan Build Order self.allocated_stock.all().delete() # Register an event trigger_event('build.completed', id=self.pk)
def complete_build(self, user): """Mark this build as complete.""" if self.incomplete_count > 0: return self.completion_date = datetime.now().date() self.completed_by = user self.status = BuildStatus.COMPLETE self.save() # Remove untracked allocated stock self.subtract_allocated_stock(user) # Ensure that there are no longer any BuildItem objects # which point to this Build Order self.allocated_stock.all().delete() # Register an event trigger_event('build.completed', id=self.pk) # Notify users that this build has been completed targets = [ self.issued_by, self.responsible, ] # Notify those users interested in the parent build if self.parent: targets.append(self.parent.issued_by) targets.append(self.parent.responsible) # Notify users if this build points to a sales order if self.sales_order: targets.append(self.sales_order.created_by) targets.append(self.sales_order.responsible) build = self name = _(f'Build order {build} has been completed') context = { 'build': build, 'name': name, 'slug': 'build.completed', 'message': _('A build order has been completed'), 'link': InvenTree.helpers.construct_absolute_url(self.get_absolute_url()), 'template': { 'html': 'email/build_order_completed.html', 'subject': name, } } common.notifications.trigger_notification( build, 'build.completed', targets=targets, context=context, target_exclude=[user], )