Coder Social home page Coder Social logo

Comments (10)

tofer avatar tofer commented on July 20, 2024 1

OK sounds good. I'll write up some tests and submit a pull request. Thanks for the fast responses.

from quickbooks-sync.

jsgoupil avatar jsgoupil commented on July 20, 2024

That is the magic code. The OwnerID of zero is reserved for custom fields. If you wanted to make it private data, you would use a GUID here, like this:

Yay for magic! Everybody loves magic. The types are controlled by the XML definition. Obviously, intuit likes to not follow it. I have changed it in the past, that's where we should start. I'll see how easy this one is.

from quickbooks-sync.

tofer avatar tofer commented on July 20, 2024

Leave it to Intuit, lol.

Would it be possible to add custom serialization to those properties instead, so it can serialize Guid.Empty to "0" instead of {00000000-0000-0000-0000-000000000000}?

from quickbooks-sync.

tofer avatar tofer commented on July 20, 2024

OK, I did another hack that didn't require changing the property type on the XSD generated types. I only did simple testing again, but your unit tests do pass, by modifying the GUIDTYPE class with some "magic zero" handling:

public partial class GUIDTYPE : ITypeWrapper, IComparable<GUIDTYPE>, IXmlSerializable
{
	protected Guid value;

	// Support for Intuit's "magic code" for OwnerID of "0"
	private bool _magicZero;

	public GUIDTYPE()
	{
		this.value = Guid.Empty;
	}

	public GUIDTYPE(string value)
	{
		this.value = Parse(value);
		if (value == "0") _magicZero = true;
	}

	public GUIDTYPE(Guid value)
	{
		this.value = value;
	}

	public override string ToString()
	{
		if (_magicZero && value == Guid.Empty)
		{
			return "0";
		}

		return value.ToString("B", CultureInfo.InvariantCulture);
	}

	public Guid ToGuid()
	{
		return value;
	}
	
	//...
	
	public void ReadXml(System.Xml.XmlReader reader)
	{
		reader.MoveToContent();
		var isEmptyElement = reader.IsEmptyElement;
		reader.ReadStartElement();
		if (!isEmptyElement)
		{
			var str = reader.ReadContentAsString();
			_magicZero = str == "0";
			value = Parse(str);

			reader.ReadEndElement();
		}
	}
	
	//...
}

With simple usage request.OwnerID = new [] { new GUIDTYPE("0") };

In theory, this would then still allow the same functionality in all other purposes, even still allowing {00000000-0000-0000-0000-000000000000} to be parsed without then outputting "0", but I'm obviously not as familiar with the rest of your library to know what ramifications this might have.

from quickbooks-sync.

jsgoupil avatar jsgoupil commented on July 20, 2024

I think that's a good alternative, do you think you can submit a pull request with some unit tests?

from quickbooks-sync.

tofer avatar tofer commented on July 20, 2024

This could arguably be simpler by always returning 0 for Guid.Empty. Do you have any insight on if that would cause issues for other uses of GUIDTYPE?

from quickbooks-sync.

jsgoupil avatar jsgoupil commented on July 20, 2024

I looked at all the usage of OwnerId and ... it's hard to tell how it should behave. Their documentation here: https://developer-static.intuit.com/qbSDK-current/Common/newOSR/index.html says

A GUIDTYPE value can be zero (0), or it can take the form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} where X is a hexadecimal digit. For example: {6B063959-81B0-4622-85D6-F548C8CCB517}

Now technically, 00000000-0000-0000-0000-000000000000 is a valid guid. So I think we should allow it. Especially if people started to use it, then we would break them.
So your magicZero idea code is a good idea.

from quickbooks-sync.

jsgoupil avatar jsgoupil commented on July 20, 2024

Make sure to not drop curling braces to keep consistency :)

from quickbooks-sync.

tofer avatar tofer commented on July 20, 2024

Pull request #27 made

from quickbooks-sync.

jsgoupil avatar jsgoupil commented on July 20, 2024

Merged.
Thanks!

from quickbooks-sync.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.