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.

86 lines
3.2 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. @api.onchange('product_id')
  11. def onchange_reason(self):
  12. for record in self:
  13. if record.product_id.id:
  14. record.name = record.product_id.name
  15. @api.model
  16. def fields_view_get(self, view_id=None, view_type='form',
  17. toolbar=False, submenu=False):
  18. res = super(PosBoxCashMoveReason, self).fields_view_get(
  19. view_id=view_id, view_type=view_type, toolbar=toolbar,
  20. submenu=submenu)
  21. doc = etree.XML(res['arch'])
  22. if self.env.context.get('active_model', '') != 'pos.session':
  23. for node in doc.xpath("//field[@name='product_id']"):
  24. modifiers = {'invisible': True, 'required': False}
  25. node.set('invisible', '1')
  26. node.set('required', '0')
  27. node.set('modifiers', simplejson.dumps(modifiers))
  28. else:
  29. for node in doc.xpath("//field[@name='name']"):
  30. node.set('string', _('Description'))
  31. res['arch'] = etree.tostring(doc)
  32. return res
  33. class PosBoxIn(PosBoxCashMoveReason):
  34. _inherit = 'cash.box.in'
  35. product_id = fields.Many2one(
  36. comodel_name='product.template', string='Reason',
  37. domain="[('income_pdt', '=', True)]")
  38. @api.model
  39. def _compute_values_for_statement_line(self, box, record):
  40. values = super(PosBoxIn, self)._compute_values_for_statement_line(
  41. box, record)
  42. if self.env.context.get('active_model', '') == 'pos.session':
  43. if box.product_id.id:
  44. product = box.product_id
  45. account_id = product.property_account_income.id or\
  46. product.categ_id.property_account_income_categ.id
  47. if account_id:
  48. values['account_id'] = account_id
  49. else:
  50. raise exceptions.Warning(_("""You have to define an
  51. income account on the related product"""))
  52. return values
  53. class PosBoxOut(PosBoxCashMoveReason):
  54. _inherit = 'cash.box.out'
  55. product_id = fields.Many2one(
  56. comodel_name='product.template', string='Reason',
  57. domain="[('expense_pdt', '=', True)]")
  58. @api.model
  59. def _compute_values_for_statement_line(self, box, record):
  60. values = super(PosBoxOut, self)._compute_values_for_statement_line(
  61. box, record)
  62. if self.env.context.get('active_model', '') == 'pos.session':
  63. if box.product_id.id:
  64. product = box.product_id
  65. account_id = product.property_account_expense.id or\
  66. product.categ_id.property_account_expense_categ.id
  67. if account_id:
  68. values['account_id'] = account_id
  69. else:
  70. raise exceptions.Warning(_("""You have to define an
  71. expense account on the related product"""))
  72. return values