Browse Source

[ADD][TASK s0010] Eaters for owners of B share

pull/18/head
Rémy Taymans 8 years ago
committed by Thibault Francois
parent
commit
b148a1e830
  1. 18
      beesdoo_base/models/partner.py
  2. 2
      beesdoo_pos/__openerp__.py
  3. 10
      beesdoo_pos/models/beesdoo_pos.py
  4. 2
      beesdoo_pos/static/src/js/beesdoo.js
  5. 5
      beesdoo_pos/static/src/xml/templates.xml

18
beesdoo_base/models/partner.py

@ -39,10 +39,26 @@ class Partner(models.Model):
@api.one
@api.constrains('child_eater_ids', 'parent_eater_id')
def _only_two_eaters(self):
def _check_number_of_eaters(self):
"""The owner of an A share can have a maximum of two eaters but
the owner of a B share can have a maximum of three eaters.
"""
# Get the default_code of the share for the current eater and his parent
share_type_code = None
parent_share_type_code = None
for line in self.share_ids:
share_type_code = line.share_product_id.default_code
for line in self.parent_eater_id.share_ids:
parent_share_type_code = line.share_product_id.default_code
# Raise exception
if share_type_code == 'share_b' or parent_share_type_code == 'share_b':
if len(self.child_eater_ids) > 3 or len(self.parent_eater_id.child_eater_ids) > 3:
raise ValidationError(_('You can only set three additional eaters per worker'))
else:
if len(self.child_eater_ids) > 2 or len(self.parent_eater_id.child_eater_ids) > 2:
raise ValidationError(_('You can only set two additional eaters per worker'))
@api.multi
def write(self, values):
if values.get('parent_eater_id') and self.parent_eater_id:

2
beesdoo_pos/__openerp__.py

@ -20,7 +20,7 @@
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['beesdoo_base', 'beesdoo_product'],
'depends': ['beesdoo_base', 'beesdoo_product', 'easy_my_coop'],
# always loaded
'data': [

10
beesdoo_pos/models/beesdoo_pos.py

@ -44,12 +44,14 @@ class BeescoopPosPartner(models.Model):
_inherit = 'res.partner'
def _get_eater(self):
eater1, eater2 = False, False
eater1, eater2, eater3 = False, False, False
if self.child_eater_ids:
eater1 = self.child_eater_ids[0].name
if len(self.child_eater_ids) > 1:
eater2 = self.child_eater_ids[1].name
return eater1, eater2
if len(self.child_eater_ids) > 2:
eater3 = self.child_eater_ids[2].name
return eater1, eater2, eater3
@api.multi
def get_balance_and_eater(self):
@ -59,7 +61,7 @@ class BeescoopPosPartner(models.Model):
move_lines = self.env['account.move.line'].search([('account_id', '=', account_id), ('partner_id', '=', self.id)])
credit = sum([m.credit for m in move_lines])
debit = sum([m.debit for m in move_lines])
eater1, eater2 = self._get_eater()
return str(round(credit - debit, 2)), eater1, eater2
eater1, eater2, eater3 = self._get_eater()
return str(round(credit - debit, 2)), eater1, eater2, eater3
last_name = fields.Char('Last Name', required=True, default="/")

2
beesdoo_pos/static/src/js/beesdoo.js

@ -59,6 +59,7 @@ odoo.define('beescoop.pos', function (require) {
set_customer_info.call(self, '.customer-balance', result[0])
set_customer_info.call(self, '.customer-delegate1', result[1], 'Eater 1: ');
set_customer_info.call(self, '.customer-delegate2', result[2], 'Eater 2: ');
set_customer_info.call(self, '.customer-delegate3', result[3], 'Eater 3: ');
}, function(err) {
loaded.reject(err);
});
@ -79,6 +80,7 @@ odoo.define('beescoop.pos', function (require) {
set_customer_info.call(self, '.customer-balance', result[0]);
set_customer_info.call(self, '.customer-delegate1', result[1], 'Eater 1: ');
set_customer_info.call(self, '.customer-delegate2', result[2], 'Eater 2: ');
set_customer_info.call(self, '.customer-delegate3', result[3], 'Eater 3: ');
}, function(err) {
loaded.reject(err);
});

5
beesdoo_pos/static/src/xml/templates.xml

@ -22,6 +22,7 @@
<span class='customer-delegate1' />
<br />
<span class='customer-delegate2' />
<span class='customer-delegate3' />
</div>
</t>
</t>
@ -37,12 +38,12 @@
<span class='customer-balance' />
<br />
Eater 1:
<span class='customer-delegate1' />
<br />
Eater 2:
<span class='customer-delegate2' />
<br />
<span class='customer-delegate3' />
<br />
</div>
</t>
</t>

Loading…
Cancel
Save