'Return the additional move lines for purchase invoices and refunds.
i_line: An account.invoice.line object.
res: The move line entries produced so far by the parent move_line_get.'

@api.model
def _anglo_saxon_purchase_move_lines(self, i_line, res):

    inv = i_line.invoice_id
    company_currency = inv.company_id.currency_id
    if (i_line.product_id and (i_line.product_id.valuation == 'real_time') and (i_line.product_id.type == 'product')):
        fpos = i_line.invoice_id.fiscal_position_id
        acc = i_line.product_id.property_account_creditor_price_difference
        if (not acc):
            acc = i_line.product_id.categ_id.property_account_creditor_price_difference_categ
        acc = fpos.map_account(acc).id
        reference_account_id = i_line.product_id.product_tmpl_id.get_product_accounts(fiscal_pos=fpos)['stock_input'].id
        diff_res = []
        account_prec = inv.company_id.currency_id.decimal_places
        for line in res:
            if ((line.get('invl_id', 0) == i_line.id) and (reference_account_id == line['account_id'])):
                valuation_price_unit = i_line.product_id.uom_id._compute_price(i_line.product_id.standard_price, i_line.uom_id)
                if ((i_line.product_id.cost_method != 'standard') and i_line.purchase_line_id):
                    valuation_price_unit = i_line.purchase_line_id.product_uom._compute_price(i_line.purchase_line_id.price_unit, i_line.uom_id)
                    stock_move_obj = self.env['stock.move']
                    valuation_stock_move = stock_move_obj.search([('purchase_line_id', '=', i_line.purchase_line_id.id), ('state', '=', 'done')])
                    if valuation_stock_move:
                        valuation_price_unit_total = 0
                        valuation_total_qty = 0
                        for val_stock_move in valuation_stock_move:
                            valuation_price_unit_total += (val_stock_move.price_unit * val_stock_move.product_qty)
                            valuation_total_qty += val_stock_move.product_qty
                        valuation_price_unit = (valuation_price_unit_total / valuation_total_qty)
                        valuation_price_unit = i_line.product_id.uom_id._compute_price(valuation_price_unit, i_line.uom_id)
                if (inv.currency_id.id != company_currency.id):
                    valuation_price_unit = company_currency.with_context(date=inv.date_invoice).compute(valuation_price_unit, inv.currency_id, round=False)
                if ((valuation_price_unit != i_line.price_unit) and (line['price_unit'] == i_line.price_unit) and acc):
                    price_unit = (i_line.price_unit * (1 - ((i_line.discount or 0.0) / 100.0)))
                    tax_ids = []
                    if line['tax_ids']:
                        taxes = self.env['account.tax'].browse([x[1] for x in line['tax_ids']])
                        price_unit = taxes.compute_all(price_unit, currency=inv.currency_id, quantity=1.0)['total_excluded']
                        for tax in taxes:
                            tax_ids.append((4, tax.id, None))
                            for child in tax.children_tax_ids:
                                if (child.type_tax_use != 'none'):
                                    tax_ids.append((4, child.id, None))
                    price_before = line.get('price', 0.0)
                    line.update({'price': round((valuation_price_unit * line['quantity']), account_prec)})
                    diff_res.append({'type': 'src', 'name': i_line.name[:64], 'price_unit': round((price_unit - valuation_price_unit), account_prec), 'quantity': line['quantity'], 'price': round((price_before - line.get('price', 0.0)), account_prec), 'account_id': acc, 'product_id': line['product_id'], 'uom_id': line['uom_id'], 'account_analytic_id': line['account_analytic_id'], 'tax_ids': tax_ids})
        return diff_res
    return []
