~jfb-tempo-consulting/unifield-wm/sync-cur

« back to all changes in this revision

Viewing changes to mkdb.py

  • Committer: jftempo
  • Date: 2016-10-04 18:05:32 UTC
  • Revision ID: jfb@tempo-consulting.fr-20161004180532-lh3ro2rucg1s33ly
[IMP] Add currency rates

Show diffs side-by-side

added added

removed removed

Lines of Context:
848
848
                    prod.write([copy_id], {'name': newcode})
849
849
                msfid += 10
850
850
 
 
851
    def test_41_load_rates(self):
 
852
        cur_dir = os.path.realpath(__file__)
 
853
        rate_file = os.path.join(cur_dir, '%s.txt' % config.currency)
 
854
        if os.path.isfile(rate_file):
 
855
            rate_obj = self.db.get('res.currency')
 
856
            fx_rate_obj = self.db.get('res.currency.rate')
 
857
            rate_ids = rate_obj.search([('active', 'in', ['t', 'f'])])
 
858
            rate_dict = {}
 
859
            for x in rate_obj.read(rate_ids, ['name']):
 
860
                rate_dict[x['name']] = x['id']
 
861
            fx_rate_obj.create({'currency_id': rate_dict[config.currency.upper()], 'rate': 1, 'name': '2016-01-01'})
 
862
            f = open(rate_file, 'r')
 
863
            date = False
 
864
            for data in f.read():
 
865
                if data[0]:
 
866
                    date = data[0]
 
867
                elif data[0] == ' ' and ':' in data:
 
868
                    cur, rate = data[1:].split(':')
 
869
                    if rate_dict.get(cur):
 
870
                        fx_rate_obj.create({'currency_id': rate_dict[cur], 'rate': rate, 'name': date})
 
871
 
 
872
 
 
873
 
851
874
    @unittest.skipIf(skipManualConfig, "Manual link on analytic account destination desactivated")
852
875
    def test_43_manual_link_on_analytic_account_destination(self):
853
876
        self.db.connect('admin')