<s> from datetime import datetime <EOL> import json_field <EOL> from django . dispatch . dispatcher import receiver <EOL> from corehq . apps . domain . signals import commcare_domain_pre_delete <EOL> from corehq . apps . locations . signals import location_edited <EOL> from dimagi . ext . couchdbkit import Document , BooleanProperty , StringProperty <EOL> from django . db import models , connection <EOL> from casexml . apps . stock . models import DocDomainMapping <EOL> from corehq . apps . locations . models import SQLLocation <EOL> from custom . utils . utils import add_to_module_map <EOL> from dimagi . utils . dates import force_to_datetime <EOL> class ILSGatewayConfig ( Document ) : <EOL> enabled = BooleanProperty ( default = False ) <EOL> domain = StringProperty ( ) <EOL> url = StringProperty ( default = "<STR_LIT>" ) <EOL> username = StringProperty ( ) <EOL> password = StringProperty ( ) <EOL> steady_sync = BooleanProperty ( default = False ) <EOL> all_stock_data = BooleanProperty ( default = False ) <EOL> @ classmethod <EOL> def for_domain ( cls , name ) : <EOL> try : <EOL> mapping = DocDomainMapping . objects . get ( domain_name = name , doc_type = '<STR_LIT>' ) <EOL> return cls . get ( docid = mapping . doc_id ) <EOL> except DocDomainMapping . DoesNotExist : <EOL> return None <EOL> @ classmethod <EOL> def get_all_configs ( cls ) : <EOL> mappings = DocDomainMapping . objects . filter ( doc_type = '<STR_LIT>' ) <EOL> configs = [ cls . get ( docid = mapping . doc_id ) for mapping in mappings ] <EOL> return configs <EOL> @ classmethod <EOL> def get_all_enabled_domains ( cls ) : <EOL> configs = cls . get_all_configs ( ) <EOL> return [ c . domain for c in filter ( lambda config : config . enabled , configs ) ] <EOL> @ classmethod <EOL> def get_all_steady_sync_configs ( cls ) : <EOL> return [ <EOL> config for config in cls . get_all_configs ( ) <EOL> if config . steady_sync <EOL> ] <EOL> @ property <EOL> def is_configured ( self ) : <EOL> return True if self . enabled and self . url and self . password and self . username else False <EOL> def save ( self , ** params ) : <EOL> super ( ILSGatewayConfig , self ) . save ( ** params ) <EOL> try : <EOL> DocDomainMapping . objects . get ( doc_id = self . _id , <EOL> domain_name = self . domain , <EOL> doc_type = "<STR_LIT>" ) <EOL> except DocDomainMapping . DoesNotExist : <EOL> DocDomainMapping . objects . create ( doc_id = self . _id , <EOL> domain_name = self . domain , <EOL> doc_type = '<STR_LIT>' ) <EOL> add_to_module_map ( self . domain , '<STR_LIT>' ) <EOL> class SupplyPointStatusValues ( object ) : <EOL> RECEIVED = "<STR_LIT>" <EOL> NOT_RECEIVED = "<STR_LIT>" <EOL> SUBMITTED = "<STR_LIT>" <EOL> NOT_SUBMITTED = "<STR_LIT>" <EOL> REMINDER_SENT = "<STR_LIT>" <EOL> ALERT_SENT = "<STR_LIT>" <EOL> CHOICES = [ RECEIVED , NOT_RECEIVED , SUBMITTED , <EOL> NOT_SUBMITTED , REMINDER_SENT , ALERT_SENT ] <EOL> class SupplyPointStatusTypes ( object ) : <EOL> DELIVERY_FACILITY = "<STR_LIT>" <EOL> DELIVERY_DISTRICT = "<STR_LIT>" <EOL> R_AND_R_FACILITY = "<STR_LIT>" <EOL> R_AND_R_DISTRICT = "<STR_LIT>" <EOL> SOH_FACILITY = "<STR_LIT>" <EOL> SUPERVISION_FACILITY = "<STR_LIT>" <EOL> LOSS_ADJUSTMENT_FACILITY = "<STR_LIT>" <EOL> DELINQUENT_DELIVERIES = "<STR_LIT>" <EOL> TRANS_FACILITY = "<STR_LIT>" <EOL> CHOICE_MAP = { <EOL> DELIVERY_FACILITY : { SupplyPointStatusValues . REMINDER_SENT : "<STR_LIT>" , <EOL> SupplyPointStatusValues . RECEIVED : "<STR_LIT>" , <EOL> SupplyPointStatusValues . NOT_RECEIVED : "<STR_LIT>" } , <EOL> DELIVERY_DISTRICT : { SupplyPointStatusValues . REMINDER_SENT : "<STR_LIT>" , <EOL> SupplyPointStatusValues . RECEIVED : "<STR_LIT>" , <EOL> SupplyPointStatusValues . NOT_RECEIVED : "<STR_LIT>" } , <EOL> R_AND_R_FACILITY : { SupplyPointStatusValues . REMINDER_SENT : "<STR_LIT>" , <EOL> SupplyPointStatusValues . SUBMITTED : "<STR_LIT>" , <EOL> SupplyPointStatusValues . NOT_SUBMITTED : "<STR_LIT>" } , <EOL> R_AND_R_DISTRICT : { SupplyPointStatusValues . REMINDER_SENT : "<STR_LIT>" , <EOL> SupplyPointStatusValues . SUBMITTED : "<STR_LIT>" } , <EOL> SOH_FACILITY : { SupplyPointStatusValues . REMINDER_SENT : "<STR_LIT>" , <EOL> SupplyPointStatusValues . SUBMITTED : "<STR_LIT>" } , <EOL> SUPERVISION_FACILITY : { SupplyPointStatusValues . REMINDER_SENT : "<STR_LIT>" , <EOL> SupplyPointStatusValues . RECEIVED : "<STR_LIT>" , <EOL> SupplyPointStatusValues . NOT_RECEIVED : "<STR_LIT>" } , <EOL> LOSS_ADJUSTMENT_FACILITY : { <EOL> SupplyPointStatusValues . REMINDER_SENT : "<STR_LIT>" <EOL> } , <EOL> DELINQUENT_DELIVERIES : { <EOL> SupplyPointStatusValues . ALERT_SENT : "<STR_LIT>" <EOL> } , <EOL> TRANS_FACILITY : { <EOL> SupplyPointStatusValues . SUBMITTED : "<STR_LIT>" , <EOL> SupplyPointStatusValues . NOT_SUBMITTED : "<STR_LIT>" , <EOL> SupplyPointStatusValues . REMINDER_SENT : "<STR_LIT>" <EOL> } <EOL> } <EOL> @ classmethod <EOL> def get_display_name ( cls , type , value ) : <EOL> return cls . CHOICE_MAP [ type ] [ value ] <EOL> @ classmethod <EOL> def is_legal_combination ( cls , type , value ) : <EOL> return type in cls . CHOICE_MAP and value in cls . CHOICE_MAP [ type ] <EOL> class SupplyPointStatus ( models . Model ) : <EOL> status_type = models . CharField ( choices = ( ( k , k ) for k in SupplyPointStatusTypes . CHOICE_MAP . keys ( ) ) , <EOL> max_length = <NUM_LIT:50> ) <EOL> status_value = models . CharField ( max_length = <NUM_LIT:50> , <EOL> choices = ( ( c , c ) for c in SupplyPointStatusValues . CHOICES ) ) <EOL> status_date = models . DateTimeField ( default = datetime . utcnow ) <EOL> location_id = models . CharField ( max_length = <NUM_LIT:100> , db_index = True ) <EOL> external_id = models . PositiveIntegerField ( null = True , db_index = True ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> if not SupplyPointStatusTypes . is_legal_combination ( self . status_type , self . status_value ) : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> ( self . status_type , self . status_value ) ) <EOL> super ( SupplyPointStatus , self ) . save ( * args , ** kwargs ) <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( self . status_type , self . status_value ) <EOL> @ property <EOL> def name ( self ) : <EOL> return SupplyPointStatusTypes . get_display_name ( self . status_type , self . status_value ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> verbose_name = "<STR_LIT>" <EOL> verbose_name_plural = "<STR_LIT>" <EOL> get_latest_by = "<STR_LIT>" <EOL> ordering = ( '<STR_LIT>' , ) <EOL> class DeliveryGroupReport ( models . Model ) : <EOL> location_id = models . CharField ( max_length = <NUM_LIT:100> , db_index = True ) <EOL> quantity = models . IntegerField ( ) <EOL> report_date = models . DateTimeField ( default = datetime . utcnow ) <EOL> message = models . CharField ( max_length = <NUM_LIT:100> , db_index = True ) <EOL> delivery_group = models . CharField ( max_length = <NUM_LIT:1> ) <EOL> external_id = models . PositiveIntegerField ( null = True , db_index = True ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> ordering = ( '<STR_LIT>' , ) <EOL> class ReportingModel ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> date = models . DateTimeField ( ) <EOL> location_id = models . CharField ( max_length = <NUM_LIT:100> , db_index = True ) <EOL> create_date = models . DateTimeField ( editable = False ) <EOL> update_date = models . DateTimeField ( editable = False ) <EOL> external_id = models . PositiveIntegerField ( db_index = True , null = True ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> def save ( self , * args , ** kwargs ) : <EOL> if not self . id : <EOL> self . create_date = datetime . utcnow ( ) <EOL> self . update_date = datetime . utcnow ( ) <EOL> super ( ReportingModel , self ) . save ( * args , ** kwargs ) <EOL> class Meta : <EOL> abstract = True <EOL> class OrganizationSummary ( ReportingModel ) : <EOL> total_orgs = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> average_lead_time_in_days = models . FloatField ( default = <NUM_LIT:0> ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( self . location_id , self . date . month , self . date . year ) <EOL> class GroupSummary ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> org_summary = models . ForeignKey ( '<STR_LIT>' ) <EOL> title = models . CharField ( max_length = <NUM_LIT:50> , blank = True , null = True ) <EOL> total = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> responded = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> on_time = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> complete = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> external_id = models . PositiveIntegerField ( db_index = True , null = True ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> @ classmethod <EOL> def wrap_form_json ( cls , obj , location_id ) : <EOL> org_summary_id = obj [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] <EOL> del obj [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] <EOL> obj [ '<STR_LIT>' ] [ '<STR_LIT>' ] = org_summary_id <EOL> obj [ '<STR_LIT>' ] [ '<STR_LIT>' ] = location_id <EOL> obj [ '<STR_LIT>' ] [ '<STR_LIT>' ] = force_to_datetime ( obj [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> obj [ '<STR_LIT>' ] [ '<STR_LIT>' ] = force_to_datetime ( obj [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> obj [ '<STR_LIT>' ] [ '<STR_LIT:date>' ] = force_to_datetime ( obj [ '<STR_LIT>' ] [ '<STR_LIT:date>' ] ) <EOL> try : <EOL> obj [ '<STR_LIT>' ] = OrganizationSummary . objects . get ( external_id = org_summary_id ) <EOL> except OrganizationSummary . DoesNotExist : <EOL> obj [ '<STR_LIT>' ] = OrganizationSummary . objects . create ( ** obj [ '<STR_LIT>' ] ) <EOL> obj [ '<STR_LIT>' ] = obj [ '<STR_LIT:id>' ] <EOL> del obj [ '<STR_LIT:id>' ] <EOL> return cls ( ** obj ) <EOL> @ property <EOL> def late ( self ) : <EOL> return self . complete - self . on_time <EOL> @ property <EOL> def not_responding ( self ) : <EOL> return self . total - self . responded <EOL> def is_delivery_or_supervision_facility ( self ) : <EOL> return self . title in [ SupplyPointStatusTypes . DELIVERY_FACILITY , <EOL> SupplyPointStatusTypes . SUPERVISION_FACILITY ] <EOL> @ property <EOL> def received ( self ) : <EOL> assert self . is_delivery_or_supervision_facility ( ) <EOL> return self . complete <EOL> @ property <EOL> def not_received ( self ) : <EOL> assert self . is_delivery_or_supervision_facility ( ) <EOL> return self . responded - self . complete <EOL> @ property <EOL> def sup_received ( self ) : <EOL> assert self . title in SupplyPointStatusTypes . SUPERVISION_FACILITY <EOL> return self . complete <EOL> @ property <EOL> def sup_not_received ( self ) : <EOL> assert self . title == SupplyPointStatusTypes . SUPERVISION_FACILITY <EOL> return self . responded - self . complete <EOL> @ property <EOL> def del_received ( self ) : <EOL> assert self . title == SupplyPointStatusTypes . DELIVERY_FACILITY <EOL> return self . complete <EOL> @ property <EOL> def del_not_received ( self ) : <EOL> assert self . title == SupplyPointStatusTypes . DELIVERY_FACILITY <EOL> return self . responded - self . complete <EOL> @ property <EOL> def not_submitted ( self ) : <EOL> assert self . title in [ SupplyPointStatusTypes . SOH_FACILITY , <EOL> SupplyPointStatusTypes . R_AND_R_FACILITY ] <EOL> return self . responded - self . complete <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( self . org_summary , self . title ) <EOL> class ProductAvailabilityData ( ReportingModel ) : <EOL> product = models . CharField ( max_length = <NUM_LIT:100> , db_index = True ) <EOL> total = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> with_stock = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> without_stock = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> without_data = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' '<STR_LIT>' . format ( self . date , self . product , self . total , self . with_stock , <EOL> self . without_stock , self . without_data ) <EOL> class ProductAvailabilityDashboardChart ( object ) : <EOL> label_color = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> width = <NUM_LIT> <EOL> height = <NUM_LIT> <EOL> div = "<STR_LIT>" <EOL> legenddiv = "<STR_LIT>" <EOL> xaxistitle = "<STR_LIT>" <EOL> yaxistitle = "<STR_LIT>" <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> class Alert ( ReportingModel ) : <EOL> type = models . CharField ( max_length = <NUM_LIT:50> , blank = True , null = True ) <EOL> number = models . PositiveIntegerField ( default = <NUM_LIT:0> ) <EOL> text = models . TextField ( ) <EOL> url = models . CharField ( max_length = <NUM_LIT:100> , blank = True , null = True ) <EOL> expires = models . DateTimeField ( ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> class DeliveryGroups ( object ) : <EOL> """<STR_LIT>""" <EOL> GROUPS = ( '<STR_LIT:A>' , '<STR_LIT:B>' , '<STR_LIT:C>' ) <EOL> def __init__ ( self , month = None , facs = None ) : <EOL> self . month = month if month else datetime . utcnow ( ) . month <EOL> self . facs = facs <EOL> def current_submitting_group ( self , month = None ) : <EOL> month = month if month else self . month <EOL> return self . GROUPS [ ( month + <NUM_LIT:2> ) % <NUM_LIT:3> ] <EOL> def current_processing_group ( self , month = None ) : <EOL> month = month if month else self . month <EOL> return self . current_submitting_group ( month = ( month + <NUM_LIT:2> ) ) <EOL> def current_delivering_group ( self , month = None ) : <EOL> month = month if month else self . month <EOL> return self . current_submitting_group ( month = ( month + <NUM_LIT:1> ) ) <EOL> def delivering ( self , facs = None , month = None ) : <EOL> if not facs : <EOL> facs = self . facs <EOL> if not facs : <EOL> return [ ] <EOL> return filter ( lambda f : self . current_delivering_group ( month ) == f . metadata . get ( '<STR_LIT>' , None ) , facs ) <EOL> def processing ( self , facs = None , month = None ) : <EOL> if not facs : <EOL> facs = self . facs <EOL> if not facs : <EOL> return [ ] <EOL> return filter ( lambda f : self . current_processing_group ( month ) == f . metadata . get ( '<STR_LIT>' , None ) , facs ) <EOL> def submitting ( self , facs = None , month = None ) : <EOL> if not facs : <EOL> facs = self . facs <EOL> if not facs : <EOL> return [ ] <EOL> return filter ( lambda f : self . current_submitting_group ( month ) == f . metadata . get ( '<STR_LIT>' , None ) , facs ) <EOL> class ReportRun ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> start = models . DateTimeField ( ) <EOL> end = models . DateTimeField ( ) <EOL> start_run = models . DateTimeField ( ) <EOL> end_run = models . DateTimeField ( null = True ) <EOL> complete = models . BooleanField ( default = False ) <EOL> has_error = models . BooleanField ( default = False ) <EOL> domain = models . CharField ( max_length = <NUM_LIT> ) <EOL> location = models . ForeignKey ( SQLLocation , null = True , on_delete = models . PROTECT ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> @ classmethod <EOL> def last_success ( cls , domain ) : <EOL> """<STR_LIT>""" <EOL> qs = cls . objects . filter ( complete = True , has_error = False , domain = domain ) <EOL> return qs . order_by ( "<STR_LIT>" ) [ <NUM_LIT:0> ] if qs . count ( ) else None <EOL> @ classmethod <EOL> def last_run ( cls , domain ) : <EOL> qs = cls . objects . filter ( complete = True , domain = domain ) <EOL> return qs . order_by ( "<STR_LIT>" ) [ <NUM_LIT:0> ] if qs . count ( ) else None <EOL> class RequisitionReport ( models . Model ) : <EOL> location_id = models . CharField ( max_length = <NUM_LIT:100> , db_index = True ) <EOL> submitted = models . BooleanField ( default = False ) <EOL> report_date = models . DateTimeField ( default = datetime . utcnow ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> class SupervisionDocument ( models . Model ) : <EOL> document = models . TextField ( ) <EOL> domain = models . CharField ( max_length = <NUM_LIT:100> ) <EOL> name = models . CharField ( max_length = <NUM_LIT:100> ) <EOL> data_type = models . CharField ( max_length = <NUM_LIT:100> ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> class ILSNotes ( models . Model ) : <EOL> location = models . ForeignKey ( SQLLocation , on_delete = models . PROTECT ) <EOL> domain = models . CharField ( max_length = <NUM_LIT:100> , null = False ) <EOL> user_name = models . CharField ( max_length = <NUM_LIT> , null = False ) <EOL> user_role = models . CharField ( max_length = <NUM_LIT:100> , null = True ) <EOL> user_phone = models . CharField ( max_length = <NUM_LIT:20> , null = True ) <EOL> date = models . DateTimeField ( ) <EOL> text = models . TextField ( ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> class PendingReportingDataRecalculation ( models . Model ) : <EOL> domain = models . CharField ( max_length = <NUM_LIT> ) <EOL> sql_location = models . ForeignKey ( SQLLocation ) <EOL> type = models . CharField ( max_length = <NUM_LIT> ) <EOL> data = json_field . JSONField ( ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> class SLABConfig ( models . Model ) : <EOL> is_pilot = models . BooleanField ( default = False ) <EOL> sql_location = models . ForeignKey ( SQLLocation , null = False , unique = True ) <EOL> closest_supply_points = models . ManyToManyField ( SQLLocation , related_name = '<STR_LIT:+>' ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> class OneOffTaskProgress ( models . Model ) : <EOL> domain = models . CharField ( max_length = <NUM_LIT> ) <EOL> task_name = models . CharField ( max_length = <NUM_LIT> ) <EOL> last_synced_object_id = models . CharField ( max_length = <NUM_LIT> , null = True ) <EOL> complete = models . BooleanField ( default = False ) <EOL> progress = models . IntegerField ( default = <NUM_LIT:0> ) <EOL> total = models . IntegerField ( default = <NUM_LIT:0> ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> @ receiver ( commcare_domain_pre_delete ) <EOL> def domain_pre_delete_receiver ( domain , ** kwargs ) : <EOL> from corehq . apps . domain . deletion import ModelDeletion , CustomDeletion <EOL> def _delete_ilsgateway_data ( domain_name ) : <EOL> locations_ids = SQLLocation . objects . filter ( domain = domain_name ) . values_list ( '<STR_LIT>' , flat = True ) <EOL> if not locations_ids : <EOL> return <EOL> DeliveryGroupReport . objects . filter ( location_id__in = locations_ids ) . delete ( ) <EOL> with connection . cursor ( ) as cursor : <EOL> cursor . execute ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , [ domain_name ] <EOL> ) <EOL> cursor . execute ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , [ domain_name ] <EOL> ) <EOL> cursor . execute ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , [ domain_name ] <EOL> ) <EOL> cursor . execute ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , [ domain_name ] <EOL> ) <EOL> cursor . execute ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , [ domain_name ] <EOL> ) <EOL> return [ <EOL> CustomDeletion ( '<STR_LIT>' , _delete_ilsgateway_data ) , <EOL> ModelDeletion ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ModelDeletion ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ModelDeletion ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> @ receiver ( location_edited ) <EOL> def location_edited_receiver ( sender , loc , moved , ** kwargs ) : <EOL> from custom . ilsgateway . utils import last_location_group <EOL> config = ILSGatewayConfig . for_domain ( loc . domain ) <EOL> if not config or not config . enabled : <EOL> return <EOL> last_run = ReportRun . last_success ( loc . domain ) <EOL> if not last_run : <EOL> return <EOL> if moved : <EOL> PendingReportingDataRecalculation . objects . create ( <EOL> domain = loc . domain , <EOL> type = '<STR_LIT>' , <EOL> sql_location = loc . sql_location , <EOL> data = { '<STR_LIT>' : loc . previous_parents [ - <NUM_LIT:1> ] , '<STR_LIT>' : loc . parent_id } <EOL> ) <EOL> group = last_location_group ( loc ) <EOL> if not loc . sql_location . location_type . administrative and group != loc . metadata [ '<STR_LIT>' ] : <EOL> PendingReportingDataRecalculation . objects . create ( <EOL> domain = loc . domain , <EOL> type = '<STR_LIT>' , <EOL> sql_location = loc . sql_location , <EOL> data = { '<STR_LIT>' : group , '<STR_LIT>' : loc . metadata [ '<STR_LIT>' ] } <EOL> ) </s>
