~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to account_msf/test/inkind_donation.yml

  • Committer: jf
  • Date: 2011-05-16 09:55:17 UTC
  • mfrom: (129.1.1 unifield-wm)
  • Revision ID: jf@tempo4-20110516095517-giuzv2mouka39jb8
UF-270 Advance return in a currency that is not the functional currency

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
-
2
 
  I create a partner with a donation payable account and another account
3
 
-
4
 
  !record {model: res.partner, id: supplier1}:
5
 
    name: S1
6
 
    supplier: True
7
 
    partner_type: external
8
 
    property_account_payable: account_account_payable_customer0
9
 
    donation_payable_account: account_account_payable_donation0
10
 
-
11
 
  I create the address for S1
12
 
-
13
 
  !record {model: res.partner.address, id: address1}:
14
 
    name: S1
15
 
    partner_id: supplier1
16
 
-
17
 
  I create a product with a donation expense account and another account
18
 
-
19
 
  !record {model: product.product, id: product1}:
20
 
    cost_method: standard
21
 
    mes_type: fixed
22
 
    name: P1
23
 
    price_margin: 2.0
24
 
    procure_method: make_to_stock
25
 
    property_stock_inventory: stock.location_inventory
26
 
    property_stock_procurement: stock.location_procurement
27
 
    property_stock_production: stock.location_production
28
 
    seller_delay: '1'
29
 
    standard_price: 100.0
30
 
    supply_method: buy
31
 
    type: product
32
 
    uom_id: product.product_uom_unit
33
 
    uom_po_id: product.product_uom_unit
34
 
    volume : 0.0
35
 
    warranty: 0.0
36
 
    weight: 0.0
37
 
    weight_net: 0.0
38
 
    seller_ids:
39
 
      - sequence: 10
40
 
        min_qty: 0.00
41
 
        name: supplier1
42
 
    donation_expense_account: account_account_expense1
43
 
    property_account_expense: account_account_expense0
44
 
-
45
 
  I create an in-kind donation PO with this partner
46
 
-
47
 
  !record {model: purchase.order, id: inkind0}:
48
 
    order_type: in_kind
49
 
    invoice_method: picking
50
 
    name: Inkind0
51
 
    partner_id: supplier1
52
 
    company_id: base.main_company
53
 
    date_order: !eval time.strftime('%Y-%m-%d')
54
 
    location_id: stock.stock_location_stock
55
 
    partner_address_id: address1
56
 
    pricelist_id: purchase.list0
57
 
-
58
 
  We create a line for this purchase order
59
 
-
60
 
  !record {model: purchase.order.line, id: inkind0_l1}:
61
 
    product_uom: product.product_uom_unit
62
 
    product_id: product1
63
 
    order_id: inkind0
64
 
    price_unit: 1.50
65
 
    product_qty: 10
66
 
    name: P1
67
 
    date_planned: !eval time.strftime('%Y-%m-%d')
68
 
-
69
 
  I validate PO
70
 
-
71
 
  !workflow {model: purchase.order, action: purchase_confirm, ref: inkind0}
72
 
-
73
 
  Then I confirm the PO
74
 
-
75
 
  !workflow {model: purchase.order, action: purchase_approve, ref: inkind0}
76
 
-
77
 
  Then I check that no commitment is attached to this PO
78
 
-
79
 
  !python {model: account.commitment}: |
80
 
    search_ids = self.search(cr, uid, [('purchase_id', '=', ref("inkind0"))])
81
 
    assert len(search_ids) == False, "A commitment should not be attached to this PO!"
82
 
-
83
 
  I validate shipment with 1 product.
84
 
-
85
 
  !python {model: stock.picking}: |
86
 
    # Prepare values
87
 
    import time
88
 
    today = time.strftime('%Y-%m-%d')
89
 
    pick_ids = self.search(cr, uid, [('purchase_id', '=', ref("inkind0"))])
90
 
    dic = self.action_process(cr, uid, pick_ids, context=context)
91
 
    res = self.pool.get(dic['res_model']).attach_certificate(cr,uid, [dic['res_id']], context=dic['context'])
92
 
    self.pool.get(res['res_model']).copy_all(cr,uid, [res['res_id']], context=res['context'])
93
 
    self.pool.get(res['res_model']).do_incoming_shipment(cr, uid, [res['res_id']], context=res['context'])
94
 
-
95
 
  I check that an invoice have been created with a inkind donation journal and right accounts (payable for partner and expense for product)
96
 
-
97
 
  !python {model: purchase.order}: |
98
 
    for po in self.browse(cr, uid, [ref("inkind0")]):
99
 
        assert po.invoice_ids != False, "No invoice for this PO!"
100
 
        for inv in po.invoice_ids:
101
 
            assert inv.journal_id.type == 'inkind', "Invoice is not on a In-kind donation journal!"
102
 
            assert inv.account_id.id == po.partner_id.donation_payable_account.id, "No donation payable account given for this invoice! Got %s instead of %s." % (inv.account_id and inv.account_id.code or '', po.partner_id.donation_payable_account and po.partner_id.donation_payable_account.code or '')
103
 
            for line in inv.invoice_line:
104
 
                assert line.account_id.id == ref("account_account_expense1"), "Account on Invoice line is not a donation expense account!"
105
 
-
106
 
  I open the invoice and verify that analytic lines have been created
107
 
-
108
 
  !python {model: account.invoice}: |
109
 
    for inv in self.browse(cr, uid, self.search(cr, uid, [('is_inkind_donation', '=', True)])):
110
 
        import netsvc
111
 
        wf_service = netsvc.LocalService("workflow")
112
 
        # Add a distribution on invoice
113
 
        self.write(cr, uid, [inv.id], {'from_yml_test': True, 'analytic_distribution_id': ref("analytic_distrib1")})
114
 
        # Validate invoice
115
 
        wf_service.trg_validate(uid, 'account.invoice', inv.id, 'invoice_open', cr)
116
 
        # Search analytic lines
117
 
        search_ids = self.pool.get('account.analytic.line').search(cr, uid, [('amount', '=', -15.0), ('general_account_id', '=', ref("account_account_expense1"))])
118
 
        assert len(search_ids) == 1, "Bad generation of analytic lines!"
119
 
-
120
 
  Then I cancel invoice and check that analytic lines have been reversed
121
 
-
122
 
  !python {model: account.invoice}: |
123
 
    for inv in self.browse(cr, uid, self.search(cr, uid, [('is_inkind_donation', '=', True)])):
124
 
        import netsvc
125
 
        wf_service = netsvc.LocalService("workflow")
126
 
        # Fetch some infos
127
 
        move_id = inv.move_id.id
128
 
        move_line_ids = self.pool.get('account.move.line').search(cr, uid, [('move_id', '=', move_id)])
129
 
        # Cancel invoice
130
 
        wf_service.trg_validate(uid, 'account.invoice', inv.id, 'invoice_cancel', cr)
131
 
        # Check that 4 analytic lines exists for this invoice
132
 
        reversed_ids = self.pool.get('account.analytic.line').search(cr, uid, [('is_reversal', '=', True), ('amount', '=', 15.0)])
133
 
        assert len(reversed_ids) == 1, "Invoice have not been reversed"