-
Notifications
You must be signed in to change notification settings - Fork 6
Add royalty mechanism #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| import process_report.invoices.invoice as invoice | ||
|
|
||
|
|
||
| @dataclass | ||
| class RoyaltyInvoice(invoice.Invoice): | ||
| name: str = "Royalties" | ||
| export_columns_list = [ # TODO: Confirm list of information we want to include in royalty report | ||
| invoice.INVOICE_DATE_FIELD, | ||
| invoice.PROJECT_FIELD, | ||
| invoice.PI_FIELD, | ||
| invoice.CLUSTER_NAME_FIELD, | ||
| invoice.INSTITUTION_FIELD, | ||
| invoice.SU_TYPE_FIELD, | ||
| invoice.BALANCE_FIELD, | ||
| invoice.ROYALTY_FIELD, | ||
| ] | ||
|
Comment on lines
+9
to
+18
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @joachimweyl @knikolla @naved001 Are we fine with these sets of columns for now for the royalty invoice? Are there any other info we want to provide to RH? |
||
|
|
||
| def _prepare_export(self): | ||
| self.export_data = self.data[~self.data[invoice.ROYALTY_FIELD].isna()] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
| @dataclass | ||
| class PrepaymentProcessor(discount_processor.DiscountProcessor): | ||
| IS_DISCOUNT_BY_NERC = True | ||
| IS_DISCOUNT_BY_NERC = False | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change was to address the fact that prepayments are still subject to the royalty. With this change, the prepay discount will no longer impact the This change will impact how the PI-specific invoices are exported, and as mentioned by @knikolla in slack, we may want to review how we handle these balance columns and refactor them. @knikolla @naved001 Given that we have no prepayments yet, are we fine with postponing refactoring the balance fields after this PR is merged? |
||
| PREPAY_DEBITS_S3_FILEPATH = "Prepay/prepay_debits.csv" | ||
|
|
||
| initializes_columns = ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from decimal import Decimal | ||
| import logging | ||
| from dataclasses import dataclass, field | ||
|
|
||
| from process_report.loader import loader | ||
| from process_report.settings import invoice_settings | ||
| from process_report.invoices import invoice | ||
| from process_report.processors import processor | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
| logging.basicConfig(level=logging.INFO) | ||
|
|
||
|
|
||
| @dataclass | ||
| class RoyaltyProcessor(processor.Processor): | ||
| """ | ||
| Given a percentage royalty rate and list of exemept institutions, creates a new `Royalty` column equal to `Balance` * royalty_rate | ||
| """ | ||
|
|
||
| royalty_rate: Decimal = invoice_settings.royalty_rate | ||
| royalty_exempt_institution_list: tuple[str] = field( | ||
| default_factory=loader.get_royalty_exempt_institutions_list | ||
| ) | ||
|
|
||
| initializes_columns = (invoice.ROYALTY_COLUMN,) | ||
| operates_on_columns = ( | ||
| *initializes_columns, | ||
| invoice.INSTITUTION_COLUMN, | ||
| invoice.IS_EXTERNALLY_FUNDED_COLUMN, | ||
| invoice.BALANCE_COLUMN, | ||
| ) | ||
|
|
||
| def _process(self): | ||
| non_moc_member_mask = ~self.data[invoice.INSTITUTION_FIELD].isin( | ||
| self.royalty_exempt_institution_list | ||
| ) | ||
| externally_funded_mask = self.data[invoice.INSTITUTION_FIELD].isin( | ||
| self.royalty_exempt_institution_list | ||
| ) & (self.data[invoice.IS_EXTERNALLY_FUNDED_FIELD] == True) # noqa: E712 | ||
|
|
||
| self.data[invoice.ROYALTY_FIELD] = ( | ||
| self.data[invoice.BALANCE_FIELD] * self.royalty_rate | ||
| ).where(non_moc_member_mask | externally_funded_mask) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joachimweyl @naved001 @knikolla Are we fine with
Falseas the default for this field. This will mean, if a Coldfront project does not specify theIs Externally Fundedattribute, invoicing will assume it is internally funded.