~unifield-team/unifield-wm/us-1035-fixed-config-setup

« back to all changes in this revision

Viewing changes to account_period_closing_level/account_year_end_closing.py

  • Committer: jf
  • Date: 2016-02-08 17:04:14 UTC
  • mfrom: (2753.4.13 unifield-wm)
  • Revision ID: jfb@tempo-consulting.fr-20160208170414-btpk0izpxsk7xwvt
US-887 [FIX] Yearly Closure last dev
lp:~unifield-team/unifield-wm/us-887

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    _columns = {
34
34
        # US-822 counterpart for BS account
35
35
        'ye_pl_cp_for_bs_debit_bal_account': fields.many2one('account.account',
36
 
            'Counterpart for B/S debit balance'),
 
36
            'Counterpart for B/S debit balance',
 
37
            domain=['|', ('user_type.code', 'in', ('income', 'expense', 'equity')), '&', ('type', '=', 'other'), ('user_type.code', '=', 'equity')]),
37
38
        'ye_pl_cp_for_bs_credit_bal_account': fields.many2one('account.account',
38
 
            'Counterpart for B/S credit balance'),
 
39
            'Counterpart for B/S credit balance',
 
40
            domain=['|', ('user_type.code', 'in', ('income', 'expense')), '&', ('type', '=', 'other'), ('user_type.code', '=', 'equity')]),
39
41
 
40
42
        # US-822 PL/BS matrix of dev2/dev3 accounts"
41
43
        'ye_pl_pos_credit_account': fields.many2one('account.account',
42
 
            'Credit Account for P&L>0 (Income account)'),
 
44
            'Credit Account for P&L>0 (Income account)',
 
45
            domain=[('user_type.code', '=', 'income')]),
43
46
        'ye_pl_pos_debit_account': fields.many2one('account.account',
44
47
            'Debit Account for P&L>0 (B/S account)',
45
48
            domain=[('type', '=', 'other'), ('user_type.code', '=', 'equity')]),
47
50
            'Credit Account P&L<0 (B/S account)',
48
51
            domain=[('type', '=', 'other'), ('user_type.code', '=', 'equity')]),
49
52
        'ye_pl_ne_debit_account': fields.many2one('account.account',
50
 
            'Debit Account P&L<0 (Expense account)'),
 
53
            'Debit Account P&L<0 (Expense account)',
 
54
            domain=[('user_type.code', '=', 'expense')]),
51
55
    }
52
56
 
53
57
res_company()
328
332
            """
329
333
            create state valid JI in its CCY/JE
330
334
            """
331
 
            name = "EOY-%d-%s-%s-%s" % (fy_year, account_code,
332
 
                instance_rec.code, ccy_code, )
 
335
            name = 'Balance move to 0'
333
336
 
334
337
            vals = {
335
338
                'account_id': account_id,
472
475
            """
473
476
            create state valid JI in its CCY/JE
474
477
            """
475
 
            name = self._book_pl_results_seqnum_pattern % (fy_year,
476
 
                instance_rec.code, cpy_rec.currency_id.name, )
 
478
            name = 'P&L Result'
477
479
 
478
480
            vals = {
479
481
                'account_id': account_rec.id,
572
574
            """
573
575
            create draft CCY/JE to log JI into
574
576
            """
575
 
            name = "IB-%d-%s-%s-%s" % (fy_year, account_code,
 
577
            name = "IB-%d-%s-%s-%s" % (fy_year + 1, account_code,
576
578
                instance_rec.code, ccy_code, )
577
579
 
578
580
            vals = {
595
597
            """
596
598
            create state valid JI in its CCY/JE
597
599
            """
598
 
            if not name:
599
 
                name = "IB-%d-%s-%s-%s" % (fy_year, account_code,
600
 
                    instance_rec.code, ccy_code, )
 
600
            default_name = 'Balance report / Previous Fiscal Year'
601
601
 
602
602
            vals = {
603
603
                'account_id': account_id,
607
607
                'document_date': posting_date,
608
608
                'instance_id': instance_rec.id,
609
609
                'journal_id': journal_id,
610
 
                'name': name,
 
610
                'name': name or default_name,
611
611
                'period_id': period_id,
612
612
                'source_date': posting_date,
613
613
 
713
713
        if not cr.rowcount:
714
714
            return
715
715
 
716
 
        re_account_found_in_bs = False
717
716
        je_by_acc_ccy = {}  # JE/ ACC/CCY, key: (acc_id, ccy_id), value: JE id
718
717
        for account_id, account_code, ccy_id, ccy_code, \
719
718
            balance_currency, balance in cr.fetchall():
733
732
                account_id=account_id, account_code=account_code,
734
733
                balance_currency=balance_currency, balance=balance, je_id=je_id)
735
734
 
736
 
        if not re_account_found_in_bs:
737
 
            # Regular/Equity account result entry for P&L
738
 
 
739
 
            # invert balance amount to debit or credit amount after account dispatch
740
 
            pl_balance *= -1
741
 
 
742
 
            je_id = je_by_acc_ccy.get(
743
 
                (re_account_rec.id, cpy_rec.currency_id.id, ), False)
744
 
            if not je_id:
745
 
                je_id = create_journal_entry(ccy_id=ccy_id,
746
 
                    ccy_code=cpy_rec.currency_id.name,
747
 
                    account_id=re_account_rec.id,
748
 
                    account_code=re_account_rec.code)
749
 
            create_journal_item(ccy_id=cpy_rec.currency_id.id,
 
735
        # Regular/Equity account result entry for P&L
 
736
        # => invert balance amount to debit or credit amount after account dispatch
 
737
        je_id = je_by_acc_ccy.get(
 
738
            (re_account_rec.id, cpy_rec.currency_id.id, ), False)
 
739
        if not je_id:
 
740
            je_id = create_journal_entry(ccy_id=ccy_id,
750
741
                ccy_code=cpy_rec.currency_id.name,
751
 
                account_id=re_account_rec.id, account_code=re_account_rec.code,
752
 
                balance_currency=pl_balance, balance=pl_balance, je_id=je_id,
753
 
                name="P&L Result report / Previous Fiscal Year")
 
742
                account_id=re_account_rec.id,
 
743
                account_code=re_account_rec.code)
 
744
        create_journal_item(ccy_id=cpy_rec.currency_id.id,
 
745
            ccy_code=cpy_rec.currency_id.name,
 
746
            account_id=re_account_rec.id, account_code=re_account_rec.code,
 
747
            balance_currency=pl_balance, balance=pl_balance, je_id=je_id,
 
748
            name="P&L Result report / Previous Fiscal Year")
754
749
 
755
750
    def update_fy_state(self, cr, uid, fy_id, reopen=False, context=None):
756
751
        def hq_close_post_entries(period_ids):