roefactura

package module
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

GOBL Romania

Released under the Apache 2.0 LICENSE, Copyright 2026 Invopop S.L..

Lint Test Go Go Report Card codecov GoDoc Latest Tag

GOBL add-on and converter for Romanian e-invoicing via RO e-Factura, the national system operated by ANAF (Agenția Națională de Administrare Fiscală).

How it works

The add-on ro-efactura-v1 registers itself with GOBL when its package is imported, and builds on the European eu-en16931-v2017 add-on, which it pulls in automatically. An invoice that declares it in $addons gets the Romanian treatment whenever GOBL runs over it: Calculate quietly fixes what can be fixed, and Validate refuses what ANAF would refuse, before any XML exists. The Invopop apps work with invoices that already have the add-on applied.

import (
	"github.com/invopop/gobl"
	_ "github.com/invopop/gobl.ro.anaf/addon"
)

The ro-efactura-v1 key is not yet in GOBL core's registry of approved external add-ons, so it is not offered as a $addons value in the JSON Schema. A document declaring it fails validation with add-on must be registered unless this package is imported.

Structure

addon/                The GOBL add-on (ro-efactura-v1): rules, normalizers, tags, document types
examples/             One invoice per case, with its calculated envelope under out/
resources/
├── artifacts/        The add-on map and the converter map
└── examples/         ANAF's official UBL and CII sample invoices
test/                 Conversion corpus of every invoice shape Romania accepts

The module root holds the converter and the tooling built on the add-on: FormatCIUSRO and FormatCIUSROCII (the UBL and CII formats ANAF checks), KindOf (what ANAF does with an invoice), Issuer and CIF (who an invoice is filed under). The routing that decides how ANAF receives an invoice lives in gov-ro.

Rules

The add-on adds 53 rules on top of GOBL and EN 16931, all under the GOBL-RO-EFACTURA- code prefix. Each one cites the BR-RO rule of Order MF 4092/2022 it implements, such as BR-RO-010. The full table, from BR-RO rule to GOBL code, and the official sources are in the add-on README.

Kind Rules What they check
Required 12 Fields ANAF needs, such as the seller's and the buyer's identifiers, the street and city of every party and the enforcement body
Code 7 Romanian codes and formats: document types, county and sector codes, the invoice number, the accounting currency, two decimals
Length 30 The BR-RO-L character limits on names, addresses, notes, items, allowances, charges and payment details
Count 4 The BR-RO-A limits on notes, preceding invoices, attachments and item attributes

On top of the rules come 3 normalizers, 2 tags of its own (accounting and enforcement), 5 document types (380, 381, 384, 389, 751) and the Autofactură scenario note. VAT rates belong to the Romanian tax regime in GOBL core, and VAT categories and VATEX codes to the EN 16931 add-on. Every rule, normalizer, tag and document type is listed in the add-on map.

Conversion

Function What it does
ForwardConvert Takes a GOBL envelope declaring the add-on, already calculated and validated with it as a silo entry is, and returns CIUS-RO UBL ready to upload
ReverseConvert Takes the XML of an invoice ANAF delivered, UBL or CII, and returns the GOBL invoice with the add-on applied

The two directions mirror each other, so an invoice sent and read back comes out the same. The round trip, and how each Romanian detail is written and read back, are in the converter map.

Testing

go test ./... is the whole check: the add-on's rules and normalizers, the examples, the converter, and the 191-invoice corpus in test, which drives every invoice through the add-on, the converter and ANAF's published schematron. The corpus needs phorm, which it looks for on localhost:9090 and fails loudly without. Routing is tested in gov-ro.

Command What it does
go test ./... Runs everything
go test ./... -count=1 Runs everything, ignoring Go's test cache
go test ./addon/... Runs only the add-on's unit tests
go test . -run TestExamples Checks the examples against their calculated envelopes
go test . -run TestExamples -update Rewrites the examples' calculated envelopes after an intended change
go test . Runs only the root tests: the converter, including the round trip and ANAF's samples, and the examples
go test ./test/... Runs only the conversion corpus
PHORM_URL=http://phorm:9090 go test ./... Points the corpus at phorm on another host or port
RO_SKIP_SCHEMATRON=1 go test ./... Runs offline, proving the add-on and the converter agree but no longer that ANAF would accept the result
Picking one case

Corpus subtests are named after the fixture file, without the extension. Anchor a single fixture with $, or ro_389_selfBilled also matches ro_389_selfBilledAccounting and the rest of its family.

Command What it does
go test ./test/... -run 'TestPipeline/ro_389_selfBilled$' -v Runs one fixture
go test ./test/... -run 'TestPipeline/ro_381' -v Runs every credit note
go test ./test/... -run 'TestPipeline/county' -v Runs the sweep of all 42 counties
go test . -run 'TestReverseConvertRoundTrip' -v Reads every accepted invoice back to GOBL and renders it again
Changing the corpus

test/out/ is rewritten on every run, so a change to the rendered XML shows up as a diff there. A new case is an envelope in test/data/ plus its entry in test/manifest.json: the suite fails on a fixture with no entry and on an entry with no fixture, so no case can be added without saying what it proves. The format is in the corpus README.

Before pushing

Run these three from the repo root. gofmt -l prints nothing when everything is formatted.

Command What it does
go test ./... Runs every test
gofmt -l . Lists any file that is not formatted
golangci-lint run ./... Runs the linters over the whole project

Documentation

Overview

Package roefactura is the root of the Romanian e-Factura module for GOBL. The GOBL addon itself lives in the addon subpackage; this root package holds the converter and the ANAF tooling built on top of it.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidDocument means the envelope does not carry a GOBL invoice
	// declaring the Romanian addon.
	ErrInvalidDocument = NewError("invalid_document")

	// ErrUnsupported means Romania does not accept a document of this kind.
	ErrUnsupported = NewError("unsupported")

	// ErrSkipped means the document is never reported to ANAF.
	ErrSkipped = NewError("skipped")

	// ErrConversion means the document could not be rendered.
	ErrConversion = NewError("conversion")

	// ErrUnreadable means a received document is not a UBL or CII invoice.
	ErrUnreadable = NewError("unreadable")
)
View Source
var (
	KindInvoice    = Kind{Name: "invoice", Code: efactura.DocumentTypeInvoice, Status: StatusAccepted}
	KindCreditNote = Kind{Name: "credit-note", Code: efactura.DocumentTypeCreditNote, Status: StatusAccepted}
	KindCorrective = Kind{Name: "corrective", Code: efactura.DocumentTypeCorrective, Status: StatusAccepted}
	KindSelfBilled = Kind{Name: "self-billed", Code: efactura.DocumentTypeSelfBilled, Status: StatusAccepted}
	KindAccounting = Kind{Name: "accounting", Code: efactura.DocumentTypeAccounting, Status: StatusAccepted}
)

Documents ANAF accepts, each with the UNTDID 1001 code the addon files it under.

View Source
var (
	KindProforma  = Kind{Name: "proforma", Status: StatusSkipped}
	KindDebitNote = Kind{Name: "debit-note", Status: StatusUnsupported}
	KindOther     = Kind{Name: "other", Status: StatusUnsupported}
)

Documents ANAF never receives.

View Source
var FormatCIUSRO = ubl.Format{
	Key:             "ubl+cius-ro-v1",
	Name:            i18n.NewString("UBL CIUS-RO"),
	Countries:       []l10n.Code{l10n.RO},
	Import:          []schema.ID{invoiceSchema},
	Export:          []schema.ID{invoiceSchema},
	CustomizationID: specificationCIUSRO,
	Addons:          []cbc.Key{efactura.V1},
	VESIDs: ubl.VESIDMapping{
		Invoice:    "ro.gov.mfinante.cius-ro:ubl-invoice:1.0.9",
		CreditNote: "ro.gov.mfinante.cius-ro:ubl-creditnote:1.0.9",
	},
	ExportFuncs: []ubl.ExportFunc{
		exportSchemaLocation,
		exportOrderReference,
		exportOutsideScope,
		exportSelfBillingNote,
	},
	ImportFuncs: []ubl.ImportFunc{
		importDocumentType,
		importOutsideScope,
		importParties,
		importPaymentMeans,
		importAttachmentNames,
		importTaxCurrency,
		importSelfBillingNote,
	},
}

FormatCIUSRO is the UBL format of the Romanian CIUS: the specification identifier, the addon that has to be declared to produce it, the schematrons published for it, and the export and import funcs, in export.go and import.go, that handle what gobl.ubl cannot decide on its own.

View Source
var FormatCIUSROCII = cii.Format{
	Key:         "cii+cius-ro-v1",
	Name:        i18n.NewString("CII CIUS-RO"),
	Countries:   []l10n.Code{l10n.RO},
	Import:      []schema.ID{invoiceSchema},
	GuidelineID: specificationCIUSRO,
	Version:     cii.VersionD16B,
	Addons:      []cbc.Key{efactura.V1},
	ImportFuncs: []cii.ImportFunc{
		importCIIDocumentType,
		importCIIOutsideScope,
		importCIIParties,
		importCIIPaymentMeans,
		importCIITaxCurrency,
		importCIISelfBillingNote,
	},
}

FormatCIUSROCII is the CII format of the Romanian CIUS, so the invoices read from CII declare the Romanian addon and get the same import funcs as UBL.

Functions

func CIF

func CIF(party *org.Party) string

CIF returns the tax number as the ANAF API wants it: the bare code, without the RO fiscal attribute. A party with no tax number, such as an enforcement body named by its legal registration identifier (BR-RO-130), gives that code instead, unless it is a personal number.

func ForwardConvert

func ForwardConvert(env *gobl.Envelope) ([]byte, error)

ForwardConvert renders the CIUS-RO document of a GOBL envelope. The envelope has to declare the Romanian addon and come calculated and validated with it, as a silo entry does, so it is converted as it is. Like any GOBL converter, rendering adjusts the envelope in place, such as rounding its amounts.

func Issuer

func Issuer(invoice *bill.Invoice) *org.Party

Issuer returns the party ANAF files a document under: the enforcement body named as payee for an enforcement invoice, the buyer for a self-billed one, and the supplier otherwise.

func ReverseConvert

func ReverseConvert(data []byte) (*bill.Invoice, error)

ReverseConvert reads a CIUS-RO document ANAF delivered, in UBL or CII, into a GOBL invoice with the addon applied. The import funcs of FormatCIUSRO and FormatCIUSROCII restore what the generic readers cannot know about Romania.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is the standard error type of the converter.

func NewError

func NewError(key string) *Error

NewError instantiates a new error with the given key.

func (*Error) Error

func (e *Error) Error() string

Error provides the string representation of the error.

func (*Error) Is

func (e *Error) Is(target error) bool

Is reports whether the target error shares this error's key.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the error that caused this error.

func (*Error) WithCause

func (e *Error) WithCause(cause error) *Error

WithCause returns a copy of the error wrapping the given cause.

func (*Error) WithMsg

func (e *Error) WithMsg(message string, args ...any) *Error

WithMsg returns a copy of the error carrying a message.

type Kind

type Kind struct {
	Name   string
	Code   cbc.Code
	Status Status
}

Kind is a document type as ANAF sees it, decided before the document is normalized so the caller can drop what will never be filed.

func KindOf

func KindOf(invoice *bill.Invoice) Kind

KindOf reports what Romania calls a GOBL invoice. It mirrors the addon's scenarios, which set the same codes once the document is calculated.

type Status

type Status string

Status tells the caller what Romania does with a document of a given kind.

const (
	StatusAccepted    Status = "accepted"
	StatusSkipped     Status = "skipped"
	StatusUnsupported Status = "unsupported"
)

The states a Kind can be in.

Directories

Path Synopsis
Package efactura implements the Romanian e-Factura rules as a GOBL addon, adding the RO_CIUS national rules (BR-RO) on top of the EU EN 16931 addon.
Package efactura implements the Romanian e-Factura rules as a GOBL addon, adding the RO_CIUS national rules (BR-RO) on top of the EU EN 16931 addon.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址