xero-gateway/xero_gateway

Discounts not reflected in response object

Closed this issue · 2 comments

In sanity-checking the results of using this gem to pull Xero data into our app, I noticed a price discrepancy between what the gem gave me vs what the Xero website said. Digging in, I discovered that the invoice in question had a 10% discount code applied to it which wasn't reflected in the XeroGateway::Invoice or XeroGateway::LineItem objects.

Here's the line item XML in the response object:

      <LineItems>
        <LineItem>
          <Description>Job Ad (30 days)</Description>
          <UnitAmount>375.00</UnitAmount>
          <TaxType>NONE</TaxType>
          <TaxAmount>0.00</TaxAmount>
          <LineAmount>1687.50</LineAmount>
          <AccountCode>4101</AccountCode>
          <Quantity>5.0000</Quantity>
          <DiscountRate>10.00</DiscountRate>
          <LineItemID>[SNIP]</LineItemID>
        </LineItem>
      </LineItems>

Compared to the values exposed through the gem:

pp resp.response_item.line_items; nil
[#<XeroGateway::LineItem:0x007fc108e4f400
  @account_code="4101",
  @description="Job Ad (30 days)",
  @errors=[],
  @line_item_id="[SNIP]",
  @quantity=0.5e1,
  @tax_amount=0.0,
  @tax_type="NONE",
  @tracking=[],
  @unit_amount=0.375e3>]

pp resp.response_item.line_items.map(&:line_amount)
[0.1875e4]

Looking at the underlying code, I don't see anything that reads in the discount information, and XeroGateway::LineItem#line_amount performs its calculation using quantity and unit amount rather than the underlying line amount attribute in the XML.

Right now, I can only fetch the discount information by manually parsing XeroGateway::Response#response_xml and stitching things together, but ideally the gem itself would surface this information.

nikz commented

Hiya Patrick,

Hmmm, thanks for that 😄 IIRC discounts weren't actually A Thing™ in Xero when this particular piece of code was first written (negative line items FTW!)

Shouldn't be too hard to add, let me know if you want to give it a shot or I'm happy to when I next have some free time.

Cheers,

Nik

Ack. I'd love to contribute, but I don't have the capacity at the moment.