Skip to content
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

Merge 16.0 & add 16.0-negative-unit-price-hook #2

Merged
merged 5 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion account_invoice_facturx/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,12 @@ def _set_iline_product_attributes(self, iline, trade_product, ns):
)
origin_trade_country_code.text = product.origin_country_id.code

def _cii_allow_negative_unit_prices(self):
"""Although not valid per the Factur-X standard, override this and return true
to allow invoice lines with negative unit prices in specific cases.
"""
return False

def _cii_add_invoice_line_block(self, trade_transaction, iline, line_number, ns):
self.ensure_one()
line_item = etree.SubElement(
Expand All @@ -682,7 +688,11 @@ def _cii_add_invoice_line_block(self, trade_transaction, iline, line_number, ns)
line_trade_agreement = etree.SubElement(
line_item, ns["ram"] + "SpecifiedLineTradeAgreement"
)
if float_compare(iline.price_unit, 0, precision_digits=ns["price_prec"]) < 0:
if (
not self._cii_allow_negative_unit_prices()
and float_compare(iline.price_unit, 0, precision_digits=ns["price_prec"])
< 0
):
raise UserError(
_(
"The Factur-X standard specify that unit prices can't be "
Expand Down
2 changes: 1 addition & 1 deletion account_invoice_facturx/models/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _render_qweb_pdf_prepare_streams(self, report_ref, data, res_ids=None):
collected_streams
and res_ids
and len(res_ids) == 1
and report_ref in invoice_reports
and self._get_report(report_ref).report_name in invoice_reports
and not self.env.context.get("no_embedded_factur-x_xml")
):
move = amo.browse(res_ids)
Expand Down
7 changes: 6 additions & 1 deletion account_invoice_facturx/tests/test_facturx_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ def setUp(self):
"unece_categ_id": self.env.ref("account_tax_unece.tax_categ_s").id,
}
)
partner = self.env.ref("base.res_partner_2")
# Reset payment method to avoid conflict with account_banking_sepa_direct_debit
partner.customer_payment_mode_id = self.env.ref(
"account_payment_mode.payment_mode_inbound_ct1"
)
self.invoice = self.env["account.move"].create(
{
"company_id": self.company.id,
"move_type": "out_invoice",
"partner_id": self.env.ref("base.res_partner_2").id,
"partner_id": partner.id,
"currency_id": self.company.currency_id.id,
"invoice_line_ids": [
(
Expand Down