Customer info in other language

Hi Anton, this works fine for other imports. The solution has to be simple. In theory (if I understand it correctly) if all strings (file, db) are encoded as UTF8, there should not be any reason to decode it to Unicode and encode it back. I think Python is smart enough to covert strings to UTF8 when you concat, replace them within ASCII strings.

Sent from mobile

On 25-Mar-2012, at 8:16 PM, AntonK <an...@gmail.com> wrote:

Anand,
all tables in my database already have CHARSET=utf8 (I've run the patch though - all the same). I think issue is somewhere in csv file reading part. Maybe charset must be explicitly specified in file_manager.py?

On Saturday, March 24, 2012 11:31:51 PM UTC+4, Anand Doshi wrote:
Hi Anton,

I think you should.
Use python wnf.py -d yourdbname -p patches.jan_mar_2012.convert_ to_utf8

*pls confirm the patch name.. In erpnext/patches/Jan_mar_2012 folder

I think thats the patch.

It converts your database tables to support utf8

Thanks,
Anand.



You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.

To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/cm0TDSTuvbwJ.

To post to this group, send email to wn…@googlegroups.com.

To unsubscribe from this group, send email to wnframework+un…@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.



You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.

To post to this group, send email to wn...@googlegroups.com.

To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

at relevant places ?


Pratik
On 25-Mar-2012, at 10:01 PM, Rushabh Mehta wrote:

Hi Anton, this works fine for other imports. The solution has to be simple. In theory (if I understand it correctly) if all strings (file, db) are encoded as UTF8, there should not be any reason to decode it to Unicode and encode it back. I think Python is smart enough to covert strings to UTF8 when you concat, replace them within ASCII strings.

Sent from mobile

On 25-Mar-2012, at 8:16 PM, AntonK an...@gmail.com wrote:

Anand,
all tables in my database already have CHARSET=utf8 (I’ve run the patch though - all the same). I think issue is somewhere in csv file reading part. Maybe charset must be explicitly specified in file_manager.py?

On Saturday, March 24, 2012 11:31:51 PM UTC+4, Anand Doshi wrote:
Hi Anton,
I think you should.
Use python wnf.py -d yourdbname -p patches.jan_mar_2012.convert_ to_utf8

*pls confirm the patch name… In erpnext/patches/Jan_mar_2012 folder

I think thats the patch.

It converts your database tables to support utf8

Thanks,
Anand.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/cm0TDSTuvbwJ.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py (line#63)?

This works for me A trip to Unicode · GitHub


Pratik
On 25-Mar-2012, at 10:01 PM, Rushabh Mehta wrote:

Hi Anton, this works fine for other imports. The solution has to be simple. In theory (if I understand it correctly) if all strings (file, db) are encoded as UTF8, there should not be any reason to decode it to Unicode and encode it back. I think Python is smart enough to covert strings to UTF8 when you concat, replace them within ASCII strings.

Sent from mobile

On 25-Mar-2012, at 8:16 PM, AntonK an...@gmail.com wrote:

Anand,
all tables in my database already have CHARSET=utf8 (I’ve run the patch though - all the same). I think issue is somewhere in csv file reading part. Maybe charset must be explicitly specified in file_manager.py?

On Saturday, March 24, 2012 11:31:51 PM UTC+4, Anand Doshi wrote:
Hi Anton,
I think you should.
Use python wnf.py -d yourdbname -p patches.jan_mar_2012.convert_ to_utf8

*pls confirm the patch name… In erpnext/patches/Jan_mar_2012 folder

I think thats the patch.

It converts your database tables to support utf8

Thanks,
Anand.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/cm0TDSTuvbwJ.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

I’ve tried it already. Error message:
Traceback (innermost last):
File “lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs
getattr(doclist, action.lower())()
File “lib/py/webnotes/model/doclist.py”, line 253, in submit
self.save()
File “lib/py/webnotes/model/doclist.py”, line 241, in save
self.run_method(‘validate’)
File “lib/py/webnotes/model/doclist.py”, line 197, in run_method
getattr(self.obj, method)()
File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 102, in validate
self.get_reconciliation_data()
File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 74, in get_reconciliation_data
self.convert_into_list(data)
File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 63, in convert_into_list
self.data.append([d.encode(“utf-8”) for d in s])
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xd0 in position 0: ordinal not in range(128)


On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:



Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

> Hi all,
> Thinking wild here.
> Do we have,
>
> # -- coding: utf-8 --
>

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py (line#63)?

This works for me https://gist.github.com/ 2198372

>
> –



You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.

To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/9rHOom2ATKgJ.

To post to this group, send email to wn...@googlegroups.com.

To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Hi Anton,
I meant, also replace “encode” with “decode”
On 25-Mar-2012, at 11:15 PM, AntonK wrote:

I’ve tried it already. Error message:
Traceback (innermost last): File “lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs getattr(doclist, action.lower())() File “lib/py/webnotes/model/doclist.py”, line 253, in submit self.save() File “lib/py/webnotes/model/doclist.py”, line 241, in save self.run_method(‘validate’) File “lib/py/webnotes/model/doclist.py”, line 197, in run_method getattr(self.obj, method)() File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 102, in validate self.get_reconciliation_data() File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 74, in get_reconciliation_data self.convert_into_list(data) File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 63, in convert_into_list self.data.append([d.encode(“utf-8”) for d in s]) UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xd0 in position 0: ordinal not in range(128)

On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:


Pratik Vyas
Twitter : @pdvyas
ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py (line#63)?

This works for me https://gist.github.com/ 2198372


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/9rHOom2ATKgJ.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Pratik,
Reading step now works I guess, but new problem is in write back to file stage:

Traceback (innermost last):
File “lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs
getattr(doclist, action.lower())()
File “lib/py/webnotes/model/doclist.py”, line 254, in submit
self.run_method(‘on_submit’)
File “lib/py/webnotes/model/doclist.py”, line 197, in run_method
getattr(self.obj, method)()
File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 197, in on_submit
self.do_stock_reco(is_submit = 1)
File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 170, in do_stock_reco
self.add_data_in_CSV(qty_diff, rate_diff)
File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 189, in add_data_in_CSV
file_manager.write_file(fname[1], out)
File “lib/py/webnotes/utils/file_manager.py”, line 214, in write_file
file.write(content)
UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u041f’ in position 79: ordinal not in range(128)


On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:



Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

> Hi all,
> Thinking wild here.
> Do we have,
>
> # -- coding: utf-8 --
>

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py (line#63)?

This works for me https://gist.github.com/ 2198372




You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.

To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/RuHtGipjwtAJ.

To post to this group, send email to wn...@googlegroups.com.

To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Great!

erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py

Line#189

replace

file_manager.write_file(fname[1], out)

by

file_manager.write_file(fname[1], out.encode(‘utf-8’))

That should bring balance to the Universe.

BTW, when you get all this working, please send a pull request / patch :slight_smile:

On 25-Mar-2012, at 11:21 PM, AntonK wrote:

Pratik,
Reading step now works I guess, but new problem is in write back to file stage:

Traceback (innermost last): File “lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs getattr(doclist, action.lower())() File “lib/py/webnotes/model/doclist.py”, line 254, in submit self.run_method(‘on_submit’) File “lib/py/webnotes/model/doclist.py”, line 197, in run_method getattr(self.obj, method)() File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 197, in on_submit self.do_stock_reco(is_submit = 1) File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 189, in add_data_in_CSV file_manager.write_file(fname[1], out) File “lib/py/webnotes/utils/file_manager.py”, line 214, in write_file file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u041f’ in position 79: ordinal not in range(128)

On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:


Pratik Vyas
Twitter : @pdvyas
ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py (line#63)?

This works for me https://gist.github.com/ 2198372


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/RuHtGipjwtAJ.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

It works now, thank you,
pulled request

On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:

Great!

erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py

Line#189

replace

file_manager.write_file(fname[ 1], out)

by

file_manager.write_file(fname[ 1], out.encode(‘utf-8’))

That should bring balance to the Universe.

BTW, when you get all this working, please send a pull request / patch :slight_smile:

On 25-Mar-2012, at 11:21 PM, AntonK wrote:

> Pratik,
> Reading step now works I guess, but new problem is in write back to file stage:
>
> Traceback (innermost last): File “lib/py/webnotes/widgets/form/ save.py”, line 40, in savedocs getattr(doclist, action.lower())() File “lib/py/webnotes/model/ doclist.py”, line 254, in submit self.run_method(‘on_submit’) File “lib/py/webnotes/model/ doclist.py”, line 197, in run_method getattr(self.obj, method)() File “erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py”, line 197, in on_submit self.do_stock_reco(is_submit = 1) File “erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py”, line 170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File “erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py”, line 189, in add_data_in_CSV file_manager.write_file(fname[ 1], out) File “lib/py/webnotes/utils/file_ manager.py”, line 214, in write_file file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u041f’ in position 79: ordinal not in range(128)
>
> On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:
>
> –
> Pratik Vyas
> Twitter : @pdvyas
> ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
> Website: https://www.erpnext.com
>
> On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:
>
> > Hi all,
> > Thinking wild here.
> > Do we have,
> >
> > # -- coding: utf-8 --
> >
>
> This comment is not required, pardon my brain damage due to exams.
>
> Anton,
> Can you try replacing
>
> [d.encode(“ascii”) for d in s]
>
> with
>
> [d.decode(“utf-8”) for d in s]
>
> in erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py (line#63)?
>
> This works for me https://gist.github.com/ 2198372




You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.

To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.

To post to this group, send email to wn...@googlegroups.com.

To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Great.
Item codes starting with ‘pi’ sound ultra cool to me :slight_smile:

On 25-Mar-2012, at 11:56 PM, AntonK wrote:

It works now, thank you,
pulled request

On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
Great!
erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py

Line#189

replace

file_manager.write_file(fname[ 1], out)

by

file_manager.write_file(fname[ 1], out.encode(‘utf-8’))

That should bring balance to the Universe.

BTW, when you get all this working, please send a pull request / patch :slight_smile:

On 25-Mar-2012, at 11:21 PM, AntonK wrote:

Pratik,
Reading step now works I guess, but new problem is in write back to file stage:

Traceback (innermost last): File “lib/py/webnotes/widgets/form/ save.py”, line 40, in savedocs getattr(doclist, action.lower())() File “lib/py/webnotes/model/ doclist.py”, line 254, in submit self.run_method(‘on_submit’) File “lib/py/webnotes/model/ doclist.py”, line 197, in run_method getattr(self.obj, method)() File “erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py”, line 197, in on_submit self.do_stock_reco(is_submit = 1) File “erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py”, line 170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File “erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py”, line 189, in add_data_in_CSV file_manager.write_file(fname[ 1], out) File “lib/py/webnotes/utils/file_ manager.py”, line 214, in write_file file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u041f’ in position 79: ordinal not in range(128)

On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:


Pratik Vyas
Twitter : @pdvyas
ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py (line#63)?

This works for me https://gist.github.com/ 2198372


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Great job guys :)…

For my understanding - did you try to remove both the "decode" and "encode" to see if it worked?

best,
Rushabh

On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas <pd…@erpnext.com> wrote:

Great.
Item codes starting with 'pi' sound ultra cool to me :)


On 25-Mar-2012, at 11:56 PM, AntonK wrote:

> It works now, thank you,
> pulled request
>
> On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
> Great!
> erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py
>
> Line#189
>
> replace
>
> file_manager.write_file(fname[ 1], out)
>
> by
>
> file_manager.write_file(fname[ 1], out.encode('utf-8'))
>
> That should bring balance to the Universe.
>
> BTW, when you get all this working, please send a pull request / patch :)
>
> On 25-Mar-2012, at 11:21 PM, AntonK wrote:
>
> > Pratik,
> > Reading step now works I guess, but new problem is in write back to file stage:
> >
> > Traceback (innermost last): File "lib/py/webnotes/widgets/form/ save.py", line 40, in savedocs getattr(doclist, action.lower())() File "lib/py/webnotes/model/ doclist.py", line 254, in submit self.run_method('on_submit') File "lib/py/webnotes/model/ doclist.py", line 197, in run_method getattr(self.obj, method)() File "erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py", line 197, in on_submit self.do_stock_reco(is_submit = 1) File "erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py", line 170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File "erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py", line 189, in add_data_in_CSV file_manager.write_file(fname[ 1], out) File "lib/py/webnotes/utils/file_ manager.py", line 214, in write_file file.write(content) UnicodeEncodeError: 'ascii' codec can't encode character u'\u041f' in position 79: ordinal not in range(128)

> >

> > On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:

> >

> > –

> > Pratik Vyas

> > Twitter : @pdvyas

> > ERPNext - World's most affordable ERP - (Rs 299 / $7 per user per month)

> > Website: https://www.erpnext.com

> >

> > On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

> >

> > > Hi all,

> > > Thinking wild here.

> > > Do we have,

> > >

> > > # -- coding: utf-8 --

> > >

> >

> > This comment is not required, pardon my brain damage due to exams.

> >

> > Anton,

> > Can you try replacing

> >

> > [d.encode("ascii") for d in s]

> >

> > with

> >

> > [d.decode("utf-8") for d in s]

> >

> > in erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py (line#63)?

> >

> > This works for me https://gist.github.com/ 2198372

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

>

> –

> You received this message because you are subscribed to the Google Groups "ERPNext Technical Forum" group.

> To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.

> To post to this group, send email to wn…@googlegroups.com.

> To unsubscribe from this group, send email to wnframework+un…@googlegroups.com.

> For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.









Pratik Vyas

Twitter : @pdvyas



ERPNext - World's most affordable ERP - (Rs 299 / $7 per user per month)

Website: https://www.erpnext.com





You received this message because you are subscribed to the Google Groups "ERPNext Technical Forum" group.

To post to this group, send email to wn…@googlegroups.com.

To unsubscribe from this group, send email to wnframework+un…@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.





You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.

To post to this group, send email to wn...@googlegroups.com.

To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

On 26-Mar-2012, at 9:41 AM, Rushabh Mehta wrote:

Great job guys :)…

For my understanding - did you try to remove both the “decode” and “encode” to see if it worked?

That depends on what you plan to do between reading and writing. :slight_smile:
To make sense of out of you the utf-8 you read, you’ll have to decode it otherwise what you see is raw codepoints.

So this is what you do,

  • Read a utf-8 encoded file., eg ‘\xd0\x9f001\n’
  • Decode it to Unicode. So you have u’\u041f001\n’
  • Do stuff with it.
  • To write it back as utf-8, you need to encode it as utf-8

best,
Rushabh

On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas pd...@erpnext.com wrote:
Great.
Item codes starting with ‘pi’ sound ultra cool to me :slight_smile:

On 25-Mar-2012, at 11:56 PM, AntonK wrote:

It works now, thank you,
pulled request

On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
Great!
erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py

Line#189

replace

file_manager.write_file(fname[ 1], out)

by

file_manager.write_file(fname[ 1], out.encode(‘utf-8’))

That should bring balance to the Universe.

BTW, when you get all this working, please send a pull request / patch :slight_smile:

On 25-Mar-2012, at 11:21 PM, AntonK wrote:

Pratik,
Reading step now works I guess, but new problem is in write back to file stage:

Traceback (innermost last): File “lib/py/webnotes/widgets/form/ save.py”, line 40, in savedocs getattr(doclist, action.lower())() File “lib/py/webnotes/model/ doclist.py”, line 254, in submit self.run_method(‘on_submit’) File “lib/py/webnotes/model/ doclist.py”, line 197, in run_method getattr(self.obj, method)() File “erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py”, line 197, in on_submit self.do_stock_reco(is_submit = 1) File “erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py”, line 170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File “erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py”, line 189, in add_data_in_CSV file_manager.write_file(fname[ 1], out) File “lib/py/webnotes/utils/file_ manager.py”, line 214, in write_file file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u041f’ in position 79: ordinal not in range(128)

On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:


Pratik Vyas
Twitter : @pdvyas
ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py (line#63)?

This works for me https://gist.github.com/ 2198372


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Pratik,



Does not answer my question. (if I had my PC would have tried it)



Python will "do the stuff" without much issues if all you have to do is
concat, compare, replace etc. The problem usually comes if your database
does not accept utf8 encoding
or if you file comes in a non ascii - non utf8 encoding.


(try doing this in your python prompt - open a file with the Russian string and concat it with another ascii string and write it back without decoding or encoding - Python will do it without sweat)

My understanding is that ascii encoding is a subset of utf8 - so when you do stuff to strings that are either ascii and utf8 encoded and write them back, all the encoding is preserved as it is.

I want to see what part of the code breaks the encoding.

best,
Rushabh

On Mon, Mar 26, 2012 at 10:00 AM, Pratik Vyas <pd...@gmail.com> wrote:

On 26-Mar-2012, at 9:41 AM, Rushabh Mehta wrote:

> Great job guys :)...
>
> For my understanding - did you try to remove both the "decode" and "encode" to see if it worked?
>
That depends on what you plan to do between reading and writing. :)
To make sense of out of you the utf-8 you read, you'll have to decode it otherwise what you see is raw codepoints.

So this is what you do,
* Read a utf-8 encoded file., eg '\xd0\x9f001\n'
* Decode it to Unicode. So you have u'\u041f001\n'
* Do stuff with it.
* To write it back as utf-8, you need to encode it as utf-8


> best,
> Rushabh
>
> On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas <pd...@erpnext.com> wrote:
> Great.
> Item codes starting with 'pi' sound ultra cool to me :)
>
>
> On 25-Mar-2012, at 11:56 PM, AntonK wrote:
>
> > It works now, thank you,
> > pulled request
> >
> > On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
> > Great!
> > erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py
> >
> > Line#189
> >
> > replace
> >
> > file_manager.write_file(fname[ 1], out)
> >
> > by
> >
> > file_manager.write_file(fname[ 1], out.encode('utf-8'))
> >
> > That should bring balance to the Universe.
> >
> > BTW, when you get all this working, please send a pull request / patch :)
> >
> > On 25-Mar-2012, at 11:21 PM, AntonK wrote:
> >
> > > Pratik,
> > > Reading step now works I guess, but new problem is in write back to file stage:
> > >
> > > Traceback (innermost last): File "lib/py/webnotes/widgets/form/ save.py", line 40, in savedocs getattr(doclist, action.lower())() File "lib/py/webnotes/model/ doclist.py", line 254, in submit self.run_method('on_submit') File "lib/py/webnotes/model/ doclist.py", line 197, in run_method getattr(self.obj, method)() File "erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py", line 197, in on_submit self.do_stock_reco(is_submit = 1) File "erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py", line 170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File "erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py", line 189, in add_data_in_CSV file_manager.write_file(fname[ 1], out) File "lib/py/webnotes/utils/file_ manager.py", line 214, in write_file file.write(content) UnicodeEncodeError: 'ascii' codec can't encode character u'\u041f' in position 79: ordinal not in range(128)

> > >

> > > On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:

> > >

> > > –

> > > Pratik Vyas

> > > Twitter : @pdvyas

> > > ERPNext - World's most affordable ERP - (Rs 299 / $7 per user per month)

> > > Website: https://www.erpnext.com

> > >

> > > On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

> > >

> > > > Hi all,

> > > > Thinking wild here.

> > > > Do we have,

> > > >

> > > > # -- coding: utf-8 --

> > > >

> > >

> > > This comment is not required, pardon my brain damage due to exams.

> > >

> > > Anton,

> > > Can you try replacing

> > >

> > > [d.encode("ascii") for d in s]

> > >

> > > with

> > >

> > > [d.decode("utf-8") for d in s]

> > >

> > > in erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py (line#63)?

> > >

> > > This works for me https://gist.github.com/ 2198372

> >

> >

> >

> >

> >

> >

> >

> >

> >

> >

> >

> >

> >

> >

> >

> >

> >

> > –

> > You received this message because you are subscribed to the Google Groups "ERPNext Technical Forum" group.

> > To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.

> > To post to this group, send email to wn…@googlegroups.com.

> > To unsubscribe from this group, send email to wnframework+un…@googlegroups.com.

> > For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

>

>

>

> –

> Pratik Vyas

> Twitter : @pdvyas

>

> ERPNext - World's most affordable ERP - (Rs 299 / $7 per user per month)

> Website: https://www.erpnext.com

>

> –

> You received this message because you are subscribed to the Google Groups "ERPNext Technical Forum" group.

> To post to this group, send email to wn…@googlegroups.com.

> To unsubscribe from this group, send email to wnframework+un…@googlegroups.com.

> For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

>

>

>

> –

> You received this message because you are subscribed to the Google Groups "ERPNext Technical Forum" group.

> To post to this group, send email to wn…@googlegroups.com.

> To unsubscribe from this group, send email to wnframework+un…@googlegroups.com.

> For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.





You received this message because you are subscribed to the Google Groups "ERPNext Technical Forum" group.

To post to this group, send email to wn…@googlegroups.com.

To unsubscribe from this group, send email to wnframework+un…@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.





You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.

To post to this group, send email to wn...@googlegroups.com.

To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Hi everyone,

As Rushabh said, the current code is incorrect:
self.data.append([d.encode(“ascii”) for d in s])

We just need to do this:
self.data.append(s)

encode causes unicode string to be converted into str string. i.e. byte string.
decode causes str sting to be converted into unicode string.
No need to encode a ‘str’ type, as it is already encoded. It will
throw UnicodeDecodeError if it finds that ‘str’ is already encoded.

Now, while writing the file: since while importing, the file is
already read as utf-8 encoded, i.e. as a byte string, doing this:
file_manager.write_file(fname[1], out.encode(‘utf-8’))
will cause a UnicodeDecodeError, since the out variable is of ‘str’ type.

If it is already encoded, and if we try to encode it in another
encoding, it casues UnicodeDecodeError. Hence,
file_manager.write_file(fname[1], out)
suffices.

@Anton:
The file with the single record, which you sent, was not encoded as utf-8.
It was showing a “?001” instead of “П001”

I replaced the item code with “П001” and saved it as a utf-8 encoded csv file.

I added this item in my test database. And then did the stock
reconciliation. It worked perfectly… I am attaching the output file
with this email.

In summary:

So the correct code is:
In stock_reconciliation.py in def convert_into_list(self, data): line 62

use
self.data.append(s)

instead of
self.data.append([d.encode(“ascii”) for d in s])

in file_manager.write_file(fname[1], out): line 188
use as it is
file_manager.write_file(fname[1], out)

In warehouse.py in get_bin: line 42:
use
bin = sql(“select name from tabBin where item_code = %s and
warehouse = %s”, (item_code, self.doc.name))

instead of
bin = sql(“select name from tabBin where item_code = ‘%s’ and
warehouse = ‘%s’” % (item_code, self.doc.name))

This solved the whole issue, when the csv file is encoded in ‘utf-8’
for non english languages. I tested this with the csv provided by
Anton and it worked…

I will push this release in master branch and you can try this out.

Thanks,
Anand.

On Mon, Mar 26, 2012 at 10:00 AM, Pratik Vyas pd...@gmail.com wrote:

On 26-Mar-2012, at 9:41 AM, Rushabh Mehta wrote:

Great job guys :)…

For my understanding - did you try to remove both the “decode” and “encode” to see if it worked?

That depends on what you plan to do between reading and writing. :slight_smile:
To make sense of out of you the utf-8 you read, you’ll have to decode it otherwise what you see is raw codepoints.

So this is what you do,

  • Read a utf-8 encoded file., eg ‘\xd0\x9f001\n’
  • Decode it to Unicode. So you have u’\u041f001\n’
  • Do stuff with it.
  • To write it back as utf-8, you need to encode it as utf-8

best,
Rushabh

On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas pd...@erpnext.com wrote:
Great.
Item codes starting with ‘pi’ sound ultra cool to me :slight_smile:

On 25-Mar-2012, at 11:56 PM, AntonK wrote:

It works now, thank you,
pulled request

On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
Great!
erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py

Line#189

replace

file_manager.write_file(fname[1], out)

by

file_manager.write_file(fname[1], out.encode(‘utf-8’))

That should bring balance to the Universe.

BTW, when you get all this working, please send a pull request / patch :slight_smile:

On 25-Mar-2012, at 11:21 PM, AntonK wrote:

Pratik,
Reading step now works I guess, but new problem is in write back to file stage:

Traceback (innermost last): File “lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs getattr(doclist, action.lower())() File “lib/py/webnotes/model/doclist.py”, line 254, in submit self.run_method(‘on_submit’) File “lib/py/webnotes/model/doclist.py”, line 197, in run_method getattr(self.obj, method)() File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 197, in on_submit self.do_stock_reco(is_submit = 1) File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 189, in add_data_in_CSV file_manager.write_file(fname[1], out) File “lib/py/webnotes/utils/file_manager.py”, line 214, in write_file file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u041f’ in position 79: ordinal not in range(128)

On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:


Pratik Vyas
Twitter : @pdvyas
ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py (line#63)?

This works for me A trip to Unicode · GitHub


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com

On 26-Mar-2012, at 10:31 AM, Rushabh Mehta wrote:

Pratik,

Does not answer my question. (if I had my PC would have tried it)

Python will “do the stuff” without much issues if all you have to do is concat, compare, replace etc. The problem usually comes if your database does not accept utf8 encoding or if you file comes in a non ascii - non utf8 encoding.

Agreed.

(try doing this in your python prompt - open a file with the Russian string and concat it with another ascii string and write it back without decoding or encoding - Python will do it without sweat)

My understanding is that ascii encoding is a subset of utf8 - so when you do stuff to strings that are either ascii and utf8 encoded and write them back, all the encoding is preserved as it is.

True. utf-8 being binary compatible with ascii explains that (all code points below 128 can be safely read as ascii).

I want to see what part of the code breaks the encoding.

I guess you mean, you want to check if such strings break other parts of the code when they reach there… If so, I agree, we need to test that.

best,
Rushabh

On Mon, Mar 26, 2012 at 10:00 AM, Pratik Vyas pd...@gmail.com wrote:

On 26-Mar-2012, at 9:41 AM, Rushabh Mehta wrote:

Great job guys :)…

For my understanding - did you try to remove both the “decode” and “encode” to see if it worked?

That depends on what you plan to do between reading and writing. :slight_smile:
To make sense of out of you the utf-8 you read, you’ll have to decode it otherwise what you see is raw codepoints.

So this is what you do,

  • Read a utf-8 encoded file., eg ‘\xd0\x9f001\n’
  • Decode it to Unicode. So you have u’\u041f001\n’
  • Do stuff with it.
  • To write it back as utf-8, you need to encode it as utf-8

best,
Rushabh

On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas pd...@erpnext.com wrote:
Great.
Item codes starting with ‘pi’ sound ultra cool to me :slight_smile:

On 25-Mar-2012, at 11:56 PM, AntonK wrote:

It works now, thank you,
pulled request

On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
Great!
erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py

Line#189

replace

file_manager.write_file(fname[ 1], out)

by

file_manager.write_file(fname[ 1], out.encode(‘utf-8’))

That should bring balance to the Universe.

BTW, when you get all this working, please send a pull request / patch :slight_smile:

On 25-Mar-2012, at 11:21 PM, AntonK wrote:

Pratik,
Reading step now works I guess, but new problem is in write back to file stage:

Traceback (innermost last): File “lib/py/webnotes/widgets/form/ save.py”, line 40, in savedocs getattr(doclist, action.lower())() File “lib/py/webnotes/model/ doclist.py”, line 254, in submit self.run_method(‘on_submit’) File “lib/py/webnotes/model/ doclist.py”, line 197, in run_method getattr(self.obj, method)() File “erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py”, line 197, in on_submit self.do_stock_reco(is_submit = 1) File “erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py”, line 170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File “erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py”, line 189, in add_data_in_CSV file_manager.write_file(fname[ 1], out) File “lib/py/webnotes/utils/file_ manager.py”, line 214, in write_file file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u041f’ in position 79: ordinal not in range(128)

On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:


Pratik Vyas
Twitter : @pdvyas
ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in erpnext/stock/doctype/stock_ reconciliation/stock_ reconciliation.py (line#63)?

This works for me https://gist.github.com/ 2198372


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Thanks Anand for clearing this. My guess was that the decode/encode was a relic of the system when mysql tables were not UTF8 encoded and we had mostly English users. Those days the only thing that used to break it were the ugly quotes " from ms word :slight_smile:

Sent from mobile

On 26-Mar-2012, at 10:46 AM, Anand Doshi an...@iwebnotes.com wrote:

Hi everyone,

As Rushabh said, the current code is incorrect:
self.data.append([d.encode(“ascii”) for d in s])

We just need to do this:
self.data.append(s)

encode causes unicode string to be converted into str string. i.e. byte string.
decode causes str sting to be converted into unicode string.
No need to encode a ‘str’ type, as it is already encoded. It will
throw UnicodeDecodeError if it finds that ‘str’ is already encoded.

Now, while writing the file: since while importing, the file is
already read as utf-8 encoded, i.e. as a byte string, doing this:
file_manager.write_file(fname[1], out.encode(‘utf-8’))
will cause a UnicodeDecodeError, since the out variable is of ‘str’ type.

If it is already encoded, and if we try to encode it in another
encoding, it casues UnicodeDecodeError. Hence,
file_manager.write_file(fname[1], out)
suffices.

@Anton:
The file with the single record, which you sent, was not encoded as utf-8.
It was showing a “?001” instead of “П001”

I replaced the item code with “П001” and saved it as a utf-8 encoded csv file.

I added this item in my test database. And then did the stock
reconciliation. It worked perfectly… I am attaching the output file
with this email.

In summary:

So the correct code is:
In stock_reconciliation.py in def convert_into_list(self, data): line 62

use
self.data.append(s)

instead of
self.data.append([d.encode(“ascii”) for d in s])

in file_manager.write_file(fname[1], out): line 188
use as it is
file_manager.write_file(fname[1], out)

In warehouse.py in get_bin: line 42:
use
bin = sql(“select name from tabBin where item_code = %s and
warehouse = %s”, (item_code, self.doc.name))

instead of
bin = sql(“select name from tabBin where item_code = ‘%s’ and
warehouse = ‘%s’” % (item_code, self.doc.name))

This solved the whole issue, when the csv file is encoded in ‘utf-8’
for non english languages. I tested this with the csv provided by
Anton and it worked…

I will push this release in master branch and you can try this out.

Thanks,
Anand.

On Mon, Mar 26, 2012 at 10:00 AM, Pratik Vyas pd...@gmail.com wrote:

On 26-Mar-2012, at 9:41 AM, Rushabh Mehta wrote:

Great job guys :)…

For my understanding - did you try to remove both the “decode” and “encode” to see if it worked?

That depends on what you plan to do between reading and writing. :slight_smile:
To make sense of out of you the utf-8 you read, you’ll have to decode it otherwise what you see is raw codepoints.

So this is what you do,

  • Read a utf-8 encoded file., eg ‘\xd0\x9f001\n’
  • Decode it to Unicode. So you have u’\u041f001\n’
  • Do stuff with it.
  • To write it back as utf-8, you need to encode it as utf-8

best,
Rushabh

On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas pd...@erpnext.com wrote:
Great.
Item codes starting with ‘pi’ sound ultra cool to me :slight_smile:

On 25-Mar-2012, at 11:56 PM, AntonK wrote:

It works now, thank you,
pulled request

On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
Great!
erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py

Line#189

replace

file_manager.write_file(fname[1], out)

by

file_manager.write_file(fname[1], out.encode(‘utf-8’))

That should bring balance to the Universe.

BTW, when you get all this working, please send a pull request / patch :slight_smile:

On 25-Mar-2012, at 11:21 PM, AntonK wrote:

Pratik,
Reading step now works I guess, but new problem is in write back to file stage:

Traceback (innermost last): File “lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs getattr(doclist, action.lower())() File “lib/py/webnotes/model/doclist.py”, line 254, in submit self.run_method(‘on_submit’) File “lib/py/webnotes/model/doclist.py”, line 197, in run_method getattr(self.obj, method)() File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 197, in on_submit self.do_stock_reco(is_submit = 1) File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 189, in add_data_in_CSV file_manager.write_file(fname[1], out) File “lib/py/webnotes/utils/file_manager.py”, line 214, in write_file file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u041f’ in position 79: ordinal not in range(128)

On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:


Pratik Vyas
Twitter : @pdvyas
ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py (line#63)?

This works for me A trip to Unicode · GitHub


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
Website: https://www.erpnext.com


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

<sr-2 (1).csv>


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Anand,
It is not working, your file contains utf-8 BOM, when I try to save Stock Reco it gives an error that item does not exists. I resaved file without BOM, document saved, but submit gives same encoding error:
Traceback
(innermost last):
File “lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs
getattr(doclist, action.lower())()
File “lib/py/webnotes/model/doclist.py”, line 254, in submit
self.run_method(‘on_submit’)
File “lib/py/webnotes/model/doclist.py”, line 197, in run_method
getattr(self.obj, method)()
File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”,
line 197, in on_submit
self.do_stock_reco(is_submit = 1)
File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”,
line 162, in do_stock_reco
self.make_sl_entry(is_submit, row, qty_diff, sys_stock)
File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”,
line 138, in make_sl_entry
get_obj(‘Stock Ledger’, ‘Stock Ledger’).update_stock(values)
File “erpnext/stock/doctype/stock_ledger/stock_ledger.py”, line 243,
in update_stock
get_obj(‘Warehouse’,
v[“warehouse”]).update_bin(flt(v[“actual_qty”]), 0, 0, 0, 0,
v[“item_code”], v[“posting_date”], sle_id, v[“posting_time”], ‘’,
v[“is_cancelled”],v[“voucher_type”],v[“voucher_no”], is_amended)
File “erpnext/stock/doctype/warehouse/warehouse.py”, line 75, in
update_bin
bin = self.get_bin(item_code)
File “erpnext/stock/doctype/warehouse/warehouse.py”, line 42, in
get_bin
bin = sql(“select name from tabBin where item_code = %s and
warehouse = %s” % (item_code, self.doc.name))
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xd0 in position
42: ordinal not in range(128)


Traceback (innermost last):
File “lib/py/webnotes/handler.py”, line 224, in handle
execute_cmd(cmd)
File “lib/py/webnotes/handler.py”, line 258, in execute_cmd
ret = method()
File “lib/py/webnotes/widgets/form/save.py”, line 54, in savedocs
raise e
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xd0 in position
42: ordinal not in range(128)

On Monday, March 26, 2012 9:16:23 AM UTC+4, Anand Doshi wrote:

Hi everyone,

As Rushabh said, the current code is incorrect:
self.data.append([d.encode(“ascii”) for d in s])

We just need to do this:
self.data.append(s)

encode causes unicode string to be converted into str string. i.e. byte string.
decode causes str sting to be converted into unicode string.
No need to encode a ‘str’ type, as it is already encoded. It will
throw UnicodeDecodeError if it finds that ‘str’ is already encoded.

Now, while writing the file: since while importing, the file is
already read as utf-8 encoded, i.e. as a byte string, doing this:
file_manager.write_file(fname[1], out.encode(‘utf-8’))
will cause a UnicodeDecodeError, since the out variable is of ‘str’ type.

If it is already encoded, and if we try to encode it in another
encoding, it casues UnicodeDecodeError. Hence,
file_manager.write_file(fname[1], out)
suffices.

@Anton:
The file with the single record, which you sent, was not encoded as utf-8.
It was showing a “?001” instead of “П001”

I replaced the item code with “П001” and saved it as a utf-8 encoded csv file.

I added this item in my test database. And then did the stock
reconciliation. It worked perfectly… I am attaching the output file
with this email.

In summary:

So the correct code is:
In stock_reconciliation.py in def convert_into_list(self, data): line 62

use
self.data.append(s)

instead of
self.data.append([d.encode(“ascii”) for d in s])

in file_manager.write_file(fname[1], out): line 188
use as it is
file_manager.write_file(fname[1], out)

In warehouse.py in get_bin: line 42:
use
bin = sql(“select name from tabBin where item_code = %s and <br>                warehouse = %s”, (item_code, self.doc.name))

instead of
bin = sql(“select name from tabBin where item_code = ‘%s’ and <br>                warehouse = ‘%s’” % (item_code, self.doc.name))

This solved the whole issue, when the csv file is encoded in ‘utf-8’
for non english languages. I tested this with the csv provided by
Anton and it worked…

I will push this release in master branch and you can try this out.

Thanks,
Anand.


On Mon, Mar 26, 2012 at 10:00 AM, Pratik Vyas <pd…@gmail.com> wrote:
>
>
> On 26-Mar-2012, at 9:41 AM, Rushabh Mehta wrote:
>
> > Great job guys :)…
> >
> > For my understanding - did you try to remove both the “decode” and “encode” to see if it worked?
> >
> That depends on what you plan to do between reading and writing. :slight_smile:
> To make sense of out of you the utf-8 you read, you’ll have to decode it otherwise what you see is raw codepoints.
>
> So this is what you do,
> * Read a utf-8 encoded file., eg ‘\xd0\x9f001\n’
> * Decode it to Unicode. So you have  u’\u041f001\n’
> * Do stuff with it.
> * To write it back as utf-8, you need to encode it as utf-8
>
>
> > best,
> > Rushabh
> >
> > On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas <pd…@erpnext.com> wrote:
> > Great.
> > Item codes starting with ‘pi’ sound ultra cool to me :slight_smile:
> >
> >
> > On 25-Mar-2012, at 11:56 PM, AntonK wrote:
> >
> > > It works now, thank you,
> > > pulled request
> > >
> > > On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
> > > Great!
> > > erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
> > >
> > > Line#189
> > >
> > > replace
> > >
> > > file_manager.write_file(fname[1], out)
> > >
> > > by
> > >
> > > file_manager.write_file(fname[1], out.encode(‘utf-8’))
> > >
> > > That should bring balance to the Universe.
> > >
> > > BTW, when you get all this working, please send a pull request / patch :slight_smile:
> > >
> > > On 25-Mar-2012, at 11:21 PM, AntonK wrote:
> > >
> > > > Pratik,
> > > > Reading step now works I guess, but new problem is in write back to file stage:
> > > >
> > > > Traceback (innermost last): File “lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs getattr(doclist, action.lower())() File “lib/py/webnotes/model/doclist.py”, line 254, in submit self.run_method(‘on_submit’) File “lib/py/webnotes/model/doclist.py”, line 197, in run_method getattr(self.obj, method)() File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 197, in on_submit self.do_stock_reco(is_submit = 1) File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 189, in add_data_in_CSV file_manager.write_file(fname[1], out) File “lib/py/webnotes/utils/file_manager.py”, line 214, in write_file file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u041f’ in position 79: ordinal not in range(128)
> > > >
> > > > On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:
> > > >
> > > > –
> > > > Pratik Vyas
> > > > Twitter : @pdvyas
> > > > ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
> > > > Website: https://www.erpnext.com
> > > >
> > > > On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:
> > > >
> > > > > Hi all,
> > > > > Thinking wild here.
> > > > > Do we have,
> > > > >
> > > > > # -- coding: utf-8 --
> > > > >
> > > >
> > > > This comment is not required, pardon my brain damage due to exams.
> > > >
> > > > Anton,
> > > > Can you try replacing
> > > >
> > > > [d.encode(“ascii”) for d in s]
> > > >
> > > > with
> > > >
> > > > [d.decode(“utf-8”) for d in s]
> > > >
> > > > in erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py (line#63)?
> > > >
> > > > This works for me https://gist.github.com/2198372



You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.

To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/q4WfKPuFXrMJ.

To post to this group, send email to wn...@googlegroups.com.

To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Hi Anton,

Please pull the master branch changes of webnotes/erpnext
From the error, I can see that your warehouse.py file is not updated.
I had already made the necessary changes to avoid this error.

Please pull and try again. Let me know if you are still facing the error.

Thanks,
Anand.

On Mon, Mar 26, 2012 at 10:01 PM, AntonK an...@gmail.com wrote:

Anand,
It is not working, your file contains utf-8 BOM, when I try to save Stock
Reco it gives an error that item does not exists. I resaved file without
BOM, document saved, but submit gives same encoding error:
Traceback (innermost last): File “lib/py/webnotes/widgets/form/save.py”,
line 40, in savedocs getattr(doclist, action.lower())() File
“lib/py/webnotes/model/doclist.py”, line 254, in submit
self.run_method(‘on_submit’) File “lib/py/webnotes/model/doclist.py”, line
197, in run_method getattr(self.obj, method)() File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
197, in on_submit self.do_stock_reco(is_submit = 1) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
162, in do_stock_reco self.make_sl_entry(is_submit, row, qty_diff,
sys_stock) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
138, in make_sl_entry get_obj(‘Stock Ledger’, ‘Stock
Ledger’).update_stock(values) File
“erpnext/stock/doctype/stock_ledger/stock_ledger.py”, line 243, in
update_stock get_obj(‘Warehouse’,
v[“warehouse”]).update_bin(flt(v[“actual_qty”]), 0, 0, 0, 0, v[“item_code”],
v[“posting_date”], sle_id, v[“posting_time”], ‘’,
v[“is_cancelled”],v[“voucher_type”],v[“voucher_no”], is_amended) File
“erpnext/stock/doctype/warehouse/warehouse.py”, line 75, in update_bin bin =
self.get_bin(item_code) File “erpnext/stock/doctype/warehouse/warehouse.py”,
line 42, in get_bin bin = sql(“select name from tabBin where item_code = %s
and warehouse = %s” % (item_code, self.doc.name)) UnicodeDecodeError:
‘ascii’ codec can’t decode byte 0xd0 in position 42: ordinal not in
range(128) ---------------- Traceback (innermost last): File
“lib/py/webnotes/handler.py”, line 224, in handle execute_cmd(cmd) File
“lib/py/webnotes/handler.py”, line 258, in execute_cmd ret = method() File
“lib/py/webnotes/widgets/form/save.py”, line 54, in savedocs raise e
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xd0 in position 42:
ordinal not in range(128)

On Monday, March 26, 2012 9:16:23 AM UTC+4, Anand Doshi wrote:

Hi everyone,

As Rushabh said, the current code is incorrect:
self.data.append([d.encode(“ascii”) for d in s])

We just need to do this:
self.data.append(s)

encode causes unicode string to be converted into str string. i.e. byte
string.
decode causes str sting to be converted into unicode string.
No need to encode a ‘str’ type, as it is already encoded. It will
throw UnicodeDecodeError if it finds that ‘str’ is already encoded.

Now, while writing the file: since while importing, the file is
already read as utf-8 encoded, i.e. as a byte string, doing this:
file_manager.write_file(fname[1], out.encode(‘utf-8’))
will cause a UnicodeDecodeError, since the out variable is of ‘str’ type.

If it is already encoded, and if we try to encode it in another
encoding, it casues UnicodeDecodeError. Hence,
file_manager.write_file(fname[1], out)
suffices.

@Anton:
The file with the single record, which you sent, was not encoded as utf-8.
It was showing a “?001” instead of “П001”

I replaced the item code with “П001” and saved it as a utf-8 encoded csv
file.

I added this item in my test database. And then did the stock
reconciliation. It worked perfectly… I am attaching the output file
with this email.

In summary:

So the correct code is:
In stock_reconciliation.py in def convert_into_list(self, data): line 62

use
self.data.append(s)

instead of
self.data.append([d.encode(“ascii”) for d in s])

in file_manager.write_file(fname[1], out): line 188
use as it is
file_manager.write_file(fname[1], out)

In warehouse.py in get_bin: line 42:
use
bin = sql(“select name from tabBin where item_code = %s and
warehouse = %s”, (item_code, self.doc.name))

instead of
bin = sql(“select name from tabBin where item_code = ‘%s’ and
warehouse = ‘%s’” % (item_code, self.doc.name))

This solved the whole issue, when the csv file is encoded in ‘utf-8’
for non english languages. I tested this with the csv provided by
Anton and it worked…

I will push this release in master branch and you can try this out.

Thanks,
Anand.

On Mon, Mar 26, 2012 at 10:00 AM, Pratik Vyas pd...@gmail.com wrote:

On 26-Mar-2012, at 9:41 AM, Rushabh Mehta wrote:

Great job guys :)…

For my understanding - did you try to remove both the “decode” and
“encode” to see if it worked?

That depends on what you plan to do between reading and writing. :slight_smile:
To make sense of out of you the utf-8 you read, you’ll have to decode it
otherwise what you see is raw codepoints.

So this is what you do,

  • Read a utf-8 encoded file., eg ‘\xd0\x9f001\n’
  • Decode it to Unicode. So you have u’\u041f001\n’
  • Do stuff with it.
  • To write it back as utf-8, you need to encode it as utf-8

best,
Rushabh

On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas pd...@erpnext.com
wrote:
Great.
Item codes starting with ‘pi’ sound ultra cool to me :slight_smile:

On 25-Mar-2012, at 11:56 PM, AntonK wrote:

It works now, thank you,
pulled request

On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
Great!
erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py

Line#189

replace

file_manager.write_file(fname[1], out)

by

file_manager.write_file(fname[1], out.encode(‘utf-8’))

That should bring balance to the Universe.

BTW, when you get all this working, please send a pull request /
patch :slight_smile:

On 25-Mar-2012, at 11:21 PM, AntonK wrote:

Pratik,
Reading step now works I guess, but new problem is in write back
to file stage:

Traceback (innermost last): File
“lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs
getattr(doclist, action.lower())() File “lib/py/webnotes/model/doclist.py”,
line 254, in submit self.run_method(‘on_submit’) File
“lib/py/webnotes/model/doclist.py”, line 197, in run_method
getattr(self.obj, method)() File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
197, in on_submit self.do_stock_reco(is_submit = 1) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
189, in add_data_in_CSV file_manager.write_file(fname[1], out) File
“lib/py/webnotes/utils/file_manager.py”, line 214, in write_file
file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character
u’\u041f’ in position 79: ordinal not in range(128)

On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:


Pratik Vyas
Twitter : @pdvyas
ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per
month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in
erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
(line#63)?

This works for me A trip to Unicode · GitHub


You received this message because you are subscribed to the Google Groups
“ERPNext Technical Forum” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/wnframework/-/q4WfKPuFXrMJ.

To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Anand,
after checkouting your changes I have another error when submitting Stock Reco:
Traceback
(innermost last):
File “lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs
getattr(doclist, action.lower())()
File “lib/py/webnotes/model/doclist.py”, line 241, in save
self.run_method(‘validate’)
File “lib/py/webnotes/model/doclist.py”, line 197, in run_method
getattr(self.obj, method)()
File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”,
line 102, in validate
self.get_reconciliation_data()
File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”,
line 74, in get_reconciliation_data
self.convert_into_list(data)
File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”,
line 59, in convert_into_list
self.validate_item(s[0], count)
File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”,
line 79, in validate_item
det = sql(“select item_code, has_serial_no from tabItem where name
= ‘%s’”% cstr(item), as_dict = 1)
File “lib/py/webnotes/db.py”, line 169, in sql
raise e
ProgrammingError: (1064, “You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near ‘Item Code’‘’ at line 1”)


Traceback (innermost last):
File “lib/py/webnotes/handler.py”, line 224, in handle
execute_cmd(cmd)
File “lib/py/webnotes/handler.py”, line 258, in execute_cmd
ret = method()
File “lib/py/webnotes/widgets/form/save.py”, line 54, in savedocs
raise e
ProgrammingError: (1064, “You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near ‘Item Code’‘’ at line 1”)

On Monday, March 26, 2012 9:16:23 AM UTC+4, Anand Doshi wrote:

Hi everyone,

As Rushabh said, the current code is incorrect:
self.data.append([d.encode(“ascii”) for d in s])

We just need to do this:
self.data.append(s)

encode causes unicode string to be converted into str string. i.e. byte string.
decode causes str sting to be converted into unicode string.
No need to encode a ‘str’ type, as it is already encoded. It will
throw UnicodeDecodeError if it finds that ‘str’ is already encoded.

Now, while writing the file: since while importing, the file is
already read as utf-8 encoded, i.e. as a byte string, doing this:
file_manager.write_file(fname[1], out.encode(‘utf-8’))
will cause a UnicodeDecodeError, since the out variable is of ‘str’ type.

If it is already encoded, and if we try to encode it in another
encoding, it casues UnicodeDecodeError. Hence,
file_manager.write_file(fname[1], out)
suffices.

@Anton:
The file with the single record, which you sent, was not encoded as utf-8.
It was showing a “?001” instead of “П001”

I replaced the item code with “П001” and saved it as a utf-8 encoded csv file.

I added this item in my test database. And then did the stock
reconciliation. It worked perfectly… I am attaching the output file
with this email.

In summary:

So the correct code is:
In stock_reconciliation.py in def convert_into_list(self, data): line 62

use
self.data.append(s)

instead of
self.data.append([d.encode(“ascii”) for d in s])

in file_manager.write_file(fname[1], out): line 188
use as it is
file_manager.write_file(fname[1], out)

In warehouse.py in get_bin: line 42:
use
bin = sql(“select name from tabBin where item_code = %s and <br>                warehouse = %s”, (item_code, self.doc.name))

instead of
bin = sql(“select name from tabBin where item_code = ‘%s’ and <br>                warehouse = ‘%s’” % (item_code, self.doc.name))

This solved the whole issue, when the csv file is encoded in ‘utf-8’
for non english languages. I tested this with the csv provided by
Anton and it worked…

I will push this release in master branch and you can try this out.

Thanks,
Anand.


On Mon, Mar 26, 2012 at 10:00 AM, Pratik Vyas <pd…@gmail.com> wrote:
>
>
> On 26-Mar-2012, at 9:41 AM, Rushabh Mehta wrote:
>
> > Great job guys :)…
> >
> > For my understanding - did you try to remove both the “decode” and “encode” to see if it worked?
> >
> That depends on what you plan to do between reading and writing. :slight_smile:
> To make sense of out of you the utf-8 you read, you’ll have to decode it otherwise what you see is raw codepoints.
>
> So this is what you do,
> * Read a utf-8 encoded file., eg ‘\xd0\x9f001\n’
> * Decode it to Unicode. So you have  u’\u041f001\n’
> * Do stuff with it.
> * To write it back as utf-8, you need to encode it as utf-8
>
>
> > best,
> > Rushabh
> >
> > On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas <pd…@erpnext.com> wrote:
> > Great.
> > Item codes starting with ‘pi’ sound ultra cool to me :slight_smile:
> >
> >
> > On 25-Mar-2012, at 11:56 PM, AntonK wrote:
> >
> > > It works now, thank you,
> > > pulled request
> > >
> > > On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
> > > Great!
> > > erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
> > >
> > > Line#189
> > >
> > > replace
> > >
> > > file_manager.write_file(fname[1], out)
> > >
> > > by
> > >
> > > file_manager.write_file(fname[1], out.encode(‘utf-8’))
> > >
> > > That should bring balance to the Universe.
> > >
> > > BTW, when you get all this working, please send a pull request / patch :slight_smile:
> > >
> > > On 25-Mar-2012, at 11:21 PM, AntonK wrote:
> > >
> > > > Pratik,
> > > > Reading step now works I guess, but new problem is in write back to file stage:
> > > >
> > > > Traceback (innermost last): File “lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs getattr(doclist, action.lower())() File “lib/py/webnotes/model/doclist.py”, line 254, in submit self.run_method(‘on_submit’) File “lib/py/webnotes/model/doclist.py”, line 197, in run_method getattr(self.obj, method)() File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 197, in on_submit self.do_stock_reco(is_submit = 1) File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 189, in add_data_in_CSV file_manager.write_file(fname[1], out) File “lib/py/webnotes/utils/file_manager.py”, line 214, in write_file file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u041f’ in position 79: ordinal not in range(128)
> > > >
> > > > On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:
> > > >
> > > > –
> > > > Pratik Vyas
> > > > Twitter : @pdvyas
> > > > ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
> > > > Website: https://www.erpnext.com
> > > >
> > > > On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:
> > > >
> > > > > Hi all,
> > > > > Thinking wild here.
> > > > > Do we have,
> > > > >
> > > > > # -- coding: utf-8 --
> > > > >
> > > >
> > > > This comment is not required, pardon my brain damage due to exams.
> > > >
> > > > Anton,
> > > > Can you try replacing
> > > >
> > > > [d.encode(“ascii”) for d in s]
> > > >
> > > > with
> > > >
> > > > [d.decode(“utf-8”) for d in s]
> > > >
> > > > in erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py (line#63)?
> > > >
> > > > This works for me https://gist.github.com/2198372
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > –
> > > You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
> > > To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.
> > > To post to this group, send email to wn…@googlegroups.com.
> > > To unsubscribe from this group, send email to wnframework+unsubscribe@googlegroups.com.
> > > For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.
> >
> >
> >
> > –
> > Pratik Vyas
> > Twitter : @pdvyas
> >
> > ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
> > Website: https://www.erpnext.com
> >
> > –
> > You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
> > To post to this group, send email to wn…@googlegroups.com.
> > To unsubscribe from this group, send email to wnframework+unsubscribe@googlegroups.com.
> > For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.
> >
> >
> >
> > –
> > You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
> > To post to this group, send email to wn…@googlegroups.com.
> > To unsubscribe from this group, send email to wnframework+unsubscribe@googlegroups.com.
> > For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.
>
> –
> You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
> To post to this group, send email to wn…@googlegroups.com.
> To unsubscribe from this group, send email to wnframework+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.
>


On Monday, March 26, 2012 9:16:23 AM UTC+4, Anand Doshi wrote:
Hi everyone,

As Rushabh said, the current code is incorrect:
self.data.append([d.encode(“ascii”) for d in s])

We just need to do this:
self.data.append(s)

encode causes unicode string to be converted into str string. i.e. byte string.
decode causes str sting to be converted into unicode string.
No need to encode a ‘str’ type, as it is already encoded. It will
throw UnicodeDecodeError if it finds that ‘str’ is already encoded.

Now, while writing the file: since while importing, the file is
already read as utf-8 encoded, i.e. as a byte string, doing this:
file_manager.write_file(fname[1], out.encode(‘utf-8’))
will cause a UnicodeDecodeError, since the out variable is of ‘str’ type.

If it is already encoded, and if we try to encode it in another
encoding, it casues UnicodeDecodeError. Hence,
file_manager.write_file(fname[1], out)
suffices.

@Anton:
The file with the single record, which you sent, was not encoded as utf-8.
It was showing a “?001” instead of “П001”

I replaced the item code with “П001” and saved it as a utf-8 encoded csv file.

I added this item in my test database. And then did the stock
reconciliation. It worked perfectly… I am attaching the output file
with this email.

In summary:

So the correct code is:
In stock_reconciliation.py in def convert_into_list(self, data): line 62

use
self.data.append(s)

instead of
self.data.append([d.encode(“ascii”) for d in s])

in file_manager.write_file(fname[1], out): line 188
use as it is
file_manager.write_file(fname[1], out)

In warehouse.py in get_bin: line 42:
use
bin = sql(“select name from tabBin where item_code = %s and <br>                warehouse = %s”, (item_code, self.doc.name))

instead of
bin = sql(“select name from tabBin where item_code = ‘%s’ and <br>                warehouse = ‘%s’” % (item_code, self.doc.name))

This solved the whole issue, when the csv file is encoded in ‘utf-8’
for non english languages. I tested this with the csv provided by
Anton and it worked…

I will push this release in master branch and you can try this out.

Thanks,
Anand.


On Mon, Mar 26, 2012 at 10:00 AM, Pratik Vyas <pd…@gmail.com> wrote:
>
>
> On 26-Mar-2012, at 9:41 AM, Rushabh Mehta wrote:
>
> > Great job guys :)…
> >
> > For my understanding - did you try to remove both the “decode” and “encode” to see if it worked?
> >
> That depends on what you plan to do between reading and writing. :slight_smile:
> To make sense of out of you the utf-8 you read, you’ll have to decode it otherwise what you see is raw codepoints.
>
> So this is what you do,
> * Read a utf-8 encoded file., eg ‘\xd0\x9f001\n’
> * Decode it to Unicode. So you have  u’\u041f001\n’
> * Do stuff with it.
> * To write it back as utf-8, you need to encode it as utf-8
>
>
> > best,
> > Rushabh
> >
> > On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas <pd…@erpnext.com> wrote:
> > Great.
> > Item codes starting with ‘pi’ sound ultra cool to me :slight_smile:
> >
> >
> > On 25-Mar-2012, at 11:56 PM, AntonK wrote:
> >
> > > It works now, thank you,
> > > pulled request
> > >
> > > On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
> > > Great!
> > > erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
> > >
> > > Line#189
> > >
> > > replace
> > >
> > > file_manager.write_file(fname[1], out)
> > >
> > > by
> > >
> > > file_manager.write_file(fname[1], out.encode(‘utf-8’))
> > >
> > > That should bring balance to the Universe.
> > >
> > > BTW, when you get all this working, please send a pull request / patch :slight_smile:
> > >
> > > On 25-Mar-2012, at 11:21 PM, AntonK wrote:
> > >
> > > > Pratik,
> > > > Reading step now works I guess, but new problem is in write back to file stage:
> > > >
> > > > Traceback (innermost last): File “lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs getattr(doclist, action.lower())() File “lib/py/webnotes/model/doclist.py”, line 254, in submit self.run_method(‘on_submit’) File “lib/py/webnotes/model/doclist.py”, line 197, in run_method getattr(self.obj, method)() File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 197, in on_submit self.do_stock_reco(is_submit = 1) File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File “erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line 189, in add_data_in_CSV file_manager.write_file(fname[1], out) File “lib/py/webnotes/utils/file_manager.py”, line 214, in write_file file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u041f’ in position 79: ordinal not in range(128)
> > > >
> > > > On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:
> > > >
> > > > –
> > > > Pratik Vyas
> > > > Twitter : @pdvyas
> > > > ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
> > > > Website: https://www.erpnext.com
> > > >
> > > > On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:
> > > >
> > > > > Hi all,
> > > > > Thinking wild here.
> > > > > Do we have,
> > > > >
> > > > > # -- coding: utf-8 --
> > > > >
> > > >
> > > > This comment is not required, pardon my brain damage due to exams.
> > > >
> > > > Anton,
> > > > Can you try replacing
> > > >
> > > > [d.encode(“ascii”) for d in s]
> > > >
> > > > with
> > > >
> > > > [d.decode(“utf-8”) for d in s]
> > > >
> > > > in erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py (line#63)?
> > > >
> > > > This works for me https://gist.github.com/2198372
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > –
> > > You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
> > > To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.
> > > To post to this group, send email to wn…@googlegroups.com.
> > > To unsubscribe from this group, send email to wnframework+unsubscribe@googlegroups.com.
> > > For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.
> >
> >
> >
> > –
> > Pratik Vyas
> > Twitter : @pdvyas
> >
> > ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per month)
> > Website: https://www.erpnext.com
> >
> > –
> > You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
> > To post to this group, send email to wn…@googlegroups.com.
> > To unsubscribe from this group, send email to wnframework+unsubscribe@googlegroups.com.
> > For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.
> >
> >
> >
> > –
> > You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
> > To post to this group, send email to wn…@googlegroups.com.
> > To unsubscribe from this group, send email to wnframework+unsubscribe@googlegroups.com.
> > For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.
>
> –
> You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
> To post to this group, send email to wn…@googlegroups.com.
> To unsubscribe from this group, send email to wnframework+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.
>



You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.

To view this discussion on the web visit https://groups.google.com/d/msg/wnframework/-/KPOOUIWAbgwJ.

To post to this group, send email to wn...@googlegroups.com.

To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Hi Anton,

I think the issue is caused when using sql(“… ‘%s’ …” %
(something)) instead of sql(“… %s …”, (something))

Try changing the syntax here and let me know. I will also look into it.

Thanks,
Anand.

On Mon, Mar 26, 2012 at 10:08 PM, AntonK an...@gmail.com wrote:

Anand,
after checkouting your changes I have another error when submitting Stock
Reco:
Traceback (innermost last): File “lib/py/webnotes/widgets/form/save.py”,
line 40, in savedocs getattr(doclist, action.lower())() File
“lib/py/webnotes/model/doclist.py”, line 241, in save
self.run_method(‘validate’) File “lib/py/webnotes/model/doclist.py”, line
197, in run_method getattr(self.obj, method)() File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
102, in validate self.get_reconciliation_data() File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
74, in get_reconciliation_data self.convert_into_list(data) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
59, in convert_into_list self.validate_item(s[0], count) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
79, in validate_item det = sql(“select item_code, has_serial_no from
tabItem where name = ‘%s’”% cstr(item), as_dict = 1) File
“lib/py/webnotes/db.py”, line 169, in sql raise e ProgrammingError: (1064,
“You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near ‘Item Code’‘’ at
line 1”) ---------------- Traceback (innermost last): File
“lib/py/webnotes/handler.py”, line 224, in handle execute_cmd(cmd) File
“lib/py/webnotes/handler.py”, line 258, in execute_cmd ret = method() File
“lib/py/webnotes/widgets/form/save.py”, line 54, in savedocs raise e
ProgrammingError: (1064, “You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax to
use near ‘Item Code’‘’ at line 1”)

On Monday, March 26, 2012 9:16:23 AM UTC+4, Anand Doshi wrote:

Hi everyone,

As Rushabh said, the current code is incorrect:
self.data.append([d.encode(“ascii”) for d in s])

We just need to do this:
self.data.append(s)

encode causes unicode string to be converted into str string. i.e. byte
string.
decode causes str sting to be converted into unicode string.
No need to encode a ‘str’ type, as it is already encoded. It will
throw UnicodeDecodeError if it finds that ‘str’ is already encoded.

Now, while writing the file: since while importing, the file is
already read as utf-8 encoded, i.e. as a byte string, doing this:
file_manager.write_file(fname[1], out.encode(‘utf-8’))
will cause a UnicodeDecodeError, since the out variable is of ‘str’ type.

If it is already encoded, and if we try to encode it in another
encoding, it casues UnicodeDecodeError. Hence,
file_manager.write_file(fname[1], out)
suffices.

@Anton:
The file with the single record, which you sent, was not encoded as utf-8.
It was showing a “?001” instead of “П001”

I replaced the item code with “П001” and saved it as a utf-8 encoded csv
file.

I added this item in my test database. And then did the stock
reconciliation. It worked perfectly… I am attaching the output file
with this email.

In summary:

So the correct code is:
In stock_reconciliation.py in def convert_into_list(self, data): line 62

use
self.data.append(s)

instead of
self.data.append([d.encode(“ascii”) for d in s])

in file_manager.write_file(fname[1], out): line 188
use as it is
file_manager.write_file(fname[1], out)

In warehouse.py in get_bin: line 42:
use
bin = sql(“select name from tabBin where item_code = %s and
warehouse = %s”, (item_code, self.doc.name))

instead of
bin = sql(“select name from tabBin where item_code = ‘%s’ and
warehouse = ‘%s’” % (item_code, self.doc.name))

This solved the whole issue, when the csv file is encoded in ‘utf-8’
for non english languages. I tested this with the csv provided by
Anton and it worked…

I will push this release in master branch and you can try this out.

Thanks,
Anand.

On Mon, Mar 26, 2012 at 10:00 AM, Pratik Vyas pd...@gmail.com wrote:

On 26-Mar-2012, at 9:41 AM, Rushabh Mehta wrote:

Great job guys :)…

For my understanding - did you try to remove both the “decode” and
“encode” to see if it worked?

That depends on what you plan to do between reading and writing. :slight_smile:
To make sense of out of you the utf-8 you read, you’ll have to decode it
otherwise what you see is raw codepoints.

So this is what you do,

  • Read a utf-8 encoded file., eg ‘\xd0\x9f001\n’
  • Decode it to Unicode. So you have u’\u041f001\n’
  • Do stuff with it.
  • To write it back as utf-8, you need to encode it as utf-8

best,
Rushabh

On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas pd...@erpnext.com
wrote:
Great.
Item codes starting with ‘pi’ sound ultra cool to me :slight_smile:

On 25-Mar-2012, at 11:56 PM, AntonK wrote:

It works now, thank you,
pulled request

On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
Great!
erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py

Line#189

replace

file_manager.write_file(fname[1], out)

by

file_manager.write_file(fname[1], out.encode(‘utf-8’))

That should bring balance to the Universe.

BTW, when you get all this working, please send a pull request /
patch :slight_smile:

On 25-Mar-2012, at 11:21 PM, AntonK wrote:

Pratik,
Reading step now works I guess, but new problem is in write back
to file stage:

Traceback (innermost last): File
“lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs
getattr(doclist, action.lower())() File “lib/py/webnotes/model/doclist.py”,
line 254, in submit self.run_method(‘on_submit’) File
“lib/py/webnotes/model/doclist.py”, line 197, in run_method
getattr(self.obj, method)() File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
197, in on_submit self.do_stock_reco(is_submit = 1) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
189, in add_data_in_CSV file_manager.write_file(fname[1], out) File
“lib/py/webnotes/utils/file_manager.py”, line 214, in write_file
file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character
u’\u041f’ in position 79: ordinal not in range(128)

On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:


Pratik Vyas
Twitter : @pdvyas
ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per
month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in
erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
(line#63)?

This works for me A trip to Unicode · GitHub


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per
month)
Website: https://www.erpnext.com


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.

On Monday, March 26, 2012 9:16:23 AM UTC+4, Anand Doshi wrote:

Hi everyone,

As Rushabh said, the current code is incorrect:
self.data.append([d.encode(“ascii”) for d in s])

We just need to do this:
self.data.append(s)

encode causes unicode string to be converted into str string. i.e. byte
string.
decode causes str sting to be converted into unicode string.
No need to encode a ‘str’ type, as it is already encoded. It will
throw UnicodeDecodeError if it finds that ‘str’ is already encoded.

Now, while writing the file: since while importing, the file is
already read as utf-8 encoded, i.e. as a byte string, doing this:
file_manager.write_file(fname[1], out.encode(‘utf-8’))
will cause a UnicodeDecodeError, since the out variable is of ‘str’ type.

If it is already encoded, and if we try to encode it in another
encoding, it casues UnicodeDecodeError. Hence,
file_manager.write_file(fname[1], out)
suffices.

@Anton:
The file with the single record, which you sent, was not encoded as utf-8.
It was showing a “?001” instead of “П001”

I replaced the item code with “П001” and saved it as a utf-8 encoded csv
file.

I added this item in my test database. And then did the stock
reconciliation. It worked perfectly… I am attaching the output file
with this email.

In summary:

So the correct code is:
In stock_reconciliation.py in def convert_into_list(self, data): line 62

use
self.data.append(s)

instead of
self.data.append([d.encode(“ascii”) for d in s])

in file_manager.write_file(fname[1], out): line 188
use as it is
file_manager.write_file(fname[1], out)

In warehouse.py in get_bin: line 42:
use
bin = sql(“select name from tabBin where item_code = %s and
warehouse = %s”, (item_code, self.doc.name))

instead of
bin = sql(“select name from tabBin where item_code = ‘%s’ and
warehouse = ‘%s’” % (item_code, self.doc.name))

This solved the whole issue, when the csv file is encoded in ‘utf-8’
for non english languages. I tested this with the csv provided by
Anton and it worked…

I will push this release in master branch and you can try this out.

Thanks,
Anand.

On Mon, Mar 26, 2012 at 10:00 AM, Pratik Vyas pd...@gmail.com wrote:

On 26-Mar-2012, at 9:41 AM, Rushabh Mehta wrote:

Great job guys :)…

For my understanding - did you try to remove both the “decode” and
“encode” to see if it worked?

That depends on what you plan to do between reading and writing. :slight_smile:
To make sense of out of you the utf-8 you read, you’ll have to decode it
otherwise what you see is raw codepoints.

So this is what you do,

  • Read a utf-8 encoded file., eg ‘\xd0\x9f001\n’
  • Decode it to Unicode. So you have u’\u041f001\n’
  • Do stuff with it.
  • To write it back as utf-8, you need to encode it as utf-8

best,
Rushabh

On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas pd...@erpnext.com
wrote:
Great.
Item codes starting with ‘pi’ sound ultra cool to me :slight_smile:

On 25-Mar-2012, at 11:56 PM, AntonK wrote:

It works now, thank you,
pulled request

On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
Great!
erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py

Line#189

replace

file_manager.write_file(fname[1], out)

by

file_manager.write_file(fname[1], out.encode(‘utf-8’))

That should bring balance to the Universe.

BTW, when you get all this working, please send a pull request /
patch :slight_smile:

On 25-Mar-2012, at 11:21 PM, AntonK wrote:

Pratik,
Reading step now works I guess, but new problem is in write back
to file stage:

Traceback (innermost last): File
“lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs
getattr(doclist, action.lower())() File “lib/py/webnotes/model/doclist.py”,
line 254, in submit self.run_method(‘on_submit’) File
“lib/py/webnotes/model/doclist.py”, line 197, in run_method
getattr(self.obj, method)() File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
197, in on_submit self.do_stock_reco(is_submit = 1) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
189, in add_data_in_CSV file_manager.write_file(fname[1], out) File
“lib/py/webnotes/utils/file_manager.py”, line 214, in write_file
file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character
u’\u041f’ in position 79: ordinal not in range(128)

On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:


Pratik Vyas
Twitter : @pdvyas
ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per
month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in
erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
(line#63)?

This works for me A trip to Unicode · GitHub


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per
month)
Website: https://www.erpnext.com


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups
“ERPNext Technical Forum” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/wnframework/-/KPOOUIWAbgwJ.

To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.

Hi Anton,

I have made the sql syntax changes. Can you try again.

Quick question, are you using openoffice or libreoffice for saving the
.csv file?

-Anand.

On Mon, Mar 26, 2012 at 10:17 PM, Anand Doshi an...@iwebnotes.com wrote:

Hi Anton,

I think the issue is caused when using sql(“… ‘%s’ …” %
(something)) instead of sql(“… %s …”, (something))

Try changing the syntax here and let me know. I will also look into it.

Thanks,
Anand.

On Mon, Mar 26, 2012 at 10:08 PM, AntonK an...@gmail.com wrote:

Anand,
after checkouting your changes I have another error when submitting Stock
Reco:
Traceback (innermost last): File “lib/py/webnotes/widgets/form/save.py”,
line 40, in savedocs getattr(doclist, action.lower())() File
“lib/py/webnotes/model/doclist.py”, line 241, in save
self.run_method(‘validate’) File “lib/py/webnotes/model/doclist.py”, line
197, in run_method getattr(self.obj, method)() File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
102, in validate self.get_reconciliation_data() File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
74, in get_reconciliation_data self.convert_into_list(data) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
59, in convert_into_list self.validate_item(s[0], count) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
79, in validate_item det = sql(“select item_code, has_serial_no from
tabItem where name = ‘%s’”% cstr(item), as_dict = 1) File
“lib/py/webnotes/db.py”, line 169, in sql raise e ProgrammingError: (1064,
“You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near ‘Item Code’‘’ at
line 1”) ---------------- Traceback (innermost last): File
“lib/py/webnotes/handler.py”, line 224, in handle execute_cmd(cmd) File
“lib/py/webnotes/handler.py”, line 258, in execute_cmd ret = method() File
“lib/py/webnotes/widgets/form/save.py”, line 54, in savedocs raise e
ProgrammingError: (1064, “You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax to
use near ‘Item Code’‘’ at line 1”)

On Monday, March 26, 2012 9:16:23 AM UTC+4, Anand Doshi wrote:

Hi everyone,

As Rushabh said, the current code is incorrect:
self.data.append([d.encode(“ascii”) for d in s])

We just need to do this:
self.data.append(s)

encode causes unicode string to be converted into str string. i.e. byte
string.
decode causes str sting to be converted into unicode string.
No need to encode a ‘str’ type, as it is already encoded. It will
throw UnicodeDecodeError if it finds that ‘str’ is already encoded.

Now, while writing the file: since while importing, the file is
already read as utf-8 encoded, i.e. as a byte string, doing this:
file_manager.write_file(fname[1], out.encode(‘utf-8’))
will cause a UnicodeDecodeError, since the out variable is of ‘str’ type.

If it is already encoded, and if we try to encode it in another
encoding, it casues UnicodeDecodeError. Hence,
file_manager.write_file(fname[1], out)
suffices.

@Anton:
The file with the single record, which you sent, was not encoded as utf-8.
It was showing a “?001” instead of “П001”

I replaced the item code with “П001” and saved it as a utf-8 encoded csv
file.

I added this item in my test database. And then did the stock
reconciliation. It worked perfectly… I am attaching the output file
with this email.

In summary:

So the correct code is:
In stock_reconciliation.py in def convert_into_list(self, data): line 62

use
self.data.append(s)

instead of
self.data.append([d.encode(“ascii”) for d in s])

in file_manager.write_file(fname[1], out): line 188
use as it is
file_manager.write_file(fname[1], out)

In warehouse.py in get_bin: line 42:
use
bin = sql(“select name from tabBin where item_code = %s and
warehouse = %s”, (item_code, self.doc.name))

instead of
bin = sql(“select name from tabBin where item_code = ‘%s’ and
warehouse = ‘%s’” % (item_code, self.doc.name))

This solved the whole issue, when the csv file is encoded in ‘utf-8’
for non english languages. I tested this with the csv provided by
Anton and it worked…

I will push this release in master branch and you can try this out.

Thanks,
Anand.

On Mon, Mar 26, 2012 at 10:00 AM, Pratik Vyas pd...@gmail.com wrote:

On 26-Mar-2012, at 9:41 AM, Rushabh Mehta wrote:

Great job guys :)…

For my understanding - did you try to remove both the “decode” and
“encode” to see if it worked?

That depends on what you plan to do between reading and writing. :slight_smile:
To make sense of out of you the utf-8 you read, you’ll have to decode it
otherwise what you see is raw codepoints.

So this is what you do,

  • Read a utf-8 encoded file., eg ‘\xd0\x9f001\n’
  • Decode it to Unicode. So you have u’\u041f001\n’
  • Do stuff with it.
  • To write it back as utf-8, you need to encode it as utf-8

best,
Rushabh

On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas pd...@erpnext.com
wrote:
Great.
Item codes starting with ‘pi’ sound ultra cool to me :slight_smile:

On 25-Mar-2012, at 11:56 PM, AntonK wrote:

It works now, thank you,
pulled request

On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
Great!
erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py

Line#189

replace

file_manager.write_file(fname[1], out)

by

file_manager.write_file(fname[1], out.encode(‘utf-8’))

That should bring balance to the Universe.

BTW, when you get all this working, please send a pull request /
patch :slight_smile:

On 25-Mar-2012, at 11:21 PM, AntonK wrote:

Pratik,
Reading step now works I guess, but new problem is in write back
to file stage:

Traceback (innermost last): File
“lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs
getattr(doclist, action.lower())() File “lib/py/webnotes/model/doclist.py”,
line 254, in submit self.run_method(‘on_submit’) File
“lib/py/webnotes/model/doclist.py”, line 197, in run_method
getattr(self.obj, method)() File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
197, in on_submit self.do_stock_reco(is_submit = 1) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
189, in add_data_in_CSV file_manager.write_file(fname[1], out) File
“lib/py/webnotes/utils/file_manager.py”, line 214, in write_file
file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character
u’\u041f’ in position 79: ordinal not in range(128)

On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:


Pratik Vyas
Twitter : @pdvyas
ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per
month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in
erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
(line#63)?

This works for me A trip to Unicode · GitHub


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per
month)
Website: https://www.erpnext.com


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.

On Monday, March 26, 2012 9:16:23 AM UTC+4, Anand Doshi wrote:

Hi everyone,

As Rushabh said, the current code is incorrect:
self.data.append([d.encode(“ascii”) for d in s])

We just need to do this:
self.data.append(s)

encode causes unicode string to be converted into str string. i.e. byte
string.
decode causes str sting to be converted into unicode string.
No need to encode a ‘str’ type, as it is already encoded. It will
throw UnicodeDecodeError if it finds that ‘str’ is already encoded.

Now, while writing the file: since while importing, the file is
already read as utf-8 encoded, i.e. as a byte string, doing this:
file_manager.write_file(fname[1], out.encode(‘utf-8’))
will cause a UnicodeDecodeError, since the out variable is of ‘str’ type.

If it is already encoded, and if we try to encode it in another
encoding, it casues UnicodeDecodeError. Hence,
file_manager.write_file(fname[1], out)
suffices.

@Anton:
The file with the single record, which you sent, was not encoded as utf-8.
It was showing a “?001” instead of “П001”

I replaced the item code with “П001” and saved it as a utf-8 encoded csv
file.

I added this item in my test database. And then did the stock
reconciliation. It worked perfectly… I am attaching the output file
with this email.

In summary:

So the correct code is:
In stock_reconciliation.py in def convert_into_list(self, data): line 62

use
self.data.append(s)

instead of
self.data.append([d.encode(“ascii”) for d in s])

in file_manager.write_file(fname[1], out): line 188
use as it is
file_manager.write_file(fname[1], out)

In warehouse.py in get_bin: line 42:
use
bin = sql(“select name from tabBin where item_code = %s and
warehouse = %s”, (item_code, self.doc.name))

instead of
bin = sql(“select name from tabBin where item_code = ‘%s’ and
warehouse = ‘%s’” % (item_code, self.doc.name))

This solved the whole issue, when the csv file is encoded in ‘utf-8’
for non english languages. I tested this with the csv provided by
Anton and it worked…

I will push this release in master branch and you can try this out.

Thanks,
Anand.

On Mon, Mar 26, 2012 at 10:00 AM, Pratik Vyas pd...@gmail.com wrote:

On 26-Mar-2012, at 9:41 AM, Rushabh Mehta wrote:

Great job guys :)…

For my understanding - did you try to remove both the “decode” and
“encode” to see if it worked?

That depends on what you plan to do between reading and writing. :slight_smile:
To make sense of out of you the utf-8 you read, you’ll have to decode it
otherwise what you see is raw codepoints.

So this is what you do,

  • Read a utf-8 encoded file., eg ‘\xd0\x9f001\n’
  • Decode it to Unicode. So you have u’\u041f001\n’
  • Do stuff with it.
  • To write it back as utf-8, you need to encode it as utf-8

best,
Rushabh

On Mon, Mar 26, 2012 at 12:11 AM, Pratik Vyas pd...@erpnext.com
wrote:
Great.
Item codes starting with ‘pi’ sound ultra cool to me :slight_smile:

On 25-Mar-2012, at 11:56 PM, AntonK wrote:

It works now, thank you,
pulled request

On Sunday, March 25, 2012 9:57:46 PM UTC+4, Pratik Vyas wrote:
Great!
erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py

Line#189

replace

file_manager.write_file(fname[1], out)

by

file_manager.write_file(fname[1], out.encode(‘utf-8’))

That should bring balance to the Universe.

BTW, when you get all this working, please send a pull request /
patch :slight_smile:

On 25-Mar-2012, at 11:21 PM, AntonK wrote:

Pratik,
Reading step now works I guess, but new problem is in write back
to file stage:

Traceback (innermost last): File
“lib/py/webnotes/widgets/form/save.py”, line 40, in savedocs
getattr(doclist, action.lower())() File “lib/py/webnotes/model/doclist.py”,
line 254, in submit self.run_method(‘on_submit’) File
“lib/py/webnotes/model/doclist.py”, line 197, in run_method
getattr(self.obj, method)() File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
197, in on_submit self.do_stock_reco(is_submit = 1) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
170, in do_stock_reco self.add_data_in_CSV(qty_diff, rate_diff) File
“erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py”, line
189, in add_data_in_CSV file_manager.write_file(fname[1], out) File
“lib/py/webnotes/utils/file_manager.py”, line 214, in write_file
file.write(content) UnicodeEncodeError: ‘ascii’ codec can’t encode character
u’\u041f’ in position 79: ordinal not in range(128)

On Sunday, March 25, 2012 9:15:24 PM UTC+4, Pratik Vyas wrote:


Pratik Vyas
Twitter : @pdvyas
ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per
month)
Website: https://www.erpnext.com

On 25-Mar-2012, at 10:05 PM, Pratik Vyas wrote:

Hi all,
Thinking wild here.
Do we have,

-- coding: utf-8 --

This comment is not required, pardon my brain damage due to exams.

Anton,
Can you try replacing

[d.encode(“ascii”) for d in s]

with

[d.decode(“utf-8”) for d in s]

in
erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
(line#63)?

This works for me A trip to Unicode · GitHub


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/wnframework/-/VmAyVN2bHR0J.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


Pratik Vyas
Twitter : @pdvyas

ERPNext - World’s most affordable ERP - (Rs 299 / $7 per user per
month)
Website: https://www.erpnext.com


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google
Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups
“ERPNext Technical Forum” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/wnframework/-/KPOOUIWAbgwJ.

To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to
wnframework+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/wnframework?hl=en.


You received this message because you are subscribed to the Google Groups “ERPNext Technical Forum” group.
To post to this group, send email to wn...@googlegroups.com.
To unsubscribe from this group, send email to wnframework+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/wnframework?hl=en.