-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add basic structs for MX fuel complement #192
Changes from 3 commits
9499268
5fb582a
57f722c
e178705
87305b0
7b4ed40
653e8bc
4be0288
fccc293
5a3388e
a4a18e8
5112d09
ce4472f
86e2823
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,58 @@ | ||||||||||||||
// Package complements provides GOBL Complements for Mexican invoices | ||||||||||||||
package complements | ||||||||||||||
|
||||||||||||||
import ( | ||||||||||||||
"cloud.google.com/go/civil" | ||||||||||||||
"github.com/invopop/gobl/bill" | ||||||||||||||
"github.com/invopop/gobl/cbc" | ||||||||||||||
"github.com/invopop/gobl/num" | ||||||||||||||
"github.com/invopop/gobl/org" | ||||||||||||||
"github.com/invopop/gobl/tax" | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
// FuelComplement provides detailed information about fuel purchases made with | ||||||||||||||
// electronic wallets. In Mexico, e-wallet suppliers are required to report this | ||||||||||||||
// information as part of the invoices they issue to their customers. | ||||||||||||||
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. I think we need to reference here the exact name of the complement and version that will be generated as a result. 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. 👍 Addressed in 653e8bc |
||||||||||||||
type FuelComplement struct { | ||||||||||||||
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. When creating the structs of this complement, I considered two general approaches:
What do you think? 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. Agreed. I think we should at least try to smooth out the edges. |
||||||||||||||
// Customer's e-wallet account number | ||||||||||||||
WalletAccountNumber string `json:"wallet-account-number" jsonschema:"title=Wallet Account Number"` | ||||||||||||||
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. GOBL convention is to use 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. My oversight. Fixed on 7b4ed40. Good catch! |
||||||||||||||
// List of fuel purchases made with the customer's e-wallets | ||||||||||||||
Lines []*FuelLine `json:"lines" jsonschema:"title=Lines"` | ||||||||||||||
// Summary of all the purchases totals, including taxes (calculated) | ||||||||||||||
Totals bill.Totals `json:"totals" jsonschema:"title=Totals" jsonschema_extras:"calculated=true"` | ||||||||||||||
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. I'm reusing A penny for your thoughts! 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. I'm inclined to agree... this strikes me as a new structure alongside the complements. 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. I agree! Addressed in 4be0288 |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// FuelLine represents a single fuel purchase made with an e-wallet issued by | ||||||||||||||
// the invoice's supplier to the invoice's customer. | ||||||||||||||
type FuelLine struct { | ||||||||||||||
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. I used the "line" word because the whole structure resembles very much to the 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. I think we're okay recreating the structures for this use-case. FuelLine makes sense. |
||||||||||||||
// Identifier of the e-wallet used to make the purchase | ||||||||||||||
WalletID cbc.Code `json:"wallet-id" jsonschema:"title=Wallet Identifier"` | ||||||||||||||
// Date and time of the purchase | ||||||||||||||
PurchaseDateTime civil.DateTime `json:"purchase-date" jsonschema:"title=Purchase Date"` | ||||||||||||||
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. We don't have 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. 🤔 interesting. It might indeed be a good idea to have a 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. Ok! Leaving 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. Have you also considered two fields? I'm not convinced, and we'd still need a new type, but "Date" and "Time" types could make sense. 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. I was right now drafting a 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. I just pushed 5a3388e with a barebones |
||||||||||||||
// Tax ID (RFC) of the purchaser | ||||||||||||||
PurchaserTaxID cbc.Code `json:"purchaser-tax-id" jsonschema:"title=Purchaser's Tax ID"` | ||||||||||||||
// Code of the service station where the purchase was made | ||||||||||||||
ServiceStationCode cbc.Code `json:"service-station-code" jsonschema:"title=Service Station Code"` | ||||||||||||||
// Amount of fuel units purchased | ||||||||||||||
Quantity num.Amount `json:"quantity" jsonschema:"title=Quantity"` | ||||||||||||||
// Details about the fuel purchased | ||||||||||||||
Item FuelItem `json:"item" jsonschema:"title=Item"` | ||||||||||||||
// Identifier of the purchase (folio) | ||||||||||||||
PurchaseID cbc.Code `json:"purchase-id" jsonschema:"title=Purchase Identifier"` | ||||||||||||||
// Result of quantity multiplied by the item's price (calculated) | ||||||||||||||
Sum num.Amount `json:"sum" jsonschema:"title=Sum" jsonschema_extras:"calculated=true"` | ||||||||||||||
// Map of taxes applied to the purchase | ||||||||||||||
Taxes tax.Set `json:"taxes" jsonschema:"title=Taxes"` | ||||||||||||||
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. Reusing GOBL's |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// FuelItem provides the details of the fuel purchased. | ||||||||||||||
type FuelItem struct { | ||||||||||||||
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. As discussed in other parts of this PR, the similarity of this struct with 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. I'd be tempted to store the 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. I created a separate On the other hand, in the CFDI the line and item data are at the same level. So if you're not convinced by this approach, let me know and I'll flatten down here too. 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. I think I accidentally deleted your last comment here. Sorry for the mess, I'm bringing it back: @samlown said:
Finding the path of least resistance for users is the same design principle I'm trying to follow. Question is which path is that! From my perspective, one of the main benefits that GOBL brings to developers is providing them with a single unified language, with a consistent vocabulary and set of idioms and patterns that they can use across regimes. That's why I thought the least resistance path was modelling lines and items resembling the ones in GOBL. In any case, I'll propose an alternative version sticking as closely as possible to the original source structure with translated fields. |
||||||||||||||
// Reference unit of measure used in the price and the quantity | ||||||||||||||
Unit org.Unit `json:"unit" jsonschema:"title=Unit"` | ||||||||||||||
// Type of fuel (c_ClaveTipoCombustible codes) | ||||||||||||||
Type cbc.Code `json:"type,omitempty" jsonschema:"title=Type"` | ||||||||||||||
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. There are only a bunch of simple values that can be used here:
We can simply use a cbc.Code with explicit codes (and validate them), or go fancy and create a new type ( I opted for the simple solution, but I can see the merits of the meaningful key option. Any thoughts about this one? 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. Initial impression: I think unless there is a fuel type elsewhere, we can just use the code specific for this document. Given the local nature of this, I'm not as worried... I envisage most use-cases of this will be hard coded in code and very unlikely to use a front-end... my impression anyway. |
||||||||||||||
// Name of the fuel | ||||||||||||||
Name string `json:"name" jsonschema:"title=Name"` | ||||||||||||||
// Base price of a single unit of the fuel | ||||||||||||||
Price num.Amount `json:"price" jsonschema:"title=Price"` | ||||||||||||||
} |
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.
Not sure what's the best way of structuring complements. For the moment, I'm putting everything under a
complements
package within themx
path. Suggestions on how to better do this are welcome!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.
I'm not sure... if you imagine a user who needs to set up complements for multiple countries, they'd have to deal with the namespace collisions of
complements
in multiple places. Could be awkward. I'd also think about the final schema URL, I was thinking of:https://gobl.org/draft-0/regimes/mx/fuel-complement
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.
Thanks, Sam! Agreed, there's no need for a
complements
package. Moved it to the mainmx
package in e178705. I also generated the schema file in the URL that you advised in 87305b0.