~philemon-core-editors/philemon/trunk

« back to all changes in this revision

Viewing changes to donation/donation.py

  • Committer: Alexis de Lattre
  • Date: 2015-02-18 20:38:01 UTC
  • Revision ID: alexis@via.ecp.fr-20150218203801-djcar2cax4uteast
Add support for in-kind donations
Add in-kind and tax-receipt options in donation report
Add copyright notice in some XML files

Show diffs side-by-side

added added

removed removed

Lines of Context:
190
190
        # key = (account_id, analytic_account_id)
191
191
        # value = {'credit': ..., 'debit': ..., 'amount_currency': ...}
192
192
        for donation_line in self.line_ids:
 
193
            if donation_line.in_kind:
 
194
                continue
193
195
            amount_total_company_cur += donation_line.amount_company_currency
194
196
            account_id = donation_line.product_id.property_account_income.id
195
197
            if not account_id:
224
226
                    'amount_currency': amount_currency,
225
227
                    }
226
228
 
 
229
        if not aml:  # for full in-kind donation
 
230
            return False
 
231
 
227
232
        for (account_id, analytic_account_id), content in aml.iteritems():
228
233
            movelines.append((0, 0, {
229
234
                'name': name,
293
298
 
294
299
        if self.amount_total:
295
300
            move_vals = self._prepare_donation_move()
296
 
            move = self.env['account.move'].create(move_vals)
297
 
            move.post()
298
 
            donation_write_vals['move_id'] = move.id
 
301
            # when we have a full in-kind donation: no account move
 
302
            if move_vals:
 
303
                move = self.env['account.move'].create(move_vals)
 
304
                move.post()
 
305
                donation_write_vals['move_id'] = move.id
 
306
            else:
 
307
                self.message_post(
 
308
                    _('Full in-kind donation: no account move generated'))
299
309
 
300
310
        self.write(donation_write_vals)
301
311
        return
381
391
    analytic_account_id = fields.Many2one(
382
392
        'account.analytic.account', string='Analytic Account',
383
393
        domain=[('type', 'not in', ('view', 'template'))], ondelete='restrict')
 
394
    in_kind = fields.Boolean(string='In Kind')
384
395
    sequence = fields.Integer('Sequence')
385
396
 
386
397
    @api.onchange('product_id')
387
398
    def product_id_change(self):
388
 
        if self.product_id and self.product_id.list_price:
389
 
            self.unit_price = self.product_id.list_price
 
399
        if self.product_id:
 
400
            if self.product_id.list_price:
 
401
                self.unit_price = self.product_id.list_price
 
402
            self.in_kind = self.product_id.in_kind_donation
390
403
 
391
404
    @api.model
392
405
    def get_analytic_account_id(self):