Skip to content

Commit

Permalink
[IMP] datev_export_dtvf_nitrokey: References for tax advisor (#171)
Browse files Browse the repository at this point in the history
* [IMP] datev_export_dtvf_nitrokey: Try to get the best references for the financial advisor

* [FIX] Map to the account moves

* [FIX] fall back to refund reference

* Extend the booking text with the linked partner name
  • Loading branch information
fkantelberg authored Oct 15, 2024
1 parent fec789a commit 732e1e5
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions datev_export_dtvf_nitrokey/models/datev_export_dtvf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,54 @@
class DatevExportDtvfExport(models.Model):
_inherit = "datev_export_dtvf.export"

def _get_matching_references(self, move, ref1, ref2):
# Incoming invoices will use the vendor reference
if move.move_type.startswith("in_"):
return move.ref, ref1

# Outgoing invoices will use the sale.order reference
if move.move_type == "out_invoice" and move.invoice_origin:
return move.invoice_origin, ref1

# Outgoing refunds will use the sale.order reference from the reversed invoice
if move.move_type == "out_refund" and move.reversed_entry_id.invoice_origin:
return move.reversed_entry_id.invoice_origin, ref1

# Use refund reference if unequal to ref1
if move.move_type == "out_refund" and move.name != ref1:
return move.name, ref1

# All non-entry will use the default
if move.move_type != "entry":
return ref1, ref2

# Try to find the reconciled invoices
matching = move.mapped("line_ids.full_reconcile_id.reconciled_line_ids.move_id")
if not matching:
return ref1, ref2

# First invoices if possible
domain = [("move_type", "=like", "%_invoice")]
invs = matching.filtered_domain(domain)
if len(invs) == 1:
return self._get_matching_references(invs, ref1, ref2)

# Fall back to refunds if possible
domain = [("move_type", "=like", "%_refund")]
invs = matching.filtered_domain(domain)
if len(invs) == 1:
return self._get_matching_references(
invs.reversed_entry_id or invs, ref1, ref2
)

# Fall back to the default
return ref1, ref2

def _get_data_transaction(self, move):
"""Try to export whatever looks like an SO number as "Belegfeld 1" """
for data in super()._get_data_transaction(move):
for line in move.line_ids:
for field_name in ("ref", "name", "move_name"):
for token in (line[field_name] or "").split():
if (
token.startswith("SO")
or token.startswith("EK")
or token.startswith("GSV")
):
data["Belegfeld 1"] = token
ref1, ref2 = self._get_matching_references(move, move.name, "")
data.update({"Belegfeld 1": ref1, "Belegfeld 2": ref2})

if move.partner_id.name:
data["Buchungstext"] += " " + move.partner_id.name
yield data

0 comments on commit 732e1e5

Please sign in to comment.