2
I create a partner with a donation payable account and another account
4
!record {model: res.partner, id: supplier1}:
8
property_account_payable: account_account_payable_customer0
9
donation_payable_account: account_account_payable_donation0
11
I create the address for S1
13
!record {model: res.partner.address, id: address1}:
17
I create a product with a donation expense account and another account
19
!record {model: product.product, id: product1}:
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
32
uom_id: product.product_uom_unit
33
uom_po_id: product.product_uom_unit
42
donation_expense_account: account_account_expense1
43
property_account_expense: account_account_expense0
45
I create an in-kind donation PO with this partner
47
!record {model: purchase.order, id: inkind0}:
49
invoice_method: picking
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
58
We create a line for this purchase order
60
!record {model: purchase.order.line, id: inkind0_l1}:
61
product_uom: product.product_uom_unit
67
date_planned: !eval time.strftime('%Y-%m-%d')
71
!workflow {model: purchase.order, action: purchase_confirm, ref: inkind0}
75
!workflow {model: purchase.order, action: purchase_approve, ref: inkind0}
77
Then I check that no commitment is attached to this PO
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!"
83
I validate shipment with 1 product.
85
!python {model: stock.picking}: |
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'])
95
I check that an invoice have been created with a inkind donation journal and right accounts (payable for partner and expense for product)
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!"
106
I open the invoice and verify that analytic lines have been created
108
!python {model: account.invoice}: |
109
for inv in self.browse(cr, uid, self.search(cr, uid, [('is_inkind_donation', '=', True)])):
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")})
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!"
120
Then I cancel invoice and check that analytic lines have been reversed
122
!python {model: account.invoice}: |
123
for inv in self.browse(cr, uid, self.search(cr, uid, [('is_inkind_donation', '=', True)])):
125
wf_service = netsvc.LocalService("workflow")
127
move_id = inv.move_id.id
128
move_line_ids = self.pool.get('account.move.line').search(cr, uid, [('move_id', '=', move_id)])
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"