Guest User

Untitled

a guest
Nov 15th, 2018
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from trytond.model import ModelView, ModelSQL, fields
  2. from trytond_gis import fields as geofields
  3.  
  4. from trytond.modules.geotools.tools import bbox_aspect
  5. from trytond.modules.qgis.qgis import QGis
  6. from trytond.modules.qgis.mapable import Mapable
  7. from trytond.pyson import Bool, Eval, Not, Or, And, Equal, In, If, Id
  8. from trytond.wizard import Wizard
  9. from trytond.pool import Pool
  10. from trytond.transaction import Transaction
  11.  
  12. __all__ = ['Region', 'RegionQGis', 'GenerateR']
  13.  
  14.  
  15. class Region(Mapable, ModelSQL, ModelView):
  16. u'Région Française'
  17. __name__ = 'fr.region'
  18. _rec_name ='nom'
  19.  
  20. name = fields.Function(
  21. fields.Char(
  22. 'Name',
  23. readonly=True),
  24. 'get_name'
  25. )
  26.  
  27. def get_name(self, ids):
  28. u'Displayed name in the form: name (region code)'
  29. return '%s (%s)' % (self.nom, self.code)
  30.  
  31. def get_rec_name(self, ids):
  32. u'Displayed name in the form: name (region code)'
  33. return '%s (%s)' % (self.nom, self.code)
  34.  
  35. @classmethod
  36. def search_rec_name(cls, name, clause):
  37. regions = cls.search([('code',) + clause[1:]], order=[])
  38. if regions:
  39. return [('id', 'in', [region.id for region in regions])]
  40. return [('nom',) + clause[1:]]
  41.  
  42. nom = fields.Char(
  43. string=u'Région',
  44. help=u'Région française',
  45. required=True,
  46. select=True
  47. )
  48. code = fields.Char(
  49. string=u'Code région',
  50. help=u'Code de la région',
  51. select=True
  52. )
  53. version = fields.Date(
  54. string=u'Date de version',
  55. help=u'Date de version',
  56. )
  57. geom = geofields.MultiPolygon(
  58. string=u'Géométrie'
  59. )
  60. region_image = fields.Function(
  61. fields.Binary(
  62. 'Image'
  63. ),
  64. 'get_image'
  65. )
  66. region_map = fields.Binary(
  67. string=u'Carte',
  68. help=u'Régions'
  69. )
  70. active = fields.Boolean(
  71. 'Active'
  72. )
  73.  
  74. @staticmethod
  75. def default_active():
  76. return True
  77.  
  78. COLOR = (1, 0.1, 0.1, 1)
  79. BGCOLOR = (1, 0.1, 0.1, 0.4)
  80.  
  81. def get_image(self, ids):
  82. print("get_image", ids)
  83. return self._get_image('region_image.qgs', 'carte')
  84.  
  85. def get_map(self, ids):
  86. print("get_map", ids)
  87. return self._get_image('region_map.qgs', 'carte')
  88.  
  89. @classmethod
  90. def __setup__(cls):
  91. super(Region, cls).__setup__()
  92. cls._buttons.update({
  93. 'region_edit': {},
  94. 'generate': {},
  95. })
  96.  
  97. @classmethod
  98. @ModelView.button_action('fr.report_region_edit')
  99. def region_edit(cls, ids):
  100. pass
  101.  
  102. @classmethod
  103. @ModelView.button
  104. def generate(cls, records):
  105. for record in records:
  106. if record.nom is None:
  107. continue
  108. print("record", record)
  109. cls.write([record], {'region_map': cls.get_map(record, 'map')})
  110.  
  111. class RegionQGis(QGis):
  112. __name__ = 'fr.region.qgis'
  113. TITLES = {'fr.region': u'Région'}
  114.  
  115. class GenerateR(Wizard):
  116. __name__ = 'fr.region_generate'
  117.  
  118. @classmethod
  119. def execute(cls, session, data, state_name):
  120. print("################### GENERATE")
  121. region = Pool().get('fr.region')
  122. regions = region.browse(Transaction().context.get('active_ids'))
  123. for record in regions:
  124. record.generate([record])
  125. return []
RAW Paste Data