You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import api, exceptions, fields, _
  5. from openerp.addons.point_of_sale.wizard.pos_box import PosBox
  6. from lxml import etree
  7. import simplejson
  8. class PosBoxCashMoveReason(PosBox):
  9. _register = False
  10. product_id = fields.Many2one(
  11. comodel_name='product.template', string='Reason')
  12. @api.onchange('product_id')
  13. def onchange_reason(self):
  14. for record in self:
  15. if record.product_id.id:
  16. record.name = record.product_id.name
  17. @api.model
  18. def fields_view_get(self, view_id=None, view_type='form',
  19. toolbar=False, submenu=False):
  20. res = super(PosBoxCashMoveReason, self).fields_view_get(
  21. view_id=view_id, view_type=view_type, toolbar=toolbar,
  22. submenu=submenu)
  23. doc = etree.XML(res['arch'])
  24. if self.env.context.get('active_model', '') != 'pos.session':
  25. for node in doc.xpath("//field[@name='product_id']"):
  26. modifiers = {'invisible': True, 'required': False}
  27. node.set('invisible', '1')
  28. node.set('required', '0')
  29. node.set('modifiers', simplejson.dumps(modifiers))
  30. else:
  31. for node in doc.xpath("//field[@name='name']"):
  32. node.set('string', _('Description'))
  33. res['arch'] = etree.tostring(doc)
  34. return res
  35. @api.model
  36. def _compute_values_for_statement_line(self, box, record):
  37. values = super(
  38. PosBoxCashMoveReason, self)._compute_values_for_statement_line(
  39. box, record)
  40. if self.env.context.get('active_model', '') == 'pos.session':
  41. product = box.product_id
  42. account_id = False
  43. if self._name == 'cash.box.in':
  44. account_id = product.property_account_income.id or\
  45. product.categ_id.property_account_income_categ.id
  46. if not account_id:
  47. raise exceptions.Warning(_(
  48. "You have to define an income account on the related"
  49. " product %s") % (product.name))
  50. elif self._name == 'cash.box.out':
  51. account_id = product.property_account_expense.id or\
  52. product.categ_id.property_account_expense_categ.id
  53. if not account_id:
  54. raise exceptions.Warning(_(
  55. "You have to define an expense account on the related"
  56. " product %s") % (product.name))
  57. values['account_id'] = account_id
  58. return values
  59. # the following lines are required for correct inheritance mechanism
  60. class PosBoxIn(PosBoxCashMoveReason):
  61. _inherit = 'cash.box.in'
  62. class PosBoxOut(PosBoxCashMoveReason):
  63. _inherit = 'cash.box.out'